From 19c56b1d1295120cc33503dd90d218d486656d5d Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Fri, 22 Jun 2012 22:31:35 +0200 Subject: [PATCH] tests: new requirement 'grep-nonprint' * t/ax/test-inist.sh ($esc): New, a literal escape character. (grep-nonprint): New requirement, check that the grep implementation available that can handle non-printing characters correctly. * t/color.sh: Use it instead of hand-rolled equivalent, and do not (re)define '$esc' explicitly. * t/color2.sh: Likewise. * t/tap-color.sh: Likewise. * t/vtexi4.sh: Likewise. * t/parallel-tests-no-color-in-log.sh: Likewise. Also prefer the use of grep over that of $FGREP, because the new requirement only check grep, and ensure we only grep non-printing characters from a pipe, to avoid hitting a BSD grep limitation. * t/parallel-tests-reset-term.sh: Likewise. * t/ax/tap-summary-aux.sh: Use '$esc' instead of hard-coding the literal escape character. Signed-off-by: Stefano Lattarini --- t/ax/tap-summary-aux.sh | 14 +++++++------- t/ax/test-init.sh | 11 +++++++++++ t/color.sh | 16 +++++----------- t/color2.sh | 16 +++++----------- t/parallel-tests-no-color-in-log.sh | 16 ++++------------ t/parallel-tests-reset-term.sh | 15 +++------------ t/tap-color.sh | 16 +++++----------- t/vtexi4.sh | 7 ++----- 8 files changed, 42 insertions(+), 69 deletions(-) diff --git a/t/ax/tap-summary-aux.sh b/t/ax/tap-summary-aux.sh index 2fadb3d..8962326 100644 --- a/t/ax/tap-summary-aux.sh +++ b/t/ax/tap-summary-aux.sh @@ -82,13 +82,13 @@ do_check () } if test $use_colors = yes; then - red='' - grn='' - lgn='' - blu='' - mgn='' - brg='' - std='' + red="$esc[0;31m" + grn="$esc[0;32m" + lgn="$esc[1;32m" + blu="$esc[1;34m" + mgn="$esc[0;35m" + brg="$esc[1m" + std="$esc[m" echo AUTOMAKE_OPTIONS = color-tests >> Makefile.am else red= grn= lgn= blu= mgn= brg= std= diff --git a/t/ax/test-init.sh b/t/ax/test-init.sh index 01d4584..ca606b5 100644 --- a/t/ax/test-init.sh +++ b/t/ax/test-init.sh @@ -63,6 +63,8 @@ tab=' ' # A newline character. nl=' ' +# A literal escape character. Used by test checking colored output. +esc='' # As autoconf-generated configure scripts do, ensure that IFS # is defined initially, so that saving and restoring $IFS works. @@ -754,6 +756,15 @@ do *) FC=$F77 FCFLAGS=$FFLAGS; export FC FCFLAGS;; esac ;; + grep-nonprint) + # Check that grep can parse nonprinting characters correctly. + # BSD 'grep' works from a pipe, but not a seekable file. + # GNU or BSD 'grep -a' works on files, but is not portable. + case $(echo "$esc" | grep .)$(echo "$esc" | grep "$esc") in + "$esc$esc") ;; + *) skip_ "grep can't handle nonprinting characters correctly";; + esac + ;; javac) # The Java compiler from JDK 1.5 (and presumably earlier versions) # cannot handle the '-version' option by itself: it bails out diff --git a/t/color.sh b/t/color.sh index 18c6e23..5726ac1 100755 --- a/t/color.sh +++ b/t/color.sh @@ -17,10 +17,10 @@ # Test Automake TESTS color output, by forcing it. # Keep this in sync with the sister test 'color2.test'. +required='grep-nonprint' # For gen-testsuite-part: ==> try-with-serial-tests <== . ./defs || Exit 1 -esc='' # Escape '[' for grep, below. red="$esc\[0;31m" grn="$esc\[0;32m" @@ -29,14 +29,6 @@ blu="$esc\[1;34m" mgn="$esc\[0;35m" std="$esc\[m" -# Check that grep can parse nonprinting characters. -# BSD 'grep' works from a pipe, but not a seekable file. -# GNU or BSD 'grep -a' works on files, but is not portable. -case $(echo "$std" | grep .) in - "$std") ;; - *) skip_ "grep can't parse nonprinting characters";; -esac - cat >>configure.ac < try-with-serial-tests <== . ./defs || Exit 1 -esc='' # Escape '[' for grep, below. red="$esc\[0;31m" grn="$esc\[0;32m" @@ -29,14 +29,6 @@ blu="$esc\[1;34m" mgn="$esc\[0;35m" std="$esc\[m" -# Check that grep can parse nonprinting characters. -# BSD 'grep' works from a pipe, but not a seekable file. -# GNU or BSD 'grep -a' works on files, but is not portable. -case $(echo "$std" | grep .) in - "$std") ;; - *) skip_ "grep can't parse nonprinting characters";; -esac - # This test requires a working a working 'expect' program. # Creative quoting required to avoid spurious maintainer-check failure. (set +e; expect -c 'exit ''77'; test $? -eq 77) \ @@ -108,7 +100,8 @@ $AUTOMAKE --add-missing test_color () { - # Not a useless use of cat; see above comments about grep. + # Not a useless use of cat; see above comments "grep-nonprinting" + # requirement in 'test-init.sh'. cat stdout | grep "^${grn}PASS${std}: .*pass" cat stdout | grep "^${red}FAIL${std}: .*fail" cat stdout | grep "^${blu}SKIP${std}: .*skip" @@ -136,7 +129,8 @@ test_no_color () # not unduly colorized. ( set +e # In case some grepped regex below isn't matched. - # Not a useless use of cat; see above comments about grep. + # Not a useless use of cat; see above comments "grep-nonprinting" + # requirement in 'test-init.sh'. cat stdout | grep "TOTAL.*:" cat stdout | grep "PASS.*:" cat stdout | grep "FAIL.*:" diff --git a/t/parallel-tests-no-color-in-log.sh b/t/parallel-tests-no-color-in-log.sh index 69414f7..e8e2030 100755 --- a/t/parallel-tests-no-color-in-log.sh +++ b/t/parallel-tests-no-color-in-log.sh @@ -16,19 +16,9 @@ # Colorized output from the testsuite report shouldn't end up in log files. +required='grep-nonprint' . ./defs || Exit 1 -esc='' - -# Check that grep can parse nonprinting characters. -# BSD 'grep' works from a pipe, but not a seekable file. -# GNU or BSD 'grep -a' works on files, but is not portable. -case `echo "$esc" | $FGREP "$esc"` in - "$esc") ;; -# Creative quoting below to please maintainer-check. - *) echo "$me: f""grep can't parse nonprinting characters" >&2; Exit 77;; -esac - TERM=ansi; export TERM cat >>configure.ac <> configure.ac << 'END' AC_OUTPUT END @@ -67,9 +58,9 @@ $AUTOMAKE -a ./configure mkcheck TESTS_ENVIRONMENT='TERM=dumb' -cat stdout | grep "PASS.*foobar" | $FGREP "$esc" +cat stdout | grep "PASS.*foobar" | grep "$esc\\[" mkcheck AM_TESTS_ENVIRONMENT='TERM=dumb' -cat stdout | grep "PASS.*foobar" | $FGREP "$esc" +cat stdout | grep "PASS.*foobar" | grep "$esc\\[" : diff --git a/t/tap-color.sh b/t/tap-color.sh index 6a91f06..5a8e1bc 100755 --- a/t/tap-color.sh +++ b/t/tap-color.sh @@ -17,9 +17,9 @@ # TAP support: # - colorization of TAP results and diagnostic messages +required='grep-nonprint' . ./defs || Exit 1 -esc='' # Escape '[' for grep, below. red="$esc\[0;31m" grn="$esc\[0;32m" @@ -28,14 +28,6 @@ blu="$esc\[1;34m" mgn="$esc\[0;35m" std="$esc\[m" -# Check that grep can parse nonprinting characters. -# BSD 'grep' works from a pipe, but not a seekable file. -# GNU or BSD 'grep -a' works on files, but is not portable. -case `echo "$std" | grep .` in - "$std") ;; - *) echo "$me: grep can't parse nonprinting characters" >&2; Exit 77;; -esac - cat > Makefile.am << 'END' AUTOMAKE_OPTIONS = color-tests AM_TEST_LOG_DRIVER_FLAGS = --comments @@ -101,7 +93,8 @@ END test_color () { - # Not a useless use of cat; see above comments about grep. + # Not a useless use of cat; see above comments "grep-nonprinting" + # requirement in 'test-init.sh'. cat stdout | grep "^${grn}PASS${std}: all\.test 1 - foo$" cat stdout | grep "^${lgn}XFAIL${std}: all\.test 2 - bar # TODO td$" cat stdout | grep "^${blu}SKIP${std}: all\.test 3 - baz # SKIP sk$" @@ -134,7 +127,8 @@ test_no_color () # colorized. ( set +e # In case some grepped regex below isn't matched. - # Not a useless use of cat; see above comments about grep. + # Not a useless use of cat; see above comments "grep-nonprinting" + # requirement in 'test-init.sh'. cat stdout | grep "TOTAL.*:" cat stdout | grep "PASS.*:" cat stdout | grep "FAIL.*:" diff --git a/t/vtexi4.sh b/t/vtexi4.sh index 27b0636..dcdcf85 100755 --- a/t/vtexi4.sh +++ b/t/vtexi4.sh @@ -21,7 +21,7 @@ # for more vers*.texi files, and does not require makeinfo, tex and # texi2dvi. -required='makeinfo tex texi2dvi-o' +required='makeinfo tex texi2dvi-o grep-nonprint' . ./defs || Exit 1 test $(LC_ALL=C date '+%u') -gt 0 && test $(LC_ALL=C date '+%u') -lt 8 \ @@ -31,9 +31,6 @@ test $(LC_ALL=C date '+%u') -gt 0 && test $(LC_ALL=C date '+%u') -lt 8 \ || skip_ "'date' is not POSIX-compliant enough" day=$(echo "$day" | sed 's/^0//') -(echo 'x' | grep x) \ - || skip_ "grep doesn't work on input that is not pure text" - cat > configure.ac << END AC_INIT([$me], [123.456]) AM_INIT_AUTOMAKE @@ -51,7 +48,7 @@ cat > Makefile.am << 'END' include defs.am info_TEXINFOS = foo.texi test-grepinfo: -## Not useless uses of cat: we only tested that grep worked on +## Not useless uses of cat: we only tested that grep works on ## non-text input when that's given from a pipe. cat $(srcdir)/foo.info | grep 'GREPVERSION=$(my_version_rx)=' cat $(srcdir)/foo.info | grep 'GREPEDITION=$(my_version_rx)=' -- 2.7.4