-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all_tests.sh
More file actions
executable file
·146 lines (128 loc) · 3.97 KB
/
run_all_tests.sh
File metadata and controls
executable file
·146 lines (128 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Script to run all tests in the tests directory
# If any test fails (returns non-zero exit code), the script stops and returns a non-zero exit code
#
# Note: The current implementation of the Batch Script Shell (BSS) may not propagate
# exit codes from commands within batch files correctly. For a test to register as
# failed, the shell process itself must return a non-zero exit code. Some improvements
# to the shell's error handling may be necessary to fully utilize this feature.
# Default values
stop_on_error=true
verbose=false
# Function to display usage
usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -h, --help Show this help message"
echo " -c, --continue Continue running tests even after a failure"
echo " -v, --verbose Print detailed output for each test"
echo " -s, --stop-on-error Stop on first error (default behavior)"
exit 1
}
# Parse command-line options
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
;;
-c|--continue)
stop_on_error=false
shift
;;
-v|--verbose)
verbose=true
shift
;;
-s|--stop-on-error)
stop_on_error=true
shift
;;
*)
echo "Unknown option: $1"
usage
;;
esac
done
# Find the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TESTS_DIR="$SCRIPT_DIR/tests"
# Check if tests directory exists
if [[ ! -d "$TESTS_DIR" ]]; then
echo "Error: Tests directory not found at $TESTS_DIR"
exit 1
fi
# Find all .bat files in the tests directory
BAT_FILES=("$TESTS_DIR"/*.bat)
# Check if any .bat files were found
if [[ ! -e "${BAT_FILES[0]}" ]]; then
echo "No .bat files found in $TESTS_DIR"
exit 0
fi
# Initialize counters
total_tests=0
failed_tests=0
passed_tests=0
# Print initial message
echo "Running all batch script tests in $TESTS_DIR"
echo "============================================="
# Loop through each .bat file
for bat_file in "${BAT_FILES[@]}"; do
# Check if the file exists (to handle case where no .bat files exist)
if [[ ! -f "$bat_file" ]]; then
continue
fi
# Extract just the filename for display
test_name=$(basename "$bat_file")
# Increment test counter
((total_tests++))
if [[ "$verbose" == true ]]; then
echo "Running test: $test_name"
else
echo -n "Running test: $test_name ... "
fi
# Execute the shell with the batch file
# Using timeout to avoid hanging tests (set to 30 seconds)
if timeout 30 "$SCRIPT_DIR/bss" "$bat_file" > /dev/null 2>&1; then
# Test passed
if [[ "$verbose" == true ]]; then
echo "PASSED"
else
echo "PASSED"
fi
((passed_tests++))
else
# Test failed
exit_code=$?
if [[ "$verbose" == true ]]; then
echo "FAILED (exit code: $exit_code)"
else
echo "FAILED (exit code: $exit_code)"
fi
((failed_tests++))
# Print error message if not in continue mode
if [[ "$stop_on_error" == true ]]; then
echo "Test $test_name failed with exit code $exit_code. Stopping execution."
echo "============================================="
echo "Test Summary:"
echo " Total: $total_tests"
echo " Passed: $passed_tests"
echo " Failed: $failed_tests"
exit $exit_code
fi
fi
done
# Print final results
echo "============================================="
echo "All tests completed."
echo "Test Summary:"
echo " Total: $total_tests"
echo " Passed: $passed_tests"
echo " Failed: $failed_tests"
# Exit with appropriate code based on results
if [[ $failed_tests -gt 0 ]]; then
echo "Some tests failed."
exit 1
else
echo "All tests passed!"
exit 0
fi