Fix test suite cleanup to handle failures and interruptions
Add proper cleanup handling using bash trap to ensure test artifacts are removed regardless of how the test script exits. Changes: - Add cleanup() function to remove all test artifacts - Set trap to call cleanup on EXIT (success, failure, or interruption) - Remove redundant manual cleanup since trap handles it automatically - Add error suppression to prevent cleanup failures This fixes the defect where test artifacts would remain if a test failed or the script was interrupted before reaching the manual cleanup section.
This commit is contained in:
parent
e63426f7c7
commit
814e0650de
1 changed files with 10 additions and 4 deletions
14
test.sh
14
test.sh
|
@ -12,6 +12,16 @@ NC='\033[0m' # No Color
|
|||
TESTS_PASSED=0
|
||||
TESTS_FAILED=0
|
||||
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
echo -e "\n${YELLOW}Cleaning up test artifacts...${NC}"
|
||||
rm -rf test test-*.tgz test-*.zip collect /tmp/test_output.txt 2>/dev/null || true
|
||||
echo -e "${GREEN}Cleanup completed.${NC}"
|
||||
}
|
||||
|
||||
# Set trap to cleanup on script exit (success, failure, or interruption)
|
||||
trap cleanup EXIT
|
||||
|
||||
# Function to run a test
|
||||
run_test() {
|
||||
local test_name="$1"
|
||||
|
@ -213,10 +223,6 @@ run_test "combined include and exclude filters" \
|
|||
"./collect --include-dir 'project-*' --exclude-dir 'project-two' --name 'app.go' --name 'lib.go' test/ test-include-exclude.tgz"
|
||||
verify_archive_contents "test-include-exclude.tgz" "project-one/src/app.go"
|
||||
|
||||
# Clean up
|
||||
echo -e "\nCleaning up..."
|
||||
rm -rf test test-*.tgz test-*.zip collect /tmp/test_output.txt
|
||||
|
||||
# Summary
|
||||
echo -e "\n${YELLOW}=== Test Summary ===${NC}"
|
||||
echo -e "Tests passed: ${GREEN}$TESTS_PASSED${NC}"
|
||||
|
|
Loading…
Add table
Reference in a new issue