tests: Add a 'print failures only' mode to 'make test', called 'make quiet-test'.

Fixes zsh-users/zsh-syntax-highlighting#262.

Currently, 'make quiet-test' uses Perl.  However, since it is considered a development
tool rather than a user-facing tool, users and downstream packages needn't install Perl.
Furthermore, even this dev-only dependency may be dropped in the future.

The only difference between tests/tap-filter here and the one in the issue is using
a `cat` subshell v. using 'undef $/; <STDIN>'.
This commit is contained in:
Daniel Shahaf 2016-01-02 21:22:01 +00:00
parent 936e2e9314
commit 9b64ad750f
4 changed files with 65 additions and 1 deletions

View file

@ -45,6 +45,9 @@ test:
done; \ done; \
exit $$result exit $$result
quiet-test:
$(MAKE) test QUIET=y
perf: perf:
@result=0; \ @result=0; \
for test in highlighters/*; do \ for test in highlighters/*; do \

View file

@ -38,6 +38,9 @@ All tests may be run with
make test make test
which will run all highlighting tests and report results in [TAP format][TAP]. which will run all highlighting tests and report results in [TAP format][TAP].
By default, the results of all tests will be printed; to show only "interesting"
results (tests that failed but were expected to succeed, or vice-versa), run
`make quiet-test` (or `make test QUIET=y`).
[TAP]: http://testanything.org/ [TAP]: http://testanything.org/

45
tests/tap-filter Executable file
View file

@ -0,0 +1,45 @@
#!/usr/bin/env perl
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2015 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.
# -------------------------------------------------------------------------------------------------
# vim: ft=perl sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
# This is a stdin-to-stdout filter that takes TAP output (such as 'make test')
# on stdin and deletes lines pertaining to expected results.
#
# More specifically, if any of the test points in a test file either failed but
# was expected to pass, or passed but was expected to fail, then emit that test
# file's output; else, elide that test file's output.
use v5.10.0;
use warnings;
use strict;
undef $/; # slurp mode
print for
grep { /^ok.*# TODO/m or /^not ok(?!.*# TODO)/m }
split /^(?=#)/m,
<STDIN>;

View file

@ -132,10 +132,23 @@ run_test() {
} }
} }
# Set up results_filter
local results_filter
if [[ $QUIET == y ]]; then
if type -w perl >/dev/null; then
results_filter=${0:A:h}/tap-filter
else
echo >&2 "Bail out! quiet mode not supported: perl not found"; exit 2
fi
else
results_filter=cat
fi
[[ -n $results_filter ]] || { echo >&2 "Bail out! BUG setting \$results_filter"; exit 2 }
# Process each test data file in test data directory. # Process each test data file in test data directory.
integer something_failed=0 integer something_failed=0
for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do
run_test "$data_file" | tee >(${0:A:h}/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -q '^not ok\|^ok.*# TODO' && (( something_failed=1 )) run_test "$data_file" | tee >($results_filter | ${0:A:h}/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -q '^not ok\|^ok.*# TODO' && (( something_failed=1 ))
(( $pipestatus[1] )) && exit 2 (( $pipestatus[1] )) && exit 2
done done