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
This commit is contained in:
		
						commit
						f63f07417d
					
				|  | @ -0,0 +1,37 @@ | ||||||
|  | #!/usr/bin/env zsh | ||||||
|  | # ------------------------------------------------------------------------------------------------- | ||||||
|  | # Copyright (c) 2019 zsh-syntax-highlighting contributors | ||||||
|  | # All rights reserved. | ||||||
|  | # | ||||||
|  | # Redistribution and use in source and binary forms, with or without modification, are permitted | ||||||
|  | # provided that the following conditions are met: | ||||||
|  | # | ||||||
|  | #  * Redistributions of source code must retain the above copyright notice, this list of conditions | ||||||
|  | #    and the following disclaimer. | ||||||
|  | #  * Redistributions in binary form must reproduce the above copyright notice, this list of | ||||||
|  | #    conditions and the following disclaimer in the documentation and/or other materials provided | ||||||
|  | #    with the distribution. | ||||||
|  | #  * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors | ||||||
|  | #    may be used to endorse or promote products derived from this software without specific prior | ||||||
|  | #    written permission. | ||||||
|  | # | ||||||
|  | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | ||||||
|  | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||||||
|  | # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||||||
|  | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||||
|  | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||||
|  | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||||||
|  | # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||||||
|  | # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||
|  | # ------------------------------------------------------------------------------------------------- | ||||||
|  | # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- | ||||||
|  | # vim: ft=zsh sw=2 ts=2 et | ||||||
|  | # ------------------------------------------------------------------------------------------------- | ||||||
|  | 
 | ||||||
|  | BUFFER=$'nice x=y ls' | ||||||
|  | 
 | ||||||
|  | expected_region_highlight=( | ||||||
|  |   '1 4 precommand' # nice | ||||||
|  |   '6 8 unknown-token "issue #641.5"' # x=y | ||||||
|  |   '10 11 default "issue #641.5 (fallout)"' # ls | ||||||
|  | ) | ||||||
|  | @ -31,8 +31,8 @@ need not match the order in `$region_highlight`. | ||||||
| 4. | 4. | ||||||
| Normally, tests fail if `$expected_region_highlight` and `$region_highlight` | Normally, tests fail if `$expected_region_highlight` and `$region_highlight` | ||||||
| have different numbers of elements.  Tests may set `$expected_mismatch` to an | have different numbers of elements.  Tests may set `$expected_mismatch` to an | ||||||
| explanation string (like `$todo`) to avoid this and mark the cardinality check | explanation string (like `$todo`) to avoid this and skip the cardinality check. | ||||||
| as todo. | `$expected_mismatch` is set implicitly if the `$todo` component is present. | ||||||
| 
 | 
 | ||||||
| **Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but | **Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but | ||||||
| interprets the indexes differently. | interprets the indexes differently. | ||||||
|  |  | ||||||
|  | @ -153,7 +153,10 @@ run_test_internal() { | ||||||
|     local -a expected_highlight_zone; expected_highlight_zone=( ${(z)expected_region_highlight[i]} ) |     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] |     integer exp_start=$expected_highlight_zone[1] exp_end=$expected_highlight_zone[2] | ||||||
|     local todo= |     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 |     if ! (( $+region_highlight[i] )); then | ||||||
|       print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])" \ |       print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])" \ | ||||||
|          "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" |          "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" | ||||||
|  | @ -180,14 +183,17 @@ run_test_internal() { | ||||||
|     unset desc |     unset desc | ||||||
|   done |   done | ||||||
| 
 | 
 | ||||||
|   if (( $#expected_region_highlight == $#region_highlight )); then |   if [[ -n $expected_mismatch ]]; then | ||||||
|     print -r -- "ok $i - cardinality check" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" |     tap_escape $expected_mismatch; expected_mismatch=$REPLY | ||||||
|  |     print "ok $i - cardinality check" "# SKIP $expected_mismatch" | ||||||
|  |   elif (( $#expected_region_highlight == $#region_highlight )); then | ||||||
|  |     print -r -- "ok $i - cardinality check" | ||||||
|   else |   else | ||||||
|     local details |     local details | ||||||
|     details+="have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: " |     details+="have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: " | ||||||
|     details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" |     details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" | ||||||
|     tap_escape $details; details=$REPLY |     tap_escape $details; details=$REPLY | ||||||
|     print -r -- "not ok $i - $details" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" |     print -r -- "not ok $i - cardinality check - $details" | ||||||
|   fi |   fi | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue