Skip to content

Commit 61c1cfe

Browse files
committed
test harness: Change cardinality check semantics
The cardinality check shall — - if the test sets \$expected_mismatch, be XFail; - elif any test points is XFail, be skipped; - else, be expected to pass. To test this, change «6 * 9» to «6 + 9» in test-data/arith1.zsh that will be added in the after-next (grandchild) commit.
1 parent ea2f106 commit 61c1cfe

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

tests/README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ need not match the order in `$region_highlight`.
3030

3131
4.
3232
Normally, tests fail if `$expected_region_highlight` and `$region_highlight`
33-
have different numbers of elements. Tests may set `$expected_mismatch` to an
34-
explanation string (like `$todo`) to avoid this and skip the cardinality check.
35-
`$expected_mismatch` is set implicitly if the `$todo` component is present.
33+
have different numbers of elements. To mark this check as expected to fail,
34+
tests may set `$expected_mismatch` to an explanation string (like `$todo`);
35+
this is useful when the only difference between actual and expected is that actual
36+
has some additional, superfluous elements. This check is skipped if the
37+
`$todo` component is present in any regular test point.
3638

3739
**Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but
3840
interprets the indexes differently.

tests/test-highlighting.zsh

+17-7
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ run_test_internal() {
120120
# Load the data and prepare checking it.
121121
local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET REPLY skip_test unsorted=0
122122
local expected_mismatch
123+
local skip_mismatch
123124
local -a expected_region_highlight region_highlight
124125

125126
. "$srcdir"/"$1"
@@ -155,11 +156,11 @@ run_test_internal() {
155156
local todo=
156157
if (( $+expected_highlight_zone[4] )); then
157158
todo="# TODO $expected_highlight_zone[4]"
158-
: ${expected_mismatch:="cardinality check disabled whilst regular test points are expected to fail"}
159+
skip_mismatch="cardinality check disabled whilst regular test points are expected to fail"
159160
fi
160161
if ! (( $+region_highlight[i] )); then
161162
print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])" \
162-
"${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}"
163+
"${skip_mismatch:+"# TODO ${(qqq)skip_mismatch}"}"
163164
continue
164165
fi
165166
local -a highlight_zone; highlight_zone=( ${(z)region_highlight[i]} )
@@ -183,18 +184,27 @@ run_test_internal() {
183184
unset desc
184185
done
185186

186-
if [[ -n $expected_mismatch ]]; then
187-
tap_escape $expected_mismatch; expected_mismatch=$REPLY
188-
print "ok $i - cardinality check" "# SKIP $expected_mismatch"
187+
# If both $skip_mismatch and $expected_mismatch are set, that means the test
188+
# has some XFail test points, _and_ explicitly sets $expected_mismatch as
189+
# well. Explicit settings should have priority, so we ignore $skip_mismatch
190+
# if $expected_mismatch is set.
191+
if [[ -n $skip_mismatch && -z $expected_mismatch ]]; then
192+
tap_escape $skip_mismatch; skip_mismatch=$REPLY
193+
print "ok $i - cardinality check" "# SKIP $skip_mismatch"
189194
else
195+
local todo
196+
if [[ -n $expected_mismatch ]]; then
197+
tap_escape $expected_mismatch; expected_mismatch=$REPLY
198+
todo="# TODO $expected_mismatch"
199+
fi
190200
if (( $#expected_region_highlight == $#region_highlight )); then
191-
print -r -- "ok $i - cardinality check"
201+
print -r -- "ok $i - cardinality check${todo:+ - }$todo"
192202
else
193203
local details
194204
details+="have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: "
195205
details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»"
196206
tap_escape $details; details=$REPLY
197-
print -r -- "not ok $i - cardinality check - $details"
207+
print -r -- "not ok $i - cardinality check - $details${todo:+ - }$todo"
198208
fi
199209
fi
200210
}

0 commit comments

Comments
 (0)