+2011-02-25 Stefano Lattarini <stefano.lattarini@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/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 <stefano.lattarini@gmail.com>
tests: tempdirs with restrictive permissions are cleaned correctly
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 \
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 \
--- /dev/null
+#! /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
+
+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
+
+:
--- /dev/null
+#! /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
--- /dev/null
+#! /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.
+
+. ./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
+
+:
--- /dev/null
+#! /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
+
+stat c d || : # for debugging
+
+is_newest c d
+
+:
--- /dev/null
+#! /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$'
+
+:
--- /dev/null
+#! /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 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
+
+:
--- /dev/null
+#! /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
+
+#------------------------------------------------------------------
+
+: