From: Stefano Lattarini Date: Mon, 21 Feb 2011 13:57:24 +0000 (+0100) Subject: tests: add testcases sanity-checking the testsuite X-Git-Tag: ng-0.5a~229 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=082028c1dbb8e23e3a7b32ebaa3d92321b55cb15;p=thirdparty%2Fautomake.git tests: add testcases sanity-checking the testsuite Helper subroutines, variables and other pieces of code defined in the `tests/defs' and used by many testcases are non-obvious, and tricky to get to work portably; but until now, they weren't tested at all in a clear and self-contained way. This change should remedy to the situation. * tests/self-check-cleanup.test: New test, check removal of temporary test working directory by `./defs'. * tests/self-check-dir.test: New test, check that tests using `./defs' create a proper temporary directory, and run in it. * tests/self-check-exit.test: New test, check that, in case of failing commands, the correct exit status is passed to the exit trap installed by the `./defs' script. * tests/self-check-is_newest.test: New test, checking the `is_newest' subroutine. * tests/self-check-me.test: New test, checking that $me gets defined automatically by `tests/defs' if not set, and that it can be overridden from either the shell or the environment. * tests/self-check-sanity.test: New test, check that the sanity checks performed by the `tests/defs' script works correctly. * tests/self-check-unindent.test: New test, checking the `unindent' subroutine. * tests/Makefile.am (TESTS): Update. --- diff --git a/ChangeLog b/ChangeLog index f1adebc0c..5ef0c0d87 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2011-02-25 Stefano Lattarini + + tests: add testcases sanity-checking the testsuite + Helper subroutines, variables and other pieces of code defined + in the `tests/defs' and used by many testcases are non-obvious, + and tricky to get to work portably; but until now, they weren't + tested at all in a clear and self-contained way. + This change should remedy to the situation. + * tests/self-check-cleanup.test: New test, check removal of + temporary test working directory by `./defs'. + * tests/self-check-dir.test: New test, check that tests using + `./defs' create a proper temporary directory, and run in it. + * tests/self-check-exit.test: New test, check that, in case of + failing commands, the correct exit status is passed to the exit + trap installed by the `./defs' script. + * tests/self-check-is_newest.test: New test, checking the + `is_newest' subroutine. + * tests/self-check-me.test: New test, checking that $me gets + defined automatically by `tests/defs' if not set, and that it + can be overridden from either the shell or the environment. + * tests/self-check-sanity.test: New test, check that the sanity + checks performed by the `tests/defs' script works correctly. + * tests/self-check-unindent.test: New test, checking the + `unindent' subroutine. + * tests/Makefile.am (TESTS): Update. + 2011-02-20 Stefano Lattarini tests: tempdirs with restrictive permissions are cleaned correctly diff --git a/tests/Makefile.am b/tests/Makefile.am index 3709d4766..e80891716 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -788,6 +788,13 @@ reqd.test \ reqd2.test \ repeated-options.test \ rulepat.test \ +self-check-cleanup.test \ +self-check-dir.test \ +self-check-exit.test \ +self-check-is_newest.test \ +self-check-me.test \ +self-check-sanity.test \ +self-check-unindent.test \ sanity.test \ scripts.test \ seenc.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 68db8b5a1..451dff5c8 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1050,6 +1050,13 @@ reqd.test \ reqd2.test \ repeated-options.test \ rulepat.test \ +self-check-cleanup.test \ +self-check-dir.test \ +self-check-exit.test \ +self-check-is_newest.test \ +self-check-me.test \ +self-check-sanity.test \ +self-check-unindent.test \ sanity.test \ scripts.test \ seenc.test \ diff --git a/tests/self-check-cleanup.test b/tests/self-check-cleanup.test new file mode 100755 index 000000000..92a203e98 --- /dev/null +++ b/tests/self-check-cleanup.test @@ -0,0 +1,129 @@ +#! /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. +# Check creation/removal of temporary test working directory by `./defs'. + +. ./defs || Exit 1 + +if test x"$sh_errexit_works" != x"yes"; then + echo "$me: the shell can't have a working exit trap with 'set -e'" >&2 + Exit 77 +fi + +# We still need a little hack to make ./defs work outside automake's +# tree `tests' subdirectory. Not a big deal. +sed "s|^testbuilddir=.*|testbuilddir='`pwd`'|" ../defs-static >defs-static +cp ../defs . + +have_symlinks=false +ln -s defs foo && have_symlinks=: +export have_symlinks # Is used also by spawned shells. + +dir=dummy.dir + +# Check that pre-test cleanup works also with directories with +# "null" permissions, and containing broken symlinks. +mkdir $dir $dir/sub +cd $dir +touch file sub/file +if $have_symlinks; then + ln -s file symlink + ln -s none brokenlink +fi +cd .. +chmod 000 $dir/sub/* $dir/file $dir/symlink +chmod 000 $dir/sub $dir +$SHELL -c '. ./defs' dummy.test +test ! -f $dir +test ! -d $dir +test ! -r $dir + +# Check that post-test cleanup works also with directories with +# "null" permissions, and containing broken symlinks. +$SHELL -c ' + . ./defs || Exit 1 + set -e + mkdir dir dir/sub + cd dir + touch file sub/file + if $have_symlinks; then + ln -s file symlink + ln -s none brokenlink + fi + cd .. + chmod 000 dir/sub/* dir/file dir/symlink + chmod 000 dir/sub dir +' dummy.test +test ! -f $dir +test ! -d $dir +test ! -r $dir + +# Check that pre-test cleanup does not unduly change the permissions of +# files to which symlinks in the temporary test directory point to. +if $have_symlinks; then + + mkdir dir + chmod 000 dir + : > file + chmod 000 file + + mkdir $dir + cd $dir + ln -s ../dir ../file . + cd .. + $SHELL -c '. ./defs' dummy.test + ls -l # For debugging. + ls -l file | grep "^---------- .*file" + ls -ld dir | grep "^d--------- .*dir" + + $SHELL -c ' + ocwd=`pwd` || exit 1 + . ./defs || Exit 1 + ln -s "$ocwd/dir" "$ocwd/file" . + ' dummy.test + ls -l # For debugging. + ls -l file | grep "^---------- .*file" + ls -ld dir | grep "^d--------- .*dir" + + rmdir dir + rm -f file + +fi # $have_symlinks + +# Check that the cleanup trap does not remove the temporary +# test directory in case of test failure, skip, hard-error, +# or when receiving a signal. +for bailout_command in \ + 'Exit 1' \ + 'Exit 2' \ + 'Exit 10' \ + 'Exit 77' \ + 'Exit 99' \ + 'Exit 126' \ + 'Exit 127' \ + 'Exit 255' \ + 'kill -1 $$' \ + 'kill -2 $$' \ + 'kill -9 $$' \ + 'kill -13 $$' \ + 'kill -15 $$' \ +; do + $SHELL -c ". ./defs; : > foo; $bailout_command" dummy.test && Exit 1 + test -f dummy.dir/foo +done + +: diff --git a/tests/self-check-dir.test b/tests/self-check-dir.test new file mode 100755 index 000000000..a8e5d889a --- /dev/null +++ b/tests/self-check-dir.test @@ -0,0 +1,37 @@ +#! /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. +# Check that tests using `./defs' create a proper temporary directory, +# and run in it. + +set -ex + +this=S_dir +outcome=: +pwd + +rm -f $this.tmp + +$SHELL -c " + . ./defs || Exit 1 + : > $this.tmp + case \`pwd\` in '`pwd`'/$this.dir);; *) Exit 1;; esac +" $this.test || outcome=false + +test -f $this.tmp && { rm -f $this.tmp; outcome=false; } + +$outcome diff --git a/tests/self-check-exit.test b/tests/self-check-exit.test new file mode 100755 index 000000000..73f3ea5f9 --- /dev/null +++ b/tests/self-check-exit.test @@ -0,0 +1,80 @@ +#! /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. +# Check that. in case of failing commands, the correct exit status is +# passed to the exit trap installed by the `./defs' script. +# Also check that the `errexit' shell flag is active. + +. ./defs-static || exit 99 + +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 + +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=$? + 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 + 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 + fi + +done + +: diff --git a/tests/self-check-is_newest.test b/tests/self-check-is_newest.test new file mode 100755 index 000000000..f17922952 --- /dev/null +++ b/tests/self-check-is_newest.test @@ -0,0 +1,42 @@ +#! /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. +# Check the `is_newest' subroutine. + +. ./defs || Exit 1 + +: > a +$sleep +: > b +: > c + +stat a b c || : # for debugging + +is_newest c a +is_newest b a +is_newest a b && Exit 1 +is_newest c b +is_newest c c +is_newest c a b c + +touch -r c d + +stat c d || : # for debugging + +is_newest c d + +: diff --git a/tests/self-check-me.test b/tests/self-check-me.test new file mode 100755 index 000000000..5773e2c2a --- /dev/null +++ b/tests/self-check-me.test @@ -0,0 +1,29 @@ +#! /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'. + +set -ex + +: ${SHELL=/bin/sh} + +$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$' + +: diff --git a/tests/self-check-sanity.test b/tests/self-check-sanity.test new file mode 100755 index 000000000..d35432f69 --- /dev/null +++ b/tests/self-check-sanity.test @@ -0,0 +1,69 @@ +#! /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. +# Test the sanity checks performed by the `defs' script. Also check +# that we can use `defs' elsewhere, when we duplicate some of the +# infrastructure from the automake/tests subdirectory. + +. ./defs || Exit 1 + +# Avoid to confuse traces from child processed with our own traces. +show_stderr () +{ + sed 's/^/ | /' stderr >&2 +} + +if $SHELL -c '. ../defs' dummy.test 2>stderr; then + show_stderr + Exit 1 +else + show_stderr + grep 'defs-static: not found in current directory' stderr +fi + +sed 's|^testsrcdir=.*|testsrcdir=foo|' ../defs-static > defs-static +if $SHELL -c '. ../defs' dummy.test 2>stderr; then + show_stderr + Exit 1 +else + show_stderr + grep 'foo/defs-static\.in not found.*check \$testsrcdir' stderr +fi + +sed 's|^testbuilddir=.*|testbuilddir=foo|' ../defs-static > defs-static +if $SHELL -c '. ../defs' dummy.test 2>stderr; then + show_stderr + Exit 1 +else + show_stderr + grep 'foo/defs-static not found.*check \$testbuilddir' stderr +fi + +# We still need a little hack to make ./defs work outside automake's +# tree `tests' subdirectory. Not a big deal. +sed "s|^testbuilddir=.*|testbuilddir='`pwd`'|" ../defs-static >defs-static +# Redefining *srcdir and *builddir variables in the environment shouldn't +# cause problems +env \ + builddir=bad-dir srcdir=bad-dir \ + top_builddir=bad-dir top_srcdir=bad-dir \ + abs_builddir=bad-dir abs_srcdir=bad-dir \ + abs_top_builddir=bad-dir abs_top_srcdir=bad-dir \ + $SHELL -c '. ../defs && echo "!OK!" > ../foo' dummy.test +$FGREP '!OK!' foo + +: diff --git a/tests/self-check-unindent.test b/tests/self-check-unindent.test new file mode 100755 index 000000000..4672683de --- /dev/null +++ b/tests/self-check-unindent.test @@ -0,0 +1,217 @@ +#! /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. +# Check the `unindent' subroutine. + +. ./defs || Exit 1 + +#------------------------------------------------------------------ + +: Leading spaces + +cat > input < exp < got + +diff exp got + +#------------------------------------------------------------------ + +: Leading tab + +cat > input < exp < got + +diff exp got + +#------------------------------------------------------------------ + +: No leading whitespace + +cat > input < got + +diff exp got + +#------------------------------------------------------------------ + +: Leading empty lines are ignored [1] + +cat > input < exp < got + +diff exp got + +#------------------------------------------------------------------ + +: Leading empty lines are ignored [2] + +cat > input < exp < got + +diff exp got + +#------------------------------------------------------------------ + +: