ShellSpec :Error in ‘before and after all hook’ terminates test execution even the status code is 0

I have a test function which setup my environment before the tests execute.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Setup environment before all tests
setup_environment() {
set -x # Enable verbose output
# Determine the OS type
OS_TYPE=$(uname 2>/dev/null || echo "Unknown")
case "$OS_TYPE" in
Darwin|Linux)
TMP_DIR="/tmp"
;;
CYGWIN*|MINGW*|MSYS*)
# Ensure cygpath is available before using it
if command -v cygpath >/dev/null 2>&1; then
TMP_DIR="$(cygpath -m "${TEMP:-/tmp}")"
else
echo "Error: cygpath not found. Is Cygwin or Git Bash installed?" >&2
return 1
fi
;;
*)
echo "Error: Unsupported OS: $OS_TYPE" >&2
return 1
;;
esac
# Use a unique directory for each test run to avoid conflicts
TEST_ID=$(date +%s)
export EXTRACT_DELTA_CONSOLE_LOG_PATH="$TMP_DIR/extract-delta-console-log-$TEST_ID"
export MINIMIZED_CHECKOUT_ROOT="$TMP_DIR/minimized-checkout-root-$TEST_ID"
export CHECKOUT_ROOT="$TMP_DIR/checkout-root-$TEST_ID"
export EXTRACTED_DELTA_ROOT="$TMP_DIR/extracted-delta-root-$TEST_ID"
# Clean up any pre-existing directories
rm -rf "$EXTRACT_DELTA_CONSOLE_LOG_PATH" "$MINIMIZED_CHECKOUT_ROOT" "$CHECKOUT_ROOT" "$EXTRACTED_DELTA_ROOT"
# Create necessary directories and handle errors
mkdir -p "$EXTRACT_DELTA_CONSOLE_LOG_PATH" || {
echo "Failed to create log dir at $EXTRACT_DELTA_CONSOLE_LOG_PATH"
return 1
}
mkdir -p "$MINIMIZED_CHECKOUT_ROOT" || {
echo "Failed to create checkout dir at $MINIMIZED_CHECKOUT_ROOT"
return 1
}
mkdir -p "$CHECKOUT_ROOT" || {
echo "Failed to create root checkout dir at $CHECKOUT_ROOT"
return 1
}
mkdir -p "$EXTRACTED_DELTA_ROOT" || {
echo "Failed to create extracted delta dir at $EXTRACTED_DELTA_ROOT"
return 1
}
# Git operations
mkdir -p "$CHECKOUT_ROOT/default-branch"
cd "$CHECKOUT_ROOT/default-branch" || {
echo "Failed to change directory to $CHECKOUT_ROOT/default-branch"
return 1
}
git init || {
echo "Failed to initialize Git"
return 1
}
git config core.autocrlf false || {
echo "Failed to set Git config"
return 1
}
# Create and commit an initial file
echo "Initial file content" >file1.txt
git add file1.txt || {
echo "Failed to add file1.txt"
return 1
}
git commit -m "Initial commit" || {
echo "Failed to commit"
return 1
}
# Checkout the main branch
git checkout -b main || {
echo "Failed to checkout branch 'main'"
return 1
}
echo "Setup completed for test: $TEST_ID"
}
</code>
<code>Setup environment before all tests setup_environment() { set -x # Enable verbose output # Determine the OS type OS_TYPE=$(uname 2>/dev/null || echo "Unknown") case "$OS_TYPE" in Darwin|Linux) TMP_DIR="/tmp" ;; CYGWIN*|MINGW*|MSYS*) # Ensure cygpath is available before using it if command -v cygpath >/dev/null 2>&1; then TMP_DIR="$(cygpath -m "${TEMP:-/tmp}")" else echo "Error: cygpath not found. Is Cygwin or Git Bash installed?" >&2 return 1 fi ;; *) echo "Error: Unsupported OS: $OS_TYPE" >&2 return 1 ;; esac # Use a unique directory for each test run to avoid conflicts TEST_ID=$(date +%s) export EXTRACT_DELTA_CONSOLE_LOG_PATH="$TMP_DIR/extract-delta-console-log-$TEST_ID" export MINIMIZED_CHECKOUT_ROOT="$TMP_DIR/minimized-checkout-root-$TEST_ID" export CHECKOUT_ROOT="$TMP_DIR/checkout-root-$TEST_ID" export EXTRACTED_DELTA_ROOT="$TMP_DIR/extracted-delta-root-$TEST_ID" # Clean up any pre-existing directories rm -rf "$EXTRACT_DELTA_CONSOLE_LOG_PATH" "$MINIMIZED_CHECKOUT_ROOT" "$CHECKOUT_ROOT" "$EXTRACTED_DELTA_ROOT" # Create necessary directories and handle errors mkdir -p "$EXTRACT_DELTA_CONSOLE_LOG_PATH" || { echo "Failed to create log dir at $EXTRACT_DELTA_CONSOLE_LOG_PATH" return 1 } mkdir -p "$MINIMIZED_CHECKOUT_ROOT" || { echo "Failed to create checkout dir at $MINIMIZED_CHECKOUT_ROOT" return 1 } mkdir -p "$CHECKOUT_ROOT" || { echo "Failed to create root checkout dir at $CHECKOUT_ROOT" return 1 } mkdir -p "$EXTRACTED_DELTA_ROOT" || { echo "Failed to create extracted delta dir at $EXTRACTED_DELTA_ROOT" return 1 } # Git operations mkdir -p "$CHECKOUT_ROOT/default-branch" cd "$CHECKOUT_ROOT/default-branch" || { echo "Failed to change directory to $CHECKOUT_ROOT/default-branch" return 1 } git init || { echo "Failed to initialize Git" return 1 } git config core.autocrlf false || { echo "Failed to set Git config" return 1 } # Create and commit an initial file echo "Initial file content" >file1.txt git add file1.txt || { echo "Failed to add file1.txt" return 1 } git commit -m "Initial commit" || { echo "Failed to commit" return 1 } # Checkout the main branch git checkout -b main || { echo "Failed to checkout branch 'main'" return 1 } echo "Setup completed for test: $TEST_ID" } </code>
Setup environment before all tests
setup_environment() {
    set -x # Enable verbose output

    # Determine the OS type
    OS_TYPE=$(uname 2>/dev/null || echo "Unknown")

    case "$OS_TYPE" in
        Darwin|Linux)
            TMP_DIR="/tmp"
            ;;
        CYGWIN*|MINGW*|MSYS*)
            # Ensure cygpath is available before using it
            if command -v cygpath >/dev/null 2>&1; then
                TMP_DIR="$(cygpath -m "${TEMP:-/tmp}")"
            else
                echo "Error: cygpath not found. Is Cygwin or Git Bash installed?" >&2
                return 1
            fi
            ;;
        *)
            echo "Error: Unsupported OS: $OS_TYPE" >&2
            return 1
            ;;
    esac

    # Use a unique directory for each test run to avoid conflicts
    TEST_ID=$(date +%s)
    export EXTRACT_DELTA_CONSOLE_LOG_PATH="$TMP_DIR/extract-delta-console-log-$TEST_ID"
    export MINIMIZED_CHECKOUT_ROOT="$TMP_DIR/minimized-checkout-root-$TEST_ID"
    export CHECKOUT_ROOT="$TMP_DIR/checkout-root-$TEST_ID"
    export EXTRACTED_DELTA_ROOT="$TMP_DIR/extracted-delta-root-$TEST_ID"

    # Clean up any pre-existing directories
    rm -rf "$EXTRACT_DELTA_CONSOLE_LOG_PATH" "$MINIMIZED_CHECKOUT_ROOT" "$CHECKOUT_ROOT" "$EXTRACTED_DELTA_ROOT"

    # Create necessary directories and handle errors
    mkdir -p "$EXTRACT_DELTA_CONSOLE_LOG_PATH" || {
        echo "Failed to create log dir at $EXTRACT_DELTA_CONSOLE_LOG_PATH"
        return 1
    }
    mkdir -p "$MINIMIZED_CHECKOUT_ROOT" || {
        echo "Failed to create checkout dir at $MINIMIZED_CHECKOUT_ROOT"
        return 1
    }
    mkdir -p "$CHECKOUT_ROOT" || {
        echo "Failed to create root checkout dir at $CHECKOUT_ROOT"
        return 1
    }
    mkdir -p "$EXTRACTED_DELTA_ROOT" || {
        echo "Failed to create extracted delta dir at $EXTRACTED_DELTA_ROOT"
        return 1
    }

    # Git operations
    mkdir -p "$CHECKOUT_ROOT/default-branch"
    cd "$CHECKOUT_ROOT/default-branch" || {
        echo "Failed to change directory to $CHECKOUT_ROOT/default-branch"
        return 1
    }

    git init || {
        echo "Failed to initialize Git"
        return 1
    }
    git config core.autocrlf false || {
        echo "Failed to set Git config"
        return 1
    }

    # Create and commit an initial file
    echo "Initial file content" >file1.txt
    git add file1.txt || {
        echo "Failed to add file1.txt"
        return 1
    }
    git commit -m "Initial commit" || {
        echo "Failed to commit"
        return 1
    }

    # Checkout the main branch
    git checkout -b main || {
        echo "Failed to checkout branch 'main'"
        return 1
    }
    echo "Setup completed for test: $TEST_ID"
}

Once executed, this fails by given the following error

a) ERROR: An error occurred in before all hook ‘setup_environment || fail “Setup failed, terminating”‘ (exit status: 0)

Similar error is given in the after all function as well.

b) ERROR: An error occurred in after hook ‘teardown_environment || fail “Teardown failed”‘ (exit status: 0)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> + eval 'set -- "$1" "${SHELLSPEC_AFTER_ALL_1#*:}" "${SHELLSPEC_AFTER_ALL_1%%:*}"'
++ set -- AFTER_ALL 'teardown_environment || fail "Teardown failed"' 1#105
+ SHELLSPEC_HOOK_BLOCK_NO=1
+ SHELLSPEC_HOOK_LINENO=105
+ case $1 in
+ '[' 1 = 1 ']'
+ shellspec_is_marked_group 1
+ eval '[ "$SHELLSPEC_MARK_1" ] &&:'
++ '[' 1 ']'
++ :
+ :
+ eval 'SHELLSPEC_HOOK=$2 && teardown_environment || fail "Teardown failed" &&:'
++ SHELLSPEC_HOOK='teardown_environment || fail "Teardown failed"'
++ teardown_environment
++ echo 'Tearing down environment...'
++ rm -rf C:/extract-delta-console-log-1725509273 C:/minimized-checkout-root-1725509273 C://checkout-root-1725509273 C:/extracted-delta-root-1725509273
++ :
+ :
+ SHELLSPEC_HOOK_STATUS=0
+ return 0
</code>
<code> + eval 'set -- "$1" "${SHELLSPEC_AFTER_ALL_1#*:}" "${SHELLSPEC_AFTER_ALL_1%%:*}"' ++ set -- AFTER_ALL 'teardown_environment || fail "Teardown failed"' 1#105 + SHELLSPEC_HOOK_BLOCK_NO=1 + SHELLSPEC_HOOK_LINENO=105 + case $1 in + '[' 1 = 1 ']' + shellspec_is_marked_group 1 + eval '[ "$SHELLSPEC_MARK_1" ] &&:' ++ '[' 1 ']' ++ : + : + eval 'SHELLSPEC_HOOK=$2 && teardown_environment || fail "Teardown failed" &&:' ++ SHELLSPEC_HOOK='teardown_environment || fail "Teardown failed"' ++ teardown_environment ++ echo 'Tearing down environment...' ++ rm -rf C:/extract-delta-console-log-1725509273 C:/minimized-checkout-root-1725509273 C://checkout-root-1725509273 C:/extracted-delta-root-1725509273 ++ : + : + SHELLSPEC_HOOK_STATUS=0 + return 0 </code>
   + eval 'set -- "$1" "${SHELLSPEC_AFTER_ALL_1#*:}" "${SHELLSPEC_AFTER_ALL_1%%:*}"'
   ++ set -- AFTER_ALL 'teardown_environment || fail "Teardown failed"' 1#105
   + SHELLSPEC_HOOK_BLOCK_NO=1
   + SHELLSPEC_HOOK_LINENO=105
   + case $1 in
   + '[' 1 = 1 ']'
   + shellspec_is_marked_group 1
   + eval '[ "$SHELLSPEC_MARK_1" ] &&:'
   ++ '[' 1 ']'
   ++ :
   + :
   + eval 'SHELLSPEC_HOOK=$2 && teardown_environment || fail "Teardown failed" &&:'
   ++ SHELLSPEC_HOOK='teardown_environment || fail "Teardown failed"'
   ++ teardown_environment
   ++ echo 'Tearing down environment...'
   ++ rm -rf C:/extract-delta-console-log-1725509273 C:/minimized-checkout-root-1725509273 C://checkout-root-1725509273 C:/extracted-delta-root-1725509273
   ++ :
   + :
   + SHELLSPEC_HOOK_STATUS=0
   + return 0
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> + return 0
</code>
<code> + return 0 </code>
   + return 0

I had added debug logs but could not find any additional errors. SHELLSPEC_HOOK_STATUS=0 could me found in the logs which suppose to mean no error has occurred. But none of my tests are getting executed as well.

The shell spec version I am using is as follows

$ shellspec -v
0.28.1

Above script is executed in a windows OS and I am checking for the compatibility of OS as well.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> # Determine OS type
OS_TYPE=$(uname 2>/dev/null || echo "Unknown")
case "$OS_TYPE" in
Darwin|Linux)
TMP_DIR="/tmp"
;;
CYGWIN*|MINGW*|MSYS*)
if command -v cygpath >/dev/null 2>&1; then
TMP_DIR="$(cygpath -m "${TEMP:-/tmp}")"
else
echo "Error: cygpath not found" >&2
exit 1
fi
;;
*)
echo "Error: Unsupported OS: $OS_TYPE" >&2
exit 1
;;
esac
</code>
<code> # Determine OS type OS_TYPE=$(uname 2>/dev/null || echo "Unknown") case "$OS_TYPE" in Darwin|Linux) TMP_DIR="/tmp" ;; CYGWIN*|MINGW*|MSYS*) if command -v cygpath >/dev/null 2>&1; then TMP_DIR="$(cygpath -m "${TEMP:-/tmp}")" else echo "Error: cygpath not found" >&2 exit 1 fi ;; *) echo "Error: Unsupported OS: $OS_TYPE" >&2 exit 1 ;; esac </code>
   # Determine OS type
    OS_TYPE=$(uname 2>/dev/null || echo "Unknown")

    case "$OS_TYPE" in
        Darwin|Linux)
            TMP_DIR="/tmp"
            ;;
        CYGWIN*|MINGW*|MSYS*)
            if command -v cygpath >/dev/null 2>&1; then
                TMP_DIR="$(cygpath -m "${TEMP:-/tmp}")"
            else
                echo "Error: cygpath not found" >&2
                exit 1
            fi
            ;;
        *)
            echo "Error: Unsupported OS: $OS_TYPE" >&2
            exit 1
            ;;
    esac

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật