@@ -4,18 +4,6 @@ set -euo pipefail
44# shellcheck source=lib/bats-core/formatter.bash
55source " $BATS_ROOT /$BATS_LIBDIR /bats-core/formatter.bash"
66
7- BASE_PATH=.
8-
9- while [[ " $# " -ne 0 ]]; do
10- case " $1 " in
11- --base-path)
12- shift
13- normalize_base_path BASE_PATH " $1 "
14- ;;
15- esac
16- shift
17- done
18-
197init_suite () {
208 suite_test_exec_time=0
219 # since we have to print the suite header before its contents but we don't know the contents before the header,
@@ -24,7 +12,6 @@ init_suite() {
2412 test_result_state=" " # declare for the first flush, when no test has been encountered
2513}
2614
27- _buffer_log=
2815init_file () {
2916 file_count=0
3017 file_failures=0
@@ -97,8 +84,8 @@ print_test_case() {
9784 fi
9885}
9986
100- xml_escape () {
101- output=${1// &/ \& amp;}
87+ xml_escape () { # <string to escape>
88+ local output=${1// &/ \& amp;}
10289 output=${output// </ \& lt;}
10390 output=${output// >/ \& gt;}
10491 output=${output// ' "' / \& quot;}
168155}
169156
170157finish_file () {
171- if [[ " ${class-JUNIT_FORMATTER_NO_FILE_ENCOUNTERED } " != JUNIT_FORMATTER_NO_FILE_ENCOUNTERED ]]; then
158+ if [[ " ${class} " != JUNIT_FORMATTER_NO_FILE_ENCOUNTERED ]]; then
172159 file_header
173160 printf " %s\n" " ${_buffer} "
174161 file_footer
@@ -189,10 +176,6 @@ bats_tap_stream_plan() { # <number of tests>
189176 :
190177}
191178
192- init_suite
193- trap finish_suite EXIT
194- trap ' ' INT
195-
196179bats_tap_stream_begin () { # <test index> <test name>
197180 flush_log
198181 # set after flushing to avoid overriding name of test
@@ -259,4 +242,44 @@ bats_tap_stream_unknown() { # <full line>
259242 :
260243}
261244
262- bats_parse_internal_extended_tap
245+ main () {
246+ local _buffer_log=" " \
247+ name=" " \
248+ class=" JUNIT_FORMATTER_NO_FILE_ENCOUNTERED" \
249+ _buffer=" " \
250+ _buffer_log=" " \
251+ _suite_buffer=" " \
252+ _system_out_log=" " \
253+ test_result_state=" " \
254+ test_skip_message=" "
255+
256+ local -i file_count=0 \
257+ file_failures=0 \
258+ file_skipped=0 \
259+ file_exec_time=0 \
260+ test_exec_time=0 \
261+ suite_test_exec_time=0
262+
263+ local BASE_PATH=.
264+
265+ while [[ " $# " -ne 0 ]]; do
266+ case " $1 " in
267+ --base-path)
268+ shift
269+ normalize_base_path BASE_PATH " $1 "
270+ ;;
271+ esac
272+ shift
273+ done
274+
275+ init_suite
276+ trap finish_suite EXIT
277+ trap ' ' INT
278+
279+ bats_parse_internal_extended_tap
280+
281+ trap - EXIT
282+ finish_suite # ensure we run this with the local variables still in scope
283+ }
284+
285+ main " $@ "
0 commit comments