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/S_cleanup.test: New test, check removal of temporary test working directory by `./defs'. * tests/S_dir.test: New test, check that tests using `./defs' create a proper temporary directory, and run in it. * tests/S_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/S_is_newest.test: New test, checking the `is_newest' subroutine. * tests/S_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/S_sanity.test: New test, check that the sanity checks performed by the `tests/defs' script works correctly. * tests/S_unindent.test: New test, checking the `unindent' subroutine. * tests/Makefile.am (TESTS): Update. --- ChangeLog | 25 ++++++ tests/Makefile.am | 7 ++ tests/Makefile.in | 7 ++ tests/S_cleanup.test | 124 +++++++++++++++++++++++++++ tests/S_dir.test | 37 ++++++++ tests/S_exit.test | 58 +++++++++++++ tests/S_is_newest.test | 43 ++++++++++ tests/S_me.test | 29 +++++++ tests/S_sanity.test | 69 +++++++++++++++ tests/S_unindent.test | 217 ++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 617 insertions(+), 0 deletions(-) create mode 100755 tests/S_cleanup.test create mode 100755 tests/S_dir.test create mode 100755 tests/S_exit.test create mode 100755 tests/S_is_newest.test create mode 100755 tests/S_me.test create mode 100755 tests/S_sanity.test create mode 100755 tests/S_unindent.test
From 82cf2e7e42a0e8982e95ac2c0581593369bcf1cc Mon Sep 17 00:00:00 2001 From: Stefano Lattarini <stefano.lattar...@gmail.com> Date: Mon, 21 Feb 2011 14:57:24 +0100 Subject: [PATCH] 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/S_cleanup.test: New test, check removal of temporary test working directory by `./defs'. * tests/S_dir.test: New test, check that tests using `./defs' create a proper temporary directory, and run in it. * tests/S_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/S_is_newest.test: New test, checking the `is_newest' subroutine. * tests/S_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/S_sanity.test: New test, check that the sanity checks performed by the `tests/defs' script works correctly. * tests/S_unindent.test: New test, checking the `unindent' subroutine. * tests/Makefile.am (TESTS): Update. --- ChangeLog | 26 ++++++ tests/Makefile.am | 7 ++ tests/Makefile.in | 7 ++ tests/S_cleanup.test | 124 +++++++++++++++++++++++++++ tests/S_dir.test | 37 ++++++++ tests/S_exit.test | 58 +++++++++++++ tests/S_is_newest.test | 43 ++++++++++ tests/S_me.test | 29 +++++++ tests/S_sanity.test | 69 +++++++++++++++ tests/S_unindent.test | 217 ++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 617 insertions(+), 0 deletions(-) create mode 100755 tests/S_cleanup.test create mode 100755 tests/S_dir.test create mode 100755 tests/S_exit.test create mode 100755 tests/S_is_newest.test create mode 100755 tests/S_me.test create mode 100755 tests/S_sanity.test create mode 100755 tests/S_unindent.test diff --git a/ChangeLog b/ChangeLog index f1adebc..98de17e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2011-02-23 Stefano Lattarini <stefano.lattar...@gmail.com> + + 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/S_cleanup.test: New test, check removal of temporary + test working directory by `./defs'. + * tests/S_dir.test: New test, check that tests using `./defs' + create a proper temporary directory, and run in it. + * tests/S_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/S_is_newest.test: New test, checking the `is_newest' + subroutine. + * tests/S_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/S_sanity.test: New test, check that the sanity checks + performed by the `tests/defs' script works correctly. + * tests/S_unindent.test: New test, checking the `unindent' + subroutine. + * tests/Makefile.am (TESTS): Update. + 2011-02-20 Stefano Lattarini <stefano.lattar...@gmail.com> tests: tempdirs with restrictive permissions are cleaned correctly diff --git a/tests/Makefile.am b/tests/Makefile.am index 3709d47..f70decc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -97,6 +97,13 @@ XFAIL_TESTS += $(instspc_xfail_tests) TESTS = \ +S_cleanup.test \ +S_dir.test \ +S_exit.test \ +S_is_newest.test \ +S_me.test \ +S_sanity.test \ +S_unindent.test \ aclocal.test \ aclocal3.test \ aclocal4.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 68db8b5..486cfa4 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -359,6 +359,13 @@ instspc_xfail_tests = instspc-squote-build.test \ instspc-sharp-install.test instspc-dollar-install.test \ instspc-linefeed-install.test instspc-a_lf_b-install.test TESTS = \ +S_cleanup.test \ +S_dir.test \ +S_exit.test \ +S_is_newest.test \ +S_me.test \ +S_sanity.test \ +S_unindent.test \ aclocal.test \ aclocal3.test \ aclocal4.test \ diff --git a/tests/S_cleanup.test b/tests/S_cleanup.test new file mode 100755 index 0000000..ecc336b --- /dev/null +++ b/tests/S_cleanup.test @@ -0,0 +1,124 @@ +#! /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 <http://www.gnu.org/licenses/>. + +# Sanity check for the automake testsuite. +# Check creation/removal of temporary test working directory by `./defs'. + +. ./defs || Exit 1 + +# 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_simlinks=false +ln -s defs foo && test -h foo && have_simlinks=: +export have_simlinks # 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_simlinks; 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 do not unduly change the permissions of +# files to which symlinks in the temporary test directory point to. +if $have_simlinks; 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 upon the receiving of 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/S_dir.test b/tests/S_dir.test new file mode 100755 index 0000000..a8e5d88 --- /dev/null +++ b/tests/S_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 <http://www.gnu.org/licenses/>. + +# 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/S_exit.test b/tests/S_exit.test new file mode 100755 index 0000000..25a7219 --- /dev/null +++ b/tests/S_exit.test @@ -0,0 +1,58 @@ +#! /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 <http://www.gnu.org/licenses/>. + +# 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. + +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 \$\$" + $SHELL -c ". ./defs; kill -$sig \$\$; :" + rc=$? + echo "* rc=$rc" + echo + test $rc -eq 99 || exit 1 + +done + +: diff --git a/tests/S_is_newest.test b/tests/S_is_newest.test new file mode 100755 index 0000000..0378db6 --- /dev/null +++ b/tests/S_is_newest.test @@ -0,0 +1,43 @@ +#! /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 <http://www.gnu.org/licenses/>. + +# 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 || Exit 77 + +stat c d || : # for debugging + +is_newest c d +is_newest d c + +: diff --git a/tests/S_me.test b/tests/S_me.test new file mode 100755 index 0000000..5773e2c --- /dev/null +++ b/tests/S_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 <http://www.gnu.org/licenses/>. + +# 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/S_sanity.test b/tests/S_sanity.test new file mode 100755 index 0000000..532f37f --- /dev/null +++ b/tests/S_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 <http://www.gnu.org/licenses/>. + +# Sanity check for the automake testsuite. +# Test the sanity checks performed by the `defs' script. Also check that +# it can be used by duplicating some of infrastructure of the automake's +# tree `tests' subdirectory. + +. ./defs || Exit 1 + +# Avoid to confuse traces from children 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/S_unindent.test b/tests/S_unindent.test new file mode 100755 index 0000000..4672683 --- /dev/null +++ b/tests/S_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 <http://www.gnu.org/licenses/>. + +# Sanity check for the automake testsuite. +# Check the `unindent' subroutine. + +. ./defs || Exit 1 + +#------------------------------------------------------------------ + +: Leading spaces + +cat > input <<END + 1 + 2 +3 + 4 +${tab}5 +${tab} 6 + 6${sp} +7${sp} + 8${sp}${sp} +9${sp}${sp} + 10${tab} +11${tab} + 12${sp}${tab} +13${sp}${tab} + 14 this${tab}with${tab}multiple fields${sp} +15 and ${tab}${tab}this too${tab} + 16 and also this +${sp}${sp} +${sp} +${tab} + +last line +END + +cat > exp <<END +1 + 2 +3 + 4 +${tab}5 +${tab} 6 +6${sp} +7${sp} +8${sp}${sp} +9${sp}${sp} +10${tab} +11${tab} +12${sp}${tab} +13${sp}${tab} +14 this${tab}with${tab}multiple fields${sp} +15 and ${tab}${tab}this too${tab} + 16 and also this + +${sp} +${tab} + +last line +END + +unindent input > got + +diff exp got + +#------------------------------------------------------------------ + +: Leading tab + +cat > input <<END +${tab}1 +${tab} 2 +3 + 4 + 5 + 6 + 7 + ${tab}8 +${tab}${tab}9 +${tab}10${tab} +${tab}11${sp} +12${tab} +13${sp} +${tab}14 this with${tab}multiple fields${sp} +15 and ${tab}${tab}this too${tab} + 16 and also this +${tab} +${sp} +${sp}${tab} + +last line +END + +cat > exp <<END +1 + 2 +3 + 4 + 5 + 6 + 7 + ${tab}8 +${tab}9 +10${tab} +11${sp} +12${tab} +13${sp} +14 this with${tab}multiple fields${sp} +15 and ${tab}${tab}this too${tab} + 16 and also this + +${sp} +${sp}${tab} + +last line +END + +unindent input > got + +diff exp got + +#------------------------------------------------------------------ + +: No leading whitespace + +cat > input <<END +1 + 2 + 3 + 4 +${tab}5 +${tab} 6 + ${tab}7 +${tab}${tab}8 +9${sp} + 10${tab} +${tab}10${sp}${sp} +14 this with${tab}multiple fields${sp} + 15 and this too${tab} +${tab}16 and also this +${tab} +${sp} + +last line +END + +cp input exp + +unindent input > got + +diff exp got + +#------------------------------------------------------------------ + +: Leading empty lines are ignored [1] + +cat > input <<END + + + foo + bar + quux +END + +cat > exp <<END + + +foo +bar + quux +END + +unindent input > got + +diff exp got + +#------------------------------------------------------------------ + +: Leading empty lines are ignored [2] + +cat > input <<END + + +foo +bar + quux +END + +cat > exp <<END + + +foo +bar + quux +END + +unindent input > got + +diff exp got + +#------------------------------------------------------------------ + +: -- 1.7.2.3