From 4952325051d41817485a4a3a2dfc9a70dd134c74 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 10 Nov 2019 11:35:21 +0000 Subject: [PATCH] tests: Skip cardinality tests whenever any test point is expected to fail. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When writing an expected-to-fail test case, the cardinality of $region_highlight at the time the test is written may differ from the cardinality it will have once the bug is fixed. For example, with issue #641.5, the current highlighting is ['nice', 'x=y', 'y', 'ls'] — four elements — but the correct highlighting would have three elements: ['nice', 'x=y', 'ls']. There is no point in reporting a separate test failure for the cardinality check in this case, nor for 'ls' being highlighted as 'command' rather than 'default'. At the same time, in other cases the current and correct highlighting may have the same number of elements (for example, this would be the case for a hypothetical "the command word is highlighted as an alias rather than a function" bug). Thus, the previous commit, q.v.. --- tests/README.md | 1 + tests/test-highlighting.zsh | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index a413e16..ebacae4 100644 --- a/tests/README.md +++ b/tests/README.md @@ -24,6 +24,7 @@ need not match the order in `$region_highlight`. Normally, tests fail if `$expected_region_highlight` and `$region_highlight` have different numbers of elements. Tests may set `$expected_mismatch` to an explanation string (like `$todo`) to avoid this and skip the cardinality check. +`$expected_mismatch` is set implicitly if the `$todo` component is present. **Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 7b32dbc..a01df43 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -145,7 +145,10 @@ run_test_internal() { local -a expected_highlight_zone; expected_highlight_zone=( ${(z)expected_region_highlight[i]} ) integer exp_start=$expected_highlight_zone[1] exp_end=$expected_highlight_zone[2] local todo= - (( $+expected_highlight_zone[4] )) && todo="# TODO $expected_highlight_zone[4]" + if (( $+expected_highlight_zone[4] )); then + todo="# TODO $expected_highlight_zone[4]" + : ${expected_mismatch:="cardinality check disabled whilst regular test points are expected to fail"} + fi if ! (( $+region_highlight[i] )); then print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])" continue