From 9880431627fa196f7f5b4fd20aaeac97bee5cbd2 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Tue, 9 Aug 2011 00:38:39 +0200 Subject: [PATCH] self tests: some new uses of TAP, few extensions * tests/self-check-me.test: Renamed ... * tests/self-check-me.tap: .. to this, and converted to use TAP. * tests/self-check-exit.test: Renamed ... * tests/self-check-exit.tap: .. to this, and converted to use TAP. Set `$stderr_fileno_' to `2', to avoid spurious messages on the console. Add a new test, and relax another one. * tests/self-check-env-sanitize.test: Renamed ... * tests/self-check-env-sanitize.tap: .. to this, and converted to the use TAP. * tests/Makefile.am (TESTS): Update. --- ChangeLog | 14 ++++ tests/Makefile.am | 6 +- tests/Makefile.in | 6 +- ...v-sanitize.test => self-check-env-sanitize.tap} | 22 +++++-- .../{self-check-exit.test => self-check-exit.tap} | 59 ++++++++--------- tests/self-check-me.tap | 75 ++++++++++++++++++++++ tests/self-check-me.test | 45 ------------- 7 files changed, 139 insertions(+), 88 deletions(-) rename tests/{self-check-env-sanitize.test => self-check-env-sanitize.tap} (72%) rename tests/{self-check-exit.test => self-check-exit.tap} (65%) create mode 100755 tests/self-check-me.tap delete mode 100755 tests/self-check-me.test diff --git a/ChangeLog b/ChangeLog index 71611ca..6a5ca12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2011-08-09 Stefano Lattarini + self tests: some new uses of TAP, few extensions + * tests/self-check-me.test: Renamed ... + * tests/self-check-me.tap: .. to this, and converted to use TAP. + * tests/self-check-exit.test: Renamed ... + * tests/self-check-exit.tap: .. to this, and converted to use TAP. + Set `$stderr_fileno_' to `2', to avoid spurious messages on the + console. Add a new test, and relax another one. + * tests/self-check-env-sanitize.test: Renamed ... + * tests/self-check-env-sanitize.tap: .. to this, and converted to + the use TAP. + * tests/Makefile.am (TESTS): Update. + +2011-08-09 Stefano Lattarini + test defs: test directory creation more configurable After this change, the individual tests will be able to tell `./defs' whether or not to create a temporary test directory diff --git a/tests/Makefile.am b/tests/Makefile.am index c887155..1a0ef0e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -899,11 +899,11 @@ repeated-options.test \ rulepat.test \ self-check-cleanup.test \ self-check-dir.test \ -self-check-env-sanitize.test \ -self-check-exit.test \ +self-check-env-sanitize.tap \ +self-check-exit.tap \ self-check-explicit-skips.test \ self-check-is_newest.test \ -self-check-me.test \ +self-check-me.tap \ self-check-reexec.test \ self-check-report.test \ self-check-sanity.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 3520590..3a30b84 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1142,11 +1142,11 @@ repeated-options.test \ rulepat.test \ self-check-cleanup.test \ self-check-dir.test \ -self-check-env-sanitize.test \ -self-check-exit.test \ +self-check-env-sanitize.tap \ +self-check-exit.tap \ self-check-explicit-skips.test \ self-check-is_newest.test \ -self-check-me.test \ +self-check-me.tap \ self-check-reexec.test \ self-check-report.test \ self-check-sanity.test \ diff --git a/tests/self-check-env-sanitize.test b/tests/self-check-env-sanitize.tap similarity index 72% rename from tests/self-check-env-sanitize.test rename to tests/self-check-env-sanitize.tap index a7c66de..16e3a99 100755 --- a/tests/self-check-env-sanitize.test +++ b/tests/self-check-env-sanitize.tap @@ -18,11 +18,14 @@ # Make sure that the testsuite initialization code complains when # some testsuite-influential variables are set in the environment. -. ./defs-static || exit 1 +am_create_testdir=no +. ./defs || Exit 1 set -x exec 5>&1 +plan_ 16 # Two times the number of variable names in $vars. + vars=' me parallel_tests @@ -34,11 +37,20 @@ vars=' original_ACLOCAL ' +do_run () +{ + env "$1=foo" $SHELL -c '. ./defs' foo.test +} + +do_grep () +{ + env "$1=foo" $SHELL -c '. ./defs' foo.test 2>&1 1>&5 \ + | grep "foo\.test:.* variable \`$1'.* in the environment.*unsafe" +} + for var in $vars; do - env "$var=foo" $SHELL -c '. ./defs' foo.test && exit 1 - env "$var=foo" $SHELL -c '. ./defs' foo.test 2>&1 1>&5 \ - | grep "foo\.test:.* variable \`$var'.* in the environment.*unsafe" \ - || exit 1 + command_not_ok_ "$var [err status]" do_run $var + command_ok_ "$var [err message]" do_grep $var done : diff --git a/tests/self-check-exit.test b/tests/self-check-exit.tap similarity index 65% rename from tests/self-check-exit.test rename to tests/self-check-exit.tap index 69aabcd..97bf3bc 100755 --- a/tests/self-check-exit.test +++ b/tests/self-check-exit.tap @@ -19,65 +19,60 @@ # passed to the exit trap installed by the `./defs' script. # Also check that the `errexit' shell flag is active. -. ./defs-static || exit 99 +am_create_testdir=no +. ./defs || Exit 99 -unset am_explicit_skips +plan_ 34 + +unset am_explicit_skips stderr_fileno_ AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC for st in 1 2 3 4 5 77 99 126 127 128 129 130 255; do - - echo "* Try: Exit $st" - $SHELL -c ". ./defs; Exit $st; :" - rc=$? - echo "* rc=$rc" - echo - test $rc -eq $st || exit 1 - - echo "* Try: sh -c 'exit $st'" - $SHELL -c ". ./defs; sh -c 'exit $st'; :" - rc=$? - echo "* rc=$rc" - echo - test $rc -eq $st || exit 1 - + rc=0; $SHELL -c ". ./defs; Exit $st; :" || rc=$? + command_ok_ "Exit $st" test $rc -eq $st + rc=0; $SHELL -c ". ./defs; sh -c 'exit $st'; :" || rc=$? + command_ok_ "exit $st" test $rc -eq $st done -echo "* Try: non-existent-program" -$SHELL -c ". ./defs; non-existent-program; :" -rc=$? -echo "* rc=$rc" -echo -test $rc -eq 127 || exit 1 - for sig in 1 2 13 15; do - - echo "* Try: kill -$sig \$\$" if test $sig -eq 2; then # Some Korn shells might otherwise get a spurious SIGINT # signal when one is sent to the child $SHELL. trap : 2 fi - $SHELL -c ". ./defs; kill -$sig \$\$; :" - rc=$? + rc=0; $SHELL -c ". ./defs; kill -$sig \$\$; :" || rc=$? if test $sig -eq 2; then # Reset default SIGINT handler as portably as possible. trap 2 || trap - 2 fi - echo "* rc=$rc" - echo if test x"$sh_errexit_works" = x"yes"; then # The exit trap should turn into an hard errors any failure # caused by signals. - test $rc -eq 99 || exit 1 + command_ok_ "kill -$sig" test $rc -eq 99 else # The exit trap is not installed, so that the shell should exit # with status 128+n when receiving signal number n. But don't # be too strict in the check, as POSIX only says that "The exit # status of a command that terminated because it received a # signal shall be reported as greater than 128". - test $rc -gt 128 || exit 1 + command_ok_ "kill -$sig" test $rc -gt 128 fi done +: Non-existent program. +rc=0; $SHELL -c ". ./defs; non-existent-program; :" || rc=$? +command_ok_ "command not found" test $rc -gt 0 + +: Non-executable command. +: > non-executable +rc=0; $SHELL -c ". ./defs; ./non-executable; :" || rc=$? +command_ok_ "permission denied" test $rc -gt 0 + +: Syntax errors in the test code. +rc=0; $SHELL -c ". ./defs; if :; then" || rc=$? +command_ok_ "syntax error 1" test $rc -gt 0 +rc=0; $SHELL -c ". ./defs; fi" || rc=$? +command_ok_ "syntax error 2" test $rc -gt 0 + : diff --git a/tests/self-check-me.tap b/tests/self-check-me.tap new file mode 100755 index 0000000..503a1d0 --- /dev/null +++ b/tests/self-check-me.tap @@ -0,0 +1,75 @@ +#! /bin/sh +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Sanity check for the automake testsuite. +# Make sure that $me gets automatically defined by `./defs', and that it +# can be overridden by the test script. + +am_create_testdir=no +. ./defs || Exit 1 + +plan_ 9 + +AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC +set +e + +do_check () +{ + if $SHELL -c '. ./defs && echo me=$me' "$1" | grep "^me=$2$"; then + r='ok' + else + r='not ok' + fi + result_ "$r" "me=$1" + unset r +} + +do_check foo-bar-.test 'foo-bar-' +do_check _foo__bar.test '_foo__bar' +do_check 012.test '012' +do_check foo.bar 'foo\.bar' +do_check a.b.c.test 'a\.b\.c' + +# If we override $me, ./defs should not modify it. + +if s=`$SHELL -c 'me=foo.test && . ./defs && echo me=$me' bad.test`; then + r='ok' +else + r='not ok' +fi +result_ "$r" "override of \$me before ./defs causes no error" + +r='ok' +if printf '%s\n' "$s" | grep '^me=foo\.test$'; then :; else r='not ok'; fi +if printf '%s\n' "$s" | grep 'me=bad'; then r='not ok'; else :; fi +result_ "$r" "override of \$me before defs is honored" + +# Overriding $me after sourcing ./defs-static should work. + +if s=`$SHELL -c '. ./defs-static && me=zardoz && + . ./defs && echo me=$me' bad.test`; then + r='ok' +else + r='not ok' +fi +result_ "$r" "override of \$me after defs-static causes no error" + +r='ok' +if printf '%s\n' "$s" | grep '^me=zardoz$'; then :; else r='not ok'; fi +if printf '%s\n' "$s" | grep 'me=bad'; then r='not ok'; else :; fi +result_ "$r" "override of \$me after ./defs-static is honored" + +: diff --git a/tests/self-check-me.test b/tests/self-check-me.test deleted file mode 100755 index e8b1361..0000000 --- a/tests/self-check-me.test +++ /dev/null @@ -1,45 +0,0 @@ -#! /bin/sh -# Copyright (C) 2011 Free Software Foundation, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# Sanity check for the automake testsuite. -# Make sure that $me gets automatically defined by `./defs', and that it -# can be overridden by the test script. - -. ./defs-static || exit 1 - -set -ex - -AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC - -$SHELL -c '. ./defs && echo me=$me' foo-bar-.test | grep '^me=foo-bar-$' -$SHELL -c '. ./defs && echo me=$me' _foo__bar.test | grep '^me=_foo__bar$' -$SHELL -c '. ./defs && echo me=$me' 012.test | grep '^me=012$' -$SHELL -c '. ./defs && echo me=$me' foo.bar | grep '^me=foo\.bar$' -$SHELL -c '. ./defs && echo me=$me' a.b.c.test | grep '^me=a\.b\.c$' - -# Overriding $me after sourcing ./defs-static should work. -s=`$SHELL -c '. ./defs-static && me=zardoz && . ./defs && echo me=$me' \ - bad.test` || exit 1 -printf '%s\n' "$s" | grep '^me=zardoz$' -printf '%s\n' "$s" | grep 'me=bad' && exit 1 - -# If we override $me, ./defs should not modify it. -s=`$SHELL -c 'me=foo.test && . ./defs && echo me=$me' \ - bad.test` || exit 1 -printf '%s\n' "$s" | grep '^me=foo\.test$' -printf '%s\n' "$s" | grep 'me=bad' && exit 1 - -: -- 2.7.4