Skip to content

Commit 3ff5bec

Browse files
committed
test harness: Let tests fail early by exiting non-zero or by setting a flag.
Fixes #609.
1 parent c4bb260 commit 3ff5bec

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

tests/README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ point will not fail the test), and `$todo` is used as the explanation.
2424
If a test sets `$skip_test` to a non-empty string, the test will be skipped
2525
with the provided string as the reason.
2626

27-
3.
27+
3.
28+
If a test sets `$fail_test` to a non-empty string, the test will be skipped
29+
with the provided string as the reason.
30+
31+
4.
2832
If a test sets `unsorted=1` the order of highlights in `$expected_region_highlight`
2933
need not match the order in `$region_highlight`.
3034

31-
4.
35+
5.
3236
Normally, tests fail if `$expected_region_highlight` and `$region_highlight`
3337
have different numbers of elements. To mark this check as expected to fail,
3438
tests may set `$expected_mismatch` to an explanation string (like `$todo`);

tests/test-highlighting.zsh

+8-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ run_test_internal() {
118118
builtin cd -q -- "$tests_tempdir" || { echo >&2 "Bail out! On ${(qq)1}: cd failed: $?"; return 1 }
119119

120120
# Load the data and prepare checking it.
121-
local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET REPLY skip_test unsorted=0
121+
local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET REPLY skip_test fail_test unsorted=0
122122
local expected_mismatch
123123
local skip_mismatch
124124
local -a expected_region_highlight region_highlight
@@ -127,9 +127,15 @@ run_test_internal() {
127127
local RETURN=""
128128
() {
129129
setopt localoptions
130-
. "$srcdir"/"$ARG"
131130

132131
# WARNING: The remainder of this anonymous function will run with the test's options in effect
132+
if { ! . "$srcdir"/"$ARG" } || (( $#fail_test )); then
133+
print -r -- "1..1"
134+
print -r -- "## ${ARG:t:r}"
135+
tap_escape $fail_test; fail_test=$REPLY
136+
print -r -- "not ok 1 - failed setup: $fail_test"
137+
return ${RETURN:=0}
138+
fi
133139

134140
(( $#skip_test )) && {
135141
print -r -- "1..0 # SKIP $skip_test"

0 commit comments

Comments
 (0)