Skip to content

Commit f63f074

Browse files
committed
Merge remote-tracking branch 'danielsh/tests-skip-cardinality-v1'
* danielsh/tests-skip-cardinality-v1: tests: Minor documentation readability tweak Add a test for issue #641.5, using the infrastructure added in the previous commits. tests: Skip cardinality tests whenever any test point is expected to fail. tests: Make $expected_mismatch skip the cardinality check, rather than consider it an expected failure. tests: Include the name of the 'cardinality check' test point in the output
2 parents 2331072 + b7592e5 commit f63f074

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env zsh
2+
# -------------------------------------------------------------------------------------------------
3+
# Copyright (c) 2019 zsh-syntax-highlighting contributors
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without modification, are permitted
7+
# provided that the following conditions are met:
8+
#
9+
# * Redistributions of source code must retain the above copyright notice, this list of conditions
10+
# and the following disclaimer.
11+
# * Redistributions in binary form must reproduce the above copyright notice, this list of
12+
# conditions and the following disclaimer in the documentation and/or other materials provided
13+
# with the distribution.
14+
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
15+
# may be used to endorse or promote products derived from this software without specific prior
16+
# written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24+
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25+
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
# -------------------------------------------------------------------------------------------------
27+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
28+
# vim: ft=zsh sw=2 ts=2 et
29+
# -------------------------------------------------------------------------------------------------
30+
31+
BUFFER=$'nice x=y ls'
32+
33+
expected_region_highlight=(
34+
'1 4 precommand' # nice
35+
'6 8 unknown-token "issue #641.5"' # x=y
36+
'10 11 default "issue #641.5 (fallout)"' # ls
37+
)

tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ need not match the order in `$region_highlight`.
3131
4.
3232
Normally, tests fail if `$expected_region_highlight` and `$region_highlight`
3333
have different numbers of elements. Tests may set `$expected_mismatch` to an
34-
explanation string (like `$todo`) to avoid this and mark the cardinality check
35-
as todo.
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.
3636

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

tests/test-highlighting.zsh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ run_test_internal() {
153153
local -a expected_highlight_zone; expected_highlight_zone=( ${(z)expected_region_highlight[i]} )
154154
integer exp_start=$expected_highlight_zone[1] exp_end=$expected_highlight_zone[2]
155155
local todo=
156-
(( $+expected_highlight_zone[4] )) && todo="# TODO $expected_highlight_zone[4]"
156+
if (( $+expected_highlight_zone[4] )); then
157+
todo="# TODO $expected_highlight_zone[4]"
158+
: ${expected_mismatch:="cardinality check disabled whilst regular test points are expected to fail"}
159+
fi
157160
if ! (( $+region_highlight[i] )); then
158161
print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])" \
159162
"${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}"
@@ -180,14 +183,17 @@ run_test_internal() {
180183
unset desc
181184
done
182185

183-
if (( $#expected_region_highlight == $#region_highlight )); then
184-
print -r -- "ok $i - cardinality check" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}"
186+
if [[ -n $expected_mismatch ]]; then
187+
tap_escape $expected_mismatch; expected_mismatch=$REPLY
188+
print "ok $i - cardinality check" "# SKIP $expected_mismatch"
189+
elif (( $#expected_region_highlight == $#region_highlight )); then
190+
print -r -- "ok $i - cardinality check"
185191
else
186192
local details
187193
details+="have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: "
188194
details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»"
189195
tap_escape $details; details=$REPLY
190-
print -r -- "not ok $i - $details" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}"
196+
print -r -- "not ok $i - cardinality check - $details"
191197
fi
192198
}
193199

0 commit comments

Comments
 (0)