-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathparallel.sh
More file actions
executable file
·143 lines (115 loc) · 4.11 KB
/
parallel.sh
File metadata and controls
executable file
·143 lines (115 loc) · 4.11 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
#!/usr/bin/env bash
function bashunit::parallel::aggregate_test_results() {
local temp_dir_parallel_test_suite=$1
local IFS=$' \t\n'
bashunit::internal_log "aggregate_test_results" "dir:$temp_dir_parallel_test_suite"
local total_failed=0
local total_passed=0
local total_skipped=0
local total_incomplete=0
local total_snapshot=0
local script_dir=""
for script_dir in "$temp_dir_parallel_test_suite"/*; do
shopt -s nullglob
# Bash 3.0 compatible: separate declaration and assignment for arrays
local result_files
result_files=("$script_dir"/*.result)
shopt -u nullglob
if [ ${#result_files[@]} -eq 0 ]; then
printf "%sNo tests found%s" "$_BASHUNIT_COLOR_SKIPPED" "$_BASHUNIT_COLOR_DEFAULT"
continue
fi
local result_file=""
for result_file in "${result_files[@]+"${result_files[@]}"}"; do
local result_line
result_line=$(<"$result_file")
result_line="${result_line##*$'\n'}"
local failed="${result_line##*##ASSERTIONS_FAILED=}"
failed="${failed%%##*}"
failed=${failed:-0}
local passed="${result_line##*##ASSERTIONS_PASSED=}"
passed="${passed%%##*}"
passed=${passed:-0}
local skipped="${result_line##*##ASSERTIONS_SKIPPED=}"
skipped="${skipped%%##*}"
skipped=${skipped:-0}
local incomplete="${result_line##*##ASSERTIONS_INCOMPLETE=}"
incomplete="${incomplete%%##*}"
incomplete=${incomplete:-0}
local snapshot="${result_line##*##ASSERTIONS_SNAPSHOT=}"
snapshot="${snapshot%%##*}"
snapshot=${snapshot:-0}
local exit_code="${result_line##*##TEST_EXIT_CODE=}"
exit_code="${exit_code%%##*}"
exit_code=${exit_code:-0}
# Add to the total counts
total_failed=$((total_failed + failed))
total_passed=$((total_passed + passed))
total_skipped=$((total_skipped + skipped))
total_incomplete=$((total_incomplete + incomplete))
total_snapshot=$((total_snapshot + snapshot))
if [ "${failed:-0}" -gt 0 ]; then
bashunit::state::add_tests_failed
continue
fi
if [ "${exit_code:-0}" -ne 0 ]; then
bashunit::state::add_tests_failed
continue
fi
if [ "${snapshot:-0}" -gt 0 ]; then
bashunit::state::add_tests_snapshot
continue
fi
if [ "${incomplete:-0}" -gt 0 ]; then
bashunit::state::add_tests_incomplete
continue
fi
if [ "${skipped:-0}" -gt 0 ]; then
bashunit::state::add_tests_skipped
continue
fi
# Check for risky test (zero assertions, no error)
local total_for_test=$((failed + passed + skipped + incomplete + snapshot))
if [ "$total_for_test" -eq 0 ] && [ "${exit_code:-0}" -eq 0 ]; then
bashunit::state::add_tests_risky
continue
fi
bashunit::state::add_tests_passed
done
done
export _BASHUNIT_ASSERTIONS_FAILED=$total_failed
export _BASHUNIT_ASSERTIONS_PASSED=$total_passed
export _BASHUNIT_ASSERTIONS_SKIPPED=$total_skipped
export _BASHUNIT_ASSERTIONS_INCOMPLETE=$total_incomplete
export _BASHUNIT_ASSERTIONS_SNAPSHOT=$total_snapshot
bashunit::internal_log "aggregate_totals" \
"failed:$total_failed" \
"passed:$total_passed" \
"skipped:$total_skipped" \
"incomplete:$total_incomplete" \
"snapshot:$total_snapshot"
}
function bashunit::parallel::mark_stop_on_failure() {
touch "$TEMP_FILE_PARALLEL_STOP_ON_FAILURE"
}
function bashunit::parallel::must_stop_on_failure() {
[ -f "$TEMP_FILE_PARALLEL_STOP_ON_FAILURE" ]
}
function bashunit::parallel::cleanup() {
# shellcheck disable=SC2153
rm -rf "$TEMP_DIR_PARALLEL_TEST_SUITE"
}
function bashunit::parallel::init() {
bashunit::parallel::cleanup
mkdir -p "$TEMP_DIR_PARALLEL_TEST_SUITE"
}
function bashunit::parallel::is_enabled() {
bashunit::internal_log "bashunit::parallel::is_enabled" \
"requested:$BASHUNIT_PARALLEL_RUN" "os:${_BASHUNIT_OS:-Unknown}"
if bashunit::env::is_parallel_run_enabled &&
(bashunit::check_os::is_macos || bashunit::check_os::is_ubuntu ||
bashunit::check_os::is_alpine || bashunit::check_os::is_windows); then
return 0
fi
return 1
}