automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[FYI] {testsuite-work} self tests: more use of TAP


From: Stefano Lattarini
Subject: [FYI] {testsuite-work} self tests: more use of TAP
Date: Wed, 7 Sep 2011 14:35:50 +0200

* tests/self-check-reexec.test: Renamed ...
* tests/self-check-reexec.tap: ... to this, converted to the
use of TAP protocol, and extended a bit.
* tests/self-check-seq.test: Renamed ...
* tests/self-check-seq.tap: ... to this, and converted to the
use of TAP protocol.
* tests/list-of-tests.mk: Update.
---
 ChangeLog                    |   11 +++
 tests/Makefile.in            |    4 +-
 tests/list-of-tests.mk       |    4 +-
 tests/self-check-reexec.tap  |  205 ++++++++++++++++++++++++++++++++++++++++++
 tests/self-check-reexec.test |  127 --------------------------
 tests/self-check-seq.tap     |   75 +++++++++++++++
 tests/self-check-seq.test    |   75 ---------------
 7 files changed, 295 insertions(+), 206 deletions(-)
 create mode 100755 tests/self-check-reexec.tap
 delete mode 100755 tests/self-check-reexec.test
 create mode 100755 tests/self-check-seq.tap
 delete mode 100755 tests/self-check-seq.test

diff --git a/ChangeLog b/ChangeLog
index 1142bc6..8c1e1cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2011-09-07  Stefano Lattarini  <address@hidden>
 
+       self tests: more use of TAP
+       * tests/self-check-reexec.test: Renamed ...
+       * tests/self-check-reexec.tap: ... to this, converted to the
+       use of TAP protocol, and extended a bit.
+       * tests/self-check-seq.test: Renamed ...
+       * tests/self-check-seq.tap: ... to this, and converted to the
+       use of TAP protocol.
+       * tests/list-of-tests.mk: Update.
+
+2011-09-07  Stefano Lattarini  <address@hidden>
+
        self tests: fix spurious failures when /bin/ksh do not exists
        * tests/self-check-reexec.test: Ensure that the non-bash shells
        we look do really exists.  Since we are at it, also try the name
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 556bf86..b2df0e7 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -1130,10 +1130,10 @@ self-check-exit.tap \
 self-check-explicit-skips.test \
 self-check-is_newest.tap \
 self-check-me.tap \
-self-check-reexec.test \
+self-check-reexec.tap \
 self-check-report.test \
 self-check-sanity.test \
-self-check-seq.test \
+self-check-seq.tap \
 self-check-is-blocked-signal.tap \
 self-check-tap.test \
 self-check-unindent.tap \
diff --git a/tests/list-of-tests.mk b/tests/list-of-tests.mk
index 4783b09..988b4f0 100644
--- a/tests/list-of-tests.mk
+++ b/tests/list-of-tests.mk
@@ -805,10 +805,10 @@ self-check-exit.tap \
 self-check-explicit-skips.test \
 self-check-is_newest.tap \
 self-check-me.tap \
-self-check-reexec.test \
+self-check-reexec.tap \
 self-check-report.test \
 self-check-sanity.test \
-self-check-seq.test \
+self-check-seq.tap \
 self-check-is-blocked-signal.tap \
 self-check-tap.test \
 self-check-unindent.tap \
diff --git a/tests/self-check-reexec.tap b/tests/self-check-reexec.tap
new file mode 100755
index 0000000..0982719
--- /dev/null
+++ b/tests/self-check-reexec.tap
@@ -0,0 +1,205 @@
+#! /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 automatic re-execution of test script with the
+# configure-time $SHELL.
+
+am_create_testdir=empty
+. ./defs || Exit 1
+
+plan_ 32
+
+unset AM_TESTS_REEXEC BASH_VERSION || :
+
+cwd=`pwd` || fatal_ "cannot get current working directory"
+cp ../defs .
+
+#
+# Search for required bash and non-bash shells.
+#
+
+for bash_shell in "$SHELL" bash bash3 bash4 :; do
+  test "$bash_shell" = : && break
+  $bash_shell --version || continue
+  $bash_shell -c 'test -n "$BASH_VERSION"' || continue
+  break
+done
+
+# This might not be optimal, but it's much better than writing wrapper
+# scripts acting as "fake" shells.
+for non_bash_shell in /bin/sh /bin/ksh "$SHELL" sh ksh ash dash pdksh :; do
+  test "$non_bash_shell" = : && break
+  $non_bash_shell -c 'exit 0' || continue
+  $non_bash_shell -c 'test -n "$BASH_VERSION"' && continue
+  break
+done
+
+echo "bash_shell='$bash_shell'"
+echo "non_bash_shell='$non_bash_shell'"
+
+# This would denote an internal error.
+if test "$bash_shell" = : && test "$non_bash_shell" = :; then
+  fatal_ "we couldn't find a bash shell nor a non-bash one"
+fi
+
+#
+# Functions used throughout the test.
+#
+
+get_ddata ()
+{
+  case $1 in
+    ""|*/) dsep=;;
+        *) dsep=/;;
+  esac
+  case $1 in
+    "") dname="no dir";;
+    /*) dname="absolute dir";;
+     *) dname="dir '$1'";;
+  esac
+}
+
+get_sh ()
+{
+  case $1 in
+    bash) sh=$bash_shell;;
+    non-bash) sh=$non_bash_shell;;
+    *) fatal_ "get_sh: invalid shell type '$1'";;
+  esac
+}
+
+#
+# Check how to default, force or prevent a re-execution.
+#
+
+cat > need-bash.test <<'END'
+#!/bin/false
+. ./defs
+# Ensure that the script gets re-executed with bash.  Also ensure that
+# non-standard syntax used after the inclusion of `./defs' doesn't cause
+# non-bash shells to fail.
+# Subshell required to prevent some shells (e.g., Solaris 10 /bin/sh)
+# from only complaining on stderr but then exiting with exit status 0.
+(foo=abac && test xbxc = ${foo//a/x} && test -n "$BASH_VERSION")
+END
+
+sed -e "s|^testbuilddir=.*|testbuilddir='$cwd'|" \
+    -e 's|^SHELL=.*$|SHELL=bash; export SHELL|' \
+    < ../defs-static >defs-static
+
+do_reexec ()
+{
+  command_ok_ "re-exec if AM_TESTS_REEXEC=$1" \
+              env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.test
+}
+
+dont_reexec ()
+{
+  command_ok_ "don't re-exec if AM_TESTS_REEXEC=$1" \
+              not env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.test
+}
+
+if test "$bash_shell" = :; then
+  skip_row_ 10 -r "no bash shell found" AM_TESTS_REEXEC
+elif test "$non_bash_shell" = :; then
+  skip_row_ 10 -r "no non-bash shell found" AM_TESTS_REEXEC
+else
+  command_ok_ "re-exec if AM_TESTS_REEXEC unset" \
+              $non_bash_shell need-bash.test
+  do_reexec ''
+  do_reexec yes
+  do_reexec y
+  do_reexec true
+  do_reexec 1
+  dont_reexec no
+  dont_reexec n
+  dont_reexec false
+  dont_reexec 0
+fi
+
+#
+# Check message about the re-execution.  Also check that arguments passed
+# to a test script are preserved by a re-exec, even in "corner" cases.
+#
+
+cat > dummy.test <<'END'
+#!/bin/sh
+. ./defs
+:
+END
+
+cat > checkargs.test <<'END'
+. ./defs
+test $# -eq 3 && test x"$1" = x'a' && test x"$2" = x && test x"$3" = x"-e"
+END
+
+chmod a+x dummy.test checkargs.test
+
+mkdir sub
+cp dummy.test checkargs.test defs sub
+sed -e "s|^testbuilddir=.*|testbuilddir='$cwd'|" \
+    < ../defs-static > defs-static
+sed -e "s|^testbuilddir=.*|testbuilddir='$cwd/sub'|" \
+    < ../defs-static > sub/defs-static
+
+check_preserve_args ()
+{
+  dir=$1; shift
+  get_ddata "$dir"
+  $sh "${dir}${dsep}checkargs.test" a '' -e && r='ok' || r='not ok'
+  result_ "$r" "$sh re-exec preserving args [$dname]"
+}
+
+check_reexec_message ()
+{
+  dir=$1; shift
+  get_ddata "$dir"
+  $sh "${dir}${dsep}dummy.test" "$@" \
+    | grep "^dummy: exec $SHELL ${dir}${dsep}dummy\\.test $*\$" \
+    && r='ok' || r='not ok'
+  result_ "$r" "$sh display re-exec message [$dname] [args: $*]"
+}
+
+./dummy.test a b | grep "^dummy: exec $SHELL \\./dummy\\.test a b$" \
+  && r='ok' || r='not ok'
+result_ "$r" "direct run display re-exec message [args: a b]"
+
+./checkargs.test a '' -e && r='ok' || r='not ok'
+result_ "$r" "direct re-exec preserving args"
+
+for sh_type in non-bash bash; do
+  get_sh $sh_type
+  if test "$sh" = :; then
+    skip_row_ 5 -r "no $sh_type shell available" "re-exec message"
+    skip_row_ 5 -r "no $sh_type shell available" "re-exec preserving args"
+    continue
+  fi
+  check_preserve_args ''
+  check_reexec_message '' a b c
+  check_preserve_args .
+  check_reexec_message .  a b c
+  cd sub
+  check_preserve_args ..
+  check_reexec_message .. a b c
+  cd ..
+  check_preserve_args "$cwd"
+  check_reexec_message "$cwd" a -b c-
+  check_preserve_args sub
+  check_reexec_message sub 1 2 3 4
+done
+
+:
diff --git a/tests/self-check-reexec.test b/tests/self-check-reexec.test
deleted file mode 100755
index 46cd0d4..0000000
--- a/tests/self-check-reexec.test
+++ /dev/null
@@ -1,127 +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 <http://www.gnu.org/licenses/>.
-
-# Sanity check for the automake testsuite.
-# Check that automatic re-execution of test script with the
-# configure-time $SHELL.
-
-required=bash
-. ./defs || Exit 1
-
-unset AM_TESTS_REEXEC BASH_VERSION || :
-
-# This is not optimal, but it's much better than writing wrapper
-# scripts acting as "fake" shells.
-
-bash -c 'test -n "$BASH_VERSION"' || skip_ "bash shell not found"
-
-for shell in /bin/sh /bin/ksh sh ksh ash dash pdksh __no_shell__; do
-  test $shell = __no_shell__ && skip_ "can't find any non-bash shell"
-  $shell -c 'exit 0' || continue
-  $shell -c 'test -n "$BASH_VERSION"' && continue
-  break
-done
-echo "shell='$shell'"
-
-cwd=`pwd` || Exit 99
-
-cp ../defs .
-
-#
-# Check how to default, force or prevent a re-execution.
-#
-
-cat > run-with-bash.test <<'END'
-#!/bin/false
-. ./defs
-# Ensure that the script gets re-executed with bash.  Also ensure that
-# non-standard syntax used after the inclusion of `./defs' doesn't cause
-# non-bash shells to fail.
-# Subshell required to prevent some shells (e.g., Solaris 10 /bin/sh)
-# from only complaining on stderr but then exiting with exit status 0.
-(foo=abac && test xbxc = ${foo//a/x} && test -n "$BASH_VERSION")
-END
-
-sed -e "s|^testbuilddir=.*|testbuilddir='$cwd'|" \
-    -e 's|^SHELL=.*$|SHELL=bash; export SHELL|' \
-    < ../defs-static >defs-static
-
-$shell -x run-with-bash.test
-
-AM_TESTS_REEXEC=''    $shell run-with-bash.test
-AM_TESTS_REEXEC=yes   $shell run-with-bash.test
-AM_TESTS_REEXEC=y     $shell run-with-bash.test
-AM_TESTS_REEXEC=true  $shell run-with-bash.test
-AM_TESTS_REEXEC=1     $shell run-with-bash.test
-AM_TESTS_REEXEC=no    $shell run-with-bash.test && Exit 1
-AM_TESTS_REEXEC=n     $shell run-with-bash.test && Exit 1
-AM_TESTS_REEXEC=false $shell run-with-bash.test && Exit 1
-AM_TESTS_REEXEC=0     $shell run-with-bash.test && Exit 1
-
-#
-# Check message about the re-execution.
-#
-
-cat > dummy.test <<'END'
-#!/bin/sh
-. ./defs
-:
-END
-chmod a+x dummy.test
-
-mkdir sub
-cp dummy.test defs sub
-sed -e "s|^testbuilddir=.*|testbuilddir='$cwd'|" \
-    < ../defs-static > defs-static
-sed -e "s|^testbuilddir=.*|testbuilddir='$cwd/sub'|" \
-    < ../defs-static > sub/defs-static
-
-./dummy.test a b | grep "^dummy: exec $SHELL \\./dummy\\.test a b$"
-
-for am_sh in $shell bash; do
-  $am_sh dummy.test a b c \
-    | grep "^dummy: exec $SHELL dummy\\.test a b c$"
-  $am_sh ./dummy.test a b c \
-    | grep "^dummy: exec $SHELL \\./dummy\\.test a b c$"
-  cd sub
-  $am_sh ../dummy.test a b \
-    | grep "dummy: exec $SHELL \\.\\./dummy\\.test a b$"
-  cd ..
-  $am_sh "$cwd/dummy.test" a -b c- \
-    | grep "^dummy: exec $SHELL $cwd/dummy\\.test a -b c-$"
-  $am_sh sub/dummy.test 1 2 3 4 \
-    | grep "^dummy: exec $SHELL sub/dummy\\.test 1 2 3 4$"
-done
-
-#
-# Check that arguments passed to a test script are preserved by a re-exec.
-#
-
-cat > checkargs.test <<'END'
-. ./defs
-test $# -eq 3 && test x"$1" = x'a' && test x"$2" = x && test x"$3" = x"-e"
-END
-
-$SHELL checkargs.test a '' -e
-$SHELL ./checkargs.test a '' -e
-$SHELL "$cwd/checkargs.test" a '' -e
-cd sub
-$SHELL ../checkargs.test a '' -e
-cd ..
-cp checkargs.test sub
-$SHELL sub/checkargs.test a '' -e
-
-:
diff --git a/tests/self-check-seq.tap b/tests/self-check-seq.tap
new file mode 100755
index 0000000..e643c34
--- /dev/null
+++ b/tests/self-check-seq.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 <http://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite.
+# Check the `seq_' subroutine.
+
+. ./defs || Exit 1
+
+plan_ 14
+
+unset stderr_fileno_ || :
+
+check_work ()
+{
+  desc=$1 args=$2 exp=$3
+  st=0; got=`seq_ $args` || st=$?
+  command_ok_ "$desc [exit status = 0]" test $st -eq 0
+  command_ok_ "$desc [output]" test x"$exp" = x"$got"
+}
+
+check_work 'one-argument form' '5' "\
+1
+2
+3
+4
+5"
+
+check_work 'two-arguments form' '7 11' "\
+7
+8
+9
+10
+11"
+
+check_work 'three-arguments form (1)' '120 5 135' "\
+120
+125
+130
+135"
+
+check_work 'three-arguments form (1)' '13 4 23' "\
+13
+17
+21"
+
+check_err ()
+{
+  desc=$1 args=$2 err=$3
+  (seq_ $args) >output || st=$?
+  # Protect content emitted on stdout/stderr, to avoid sending to the
+  # TAP driver possible "Bail out!" directives generated by `seq_'.
+  # Use `grep -c' below for the same reason.
+  sed 's/^/: /' output
+  command_ok_ "$desc [exit status = 99]" test $st -eq 99
+  command_ok_ "$desc [error message]" grep -c "seq_: $err" output
+}
+
+check_err 'no argument is an error' '' 'missing argument'
+check_err 'four arguments is an error' '1 1 2 1' 'too many arguments'
+check_err 'six arguments is an error' '1 1 1 1 1 1' 'too many arguments'
+
+:
diff --git a/tests/self-check-seq.test b/tests/self-check-seq.test
deleted file mode 100755
index 7e0fdf4..0000000
--- a/tests/self-check-seq.test
+++ /dev/null
@@ -1,75 +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 <http://www.gnu.org/licenses/>.
-
-# Sanity check for the automake testsuite.
-# Check the `seq_' subroutine.
-
-. ./defs || Exit 1
-
-unset stderr_fileno_ || :
-
-: One-argument form.
-exp="\
-1
-2
-3
-4
-5"
-got=`seq_ 5` || Exit 1
-test x"$exp" = x"$got" || Exit 1
-
-: Two-arguments form.
-exp="\
-7
-8
-9
-10
-11"
-got=`seq_ 7 11` || Exit 1
-test x"$exp" = x"$got" || Exit 1
-
-: Three-arguments form [1].
-exp="\
-120
-125
-130
-135"
-got=`seq_ 120 5 135` || Exit 1
-test x"$exp" = x"$got" || Exit 1
-
-: Three-arguments form [2].
-exp="\
-13
-17
-21"
-got=`seq_ 13 4 23` || Exit 1
-test x"$exp" = x"$got" || Exit 1
-
-: No argument is an error.
-st=0
-(seq_) 2>stderr || st=$?
-test $st -eq 99
-grep 'seq_: missing argument' stderr
-
-: Four or more arguments is an error.
-for args in '1 1 2 1' '1 1 1 1 1 1'; do
-  st=0
-  (seq_ $args) 2>stderr || st=$?
-  test $st -eq 99
-  grep 'seq_: too many arguments' stderr
-done
-
-:
-- 
1.7.2.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]