Skip to content

Commit 409ea0e

Browse files
committed
FIX tap plan should include skipped and pending tests
According to this example extracted from tap documentation, the skipped and pending tests should be included in the plan: ``` TAP version 14 1..2 ok 1 - do it later # Skipped ok 2 - works on windows # Skipped: only run on windows ```
1 parent 6cbf7e9 commit 409ea0e

File tree

2 files changed

+49
-19
lines changed

2 files changed

+49
-19
lines changed

bash_unit

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -236,25 +236,32 @@ maybe_shuffle() {
236236
run_tests() {
237237
local failure=0
238238

239-
for pending_test in $(set | "$GREP" -E '^(pending|todo).* \(\)' | "$GREP" -E "$test_pattern" | "$SED" -e 's: .*::')
240-
do
241-
notify_test_starting "$pending_test"
242-
notify_test_pending "$pending_test"
243-
done
244-
239+
local pending_tests=$(set | "$GREP" -E '^(pending|todo).* \(\)' | "$GREP" -E "$test_pattern" | "$SED" -e 's: .*::')
245240
if [[ -n "$skip_pattern" ]]
246241
then
247-
for skipped_test in $(set | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -E "$skip_pattern" | "$SED" -e 's: .*::')
248-
do
249-
notify_test_starting "$skipped_test"
250-
notify_test_skipped "$skipped_test"
251-
done
242+
local skipped_tests=$(set | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -E "$skip_pattern" | "$SED" -e 's: .*::')
252243
local tests_to_run="$(set | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -v -E "$skip_pattern" | "$SED" -e 's: .*::' | maybe_shuffle)"
253244
else
245+
local skipped_tests=""
254246
local tests_to_run="$(set | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$SED" -e 's: .*::' | maybe_shuffle)"
255247
fi
256248

257-
test_count=$(cat "${TEMPFILE}")
249+
local test_count=$(cat "${TEMPFILE}")
250+
test_count=$((test_count + $(count "$pending_tests") + $(count "$tests_to_run") + $(count "$skipped_tests")))
251+
echo "${test_count}" > "${TEMPFILE}"
252+
253+
for pending_test in $pending_tests
254+
do
255+
notify_test_starting "$pending_test"
256+
notify_test_pending "$pending_test"
257+
done
258+
259+
for skipped_test in $skipped_tests
260+
do
261+
notify_test_starting "$skipped_test"
262+
notify_test_skipped "$skipped_test"
263+
done
264+
258265
for test in $tests_to_run
259266
do
260267
(
@@ -265,9 +272,7 @@ run_tests() {
265272
exit $status
266273
)
267274
failure=$(( $? || failure))
268-
((test_count++))
269275
done
270-
echo "${test_count}" > "${TEMPFILE}"
271276

272277
return $failure
273278
}
@@ -484,6 +489,15 @@ skip_if() {
484489
fi
485490
}
486491

492+
count() {
493+
local tests="$1"
494+
if [[ -z "$tests" ]]; then
495+
echo 0
496+
else
497+
echo "$tests" | wc -l
498+
fi
499+
}
500+
487501
output_format=text
488502
verbosity=normal
489503
test_pattern=""
@@ -570,13 +584,13 @@ do
570584
)
571585
failure=$(( $? || failure))
572586
done
573-
587+
574588
if ((failure))
575589
then
576-
notify_suites_failed $(cat "${TEMPFILE}")
590+
notify_suites_failed "$(cat "${TEMPFILE}")"
577591
else
578-
notify_suites_succeded $(cat "${TEMPFILE}")
592+
notify_suites_succeded "$(cat "${TEMPFILE}")"
579593
fi
580594

581-
unlink $TEMPFILE
595+
unlink "$TEMPFILE"
582596
exit $failure

tests/test_tap_format

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test_tap_format_for_one_pending_test() {
4242
"\
4343
# Running tests in code
4444
ok - pending_not_yet_implemented # todo test to be written
45-
1..0" \
45+
1..1" \
4646
"$(bash_unit_out_for_code <<EOF
4747
pending_not_yet_implemented() {
4848
assert false
@@ -51,6 +51,22 @@ EOF
5151
)"
5252
}
5353

54+
test_tap_format_with_skipped_tests() {
55+
bash_unit_output="$(bash_unit_out_for_code <<EOF
56+
test_one() { echo -n ; }
57+
test_two() { fail ; }
58+
skip_if true two
59+
EOF
60+
)"
61+
62+
assert_equals "\
63+
# Running tests in code
64+
ok - test_two # skip test not run
65+
ok - test_one
66+
1..2" \
67+
"$bash_unit_output"
68+
}
69+
5470
test_tap_format_for_failing_test_with_stdout_stderr_outputs() {
5571
assert_equals \
5672
"\

0 commit comments

Comments
 (0)