I have a test function which setup my environment before the tests execute.
<code>Setup environment before all tests
set -x # Enable verbose output
OS_TYPE=$(uname 2>/dev/null || echo "Unknown")
# Ensure cygpath is available before using it
if command -v cygpath >/dev/null 2>&1; then
TMP_DIR="$(cygpath -m "${TEMP:-/tmp}")"
echo "Error: cygpath not found. Is Cygwin or Git Bash installed?" >&2
echo "Error: Unsupported OS: $OS_TYPE" >&2
# Use a unique directory for each test run to avoid conflicts
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"
mkdir -p "$MINIMIZED_CHECKOUT_ROOT" || {
echo "Failed to create checkout dir at $MINIMIZED_CHECKOUT_ROOT"
mkdir -p "$CHECKOUT_ROOT" || {
echo "Failed to create root checkout dir at $CHECKOUT_ROOT"
mkdir -p "$EXTRACTED_DELTA_ROOT" || {
echo "Failed to create extracted delta dir at $EXTRACTED_DELTA_ROOT"
mkdir -p "$CHECKOUT_ROOT/default-branch"
cd "$CHECKOUT_ROOT/default-branch" || {
echo "Failed to change directory to $CHECKOUT_ROOT/default-branch"
echo "Failed to initialize Git"
git config core.autocrlf false || {
echo "Failed to set Git config"
# Create and commit an initial file
echo "Initial file content" >file1.txt
echo "Failed to add file1.txt"
git commit -m "Initial commit" || {
# Checkout the main branch
git checkout -b main || {
echo "Failed to checkout branch 'main'"
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"
}
</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)
<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
+ shellspec_is_marked_group 1
+ eval '[ "$SHELLSPEC_MARK_1" ] &&:'
+ eval 'SHELLSPEC_HOOK=$2 && teardown_environment || fail "Teardown failed" &&:'
++ SHELLSPEC_HOOK='teardown_environment || fail "Teardown failed"'
++ 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
<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
<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.
<code> # Determine OS type
OS_TYPE=$(uname 2>/dev/null || echo "Unknown")
if command -v cygpath >/dev/null 2>&1; then
TMP_DIR="$(cygpath -m "${TEMP:-/tmp}")"
echo "Error: cygpath not found" >&2
echo "Error: Unsupported OS: $OS_TYPE" >&2
<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