This simplifies the tests since, among other things, we no longer have
to manage temporary files ourselves, since the init.sh file manages that
for us. It also serves as a good example since many GNU packages use
this script.

* NEWS: Mention the improvement.
* bootstrap.conf (bootstrap_post_import_hook): Copy tests/init.sh from
Gnulib.
* Makefile.am (EXTRA_DIST): Add the file imported from Gnulib.
* .gitignore: Likewise.
* cfg.mk (VERBOSE): New variable.
* tests/atexit-1: Use the new file.
* tests/greeting-1: Likewise.
* tests/hello-1: Likewise.
* tests/last-1: Likewise.
* tests/operand-1: Likewise.
* tests/traditional-1: Likewise.
* tests/greeting-2: Likewise. Reword a comment.
---
 .gitignore          |  1 +
 Makefile.am         |  3 ++-
 NEWS                |  2 ++
 bootstrap.conf      |  3 +++
 cfg.mk              |  4 ++++
 tests/atexit-1      | 24 ++++++------------------
 tests/greeting-1    | 23 +++++------------------
 tests/greeting-2    | 27 ++++++++++-----------------
 tests/hello-1       | 28 +++++-----------------------
 tests/last-1        | 29 +++++------------------------
 tests/operand-1     | 23 +++++------------------
 tests/traditional-1 | 28 +++++-----------------------
 12 files changed, 53 insertions(+), 142 deletions(-)

diff --git a/.gitignore b/.gitignore
index 656e3eb..a5c419b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,6 +33,7 @@
 /lib
 /m4
 /maint.mk
+/tests/init.sh
 /tight-scope.mk
 /Makefile
 /Makefile.in
diff --git a/Makefile.am b/Makefile.am
index 73dc97a..c2d9f57 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -30,7 +30,8 @@ EXTRA_DIST = \
        README-dev \
        ChangeLog.O \
        m4/gnulib-cache.m4 \
-       man/hello.x
+       man/hello.x \
+       tests/init.sh
 
 # Subdirectories to descend into.
 SUBDIRS = po
diff --git a/NEWS b/NEWS
index f7fa3df..dc9afbe 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ GNU Hello NEWS                                         -*- 
outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+The test suite now uses the init.sh test framework from Gnulib, which is
+used by many other GNU packages.
 
 * Noteworthy changes in release 2.12.3 (2026-03-17) [stable]
 
diff --git a/bootstrap.conf b/bootstrap.conf
index 782c1c7..c6f9df4 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -92,6 +92,9 @@ bootstrap_post_import_hook ()
 {
   # Automake requires that ChangeLog exist.
   touch ChangeLog || return 1
+
+  # Copy tests/init.sh from Gnulib.
+  $gnulib_tool --copy-file tests/init.sh
 }
 
 # File that should exist in the top directory of a checked out hierarchy,
diff --git a/cfg.mk b/cfg.mk
index 222ec94..6ef3bca 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -19,6 +19,10 @@ GNULIB_SRCDIR ?= $(srcdir)/gnulib
 gnulib_dir = $(GNULIB_SRCDIR)
 manual_title = GNU Hello
 
+# This causes tests/init.sh to emit the commands being executed in logs,
+# which is useful for investigating failures.
+export VERBOSE = yes
+
 # Write cksum supported checksums into the announcement.
 # I.e., base64 to reduce space, and possibly tagged to ease usage.
 announce_gen_args = --cksum-checksums
diff --git a/tests/atexit-1 b/tests/atexit-1
index 2d906f1..81ee9fe 100755
--- a/tests/atexit-1
+++ b/tests/atexit-1
@@ -7,25 +7,13 @@
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
 
-trap 'rm -fr $tmpfiles' 1 2 3 15
+. "${srcdir=.}/tests/init.sh"; path_prepend_ .
 
-if ! [ -c /dev/full ]; then
-  # no such character device, skip this check
-  exit 77
+if ! test -w /dev/full || ! test -c /dev/full; then
+  skip_ '/dev/full is required'
 fi
 
-tmpfiles="$tmpfiles atexit-test1.out"
-: ${HELLO=hello}
-${HELLO} 2>&1 1>/dev/full | tr -d '\r' >atexit-test1.out
+returns_ 1 hello >/dev/full 2>err || fail=1
+grep "^hello: write error" err || fail=1
 
-# remove \r (CR) characters from the output, so that the tests work on
-# platforms with CRLF line endings.  There is apparently no reliable
-# method (across Cygwin, MingW, etc.) to force an eol style.
-
-: ${GREP=grep}
-${GREP} "^hello: write error" atexit-test1.out
-result=$?
-
-rm -fr $tmpfiles
-
-exit $result
+Exit $fail
diff --git a/tests/greeting-1 b/tests/greeting-1
index d32285e..b4e21bd 100755
--- a/tests/greeting-1
+++ b/tests/greeting-1
@@ -7,28 +7,15 @@
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
 
-trap 'rm -fr $tmpfiles' 1 2 3 15
+. "${srcdir=.}/tests/init.sh"; path_prepend_ .
 
 # No locale settings in this test, since we are using a fixed string;
 # nothing in the output should be locale-dependent.
 
-tmpfiles="greeting-test1.ok"
-cat <<EOF >greeting-test1.ok
+cat <<EOF >exp || framework_failure_
 Nothing happens here.
 EOF
+hello -g 'Nothing happens here.' >out || fail=1
+compare exp out || fail=1
 
-tmpfiles="$tmpfiles greeting-test1.out"
-: ${HELLO=hello}
-${HELLO} -g 'Nothing happens here.' | tr -d '\r' >greeting-test1.out
-
-# remove \r (CR) characters from the output, so that the tests work on
-# platforms with CRLF line endings.  There is apparently no reliable
-# method (across Cygwin, MingW, etc.) to force an eol style.
-
-: ${DIFF=diff}
-${DIFF} greeting-test1.ok greeting-test1.out
-result=$?
-
-rm -fr $tmpfiles
-
-exit $result
+Exit $fail
diff --git a/tests/greeting-2 b/tests/greeting-2
index 3b83704..0610f17 100755
--- a/tests/greeting-2
+++ b/tests/greeting-2
@@ -8,10 +8,9 @@
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
 
-trap 'rm -fr $tmpfiles' 1 2 3 15
+. "${srcdir=.}/tests/init.sh"; path_prepend_ .
 
-tmpfiles="greeting-test2.ok"
-cat <<EOF > greeting-test2.ok
+cat <<EOF >exp || framework_failure_
 
Wuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuhhh!
 EOF
 
@@ -26,23 +25,17 @@ remainder=`expr $seconds_since_2000 % 2551443`
 # Full moon is around remainder = 1760000, oscillating between ca. 1720000
 # and ca. 1805000. Allow a tolerance of +/- 24 h.
 if test `expr $remainder '>' 1650000` = 0 || test `expr $remainder '<' 
1890000` = 0; then
-  { echo "$0: Skipping test: not a full moon night"; rm -fr $tmpfiles; exit 
77; }
+  skip_ 'not a full moon night'
 fi
 
-# The exit 77 is the magic value which tells Automake's `make check'
-# that this test was skipped.  It's also good to give a
-# human-understandable reason why the test was skipped, so the person
+# The skip_ function calls exit 77, which is the magic value which tells
+# Automake's `make check' that this test was skipped.  It's also good to
+# give a human-understandable reason why the test was skipped, so the person
 # running the test can know.
 
-tmpfiles="$tmpfiles greeting-test2.out"
-: ${HELLO=hello}
-${HELLO} -g 
'Wuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuhhh!'
 \
-| tr -d '\r' >greeting-test2.out
+hello -g 
'Wuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuhhh!'
 \
+  >out || fail=1
 
-: ${DIFF=diff}
-${DIFF} greeting-test2.ok greeting-test2.out
-result=$?
+compare exp out || fail=1
 
-rm -fr $tmpfiles
-
-exit $result
+Exit $fail
diff --git a/tests/hello-1 b/tests/hello-1
index 46a4a0e..10190ed 100755
--- a/tests/hello-1
+++ b/tests/hello-1
@@ -8,30 +8,12 @@
 # notice and this notice are preserved.
 # This script takes one argument.
 
-trap 'rm -fr $tmpfiles' 1 2 3 15
+. "${srcdir=.}/tests/init.sh"; path_prepend_ .
 
-# We force the C locale here, since we are checking normal output,
-# which will be translated.
-
-LANGUAGE=
-LC_ALL=C
-LC_MESSAGES=
-LANG=
-export LANGUAGE LC_ALL LC_MESSAGES LANG
-
-tmpfiles="hello-test1.ok"
-cat <<EOF > hello-test1.ok
+cat <<EOF >exp || framework_failure_
 Hello, world!
 EOF
+hello >out || fail=1
+compare exp out || fail=1
 
-tmpfiles="$tmpfiles hello-test1.out"
-: ${HELLO=hello}
-${HELLO}  | tr -d '\r' >hello-test1.out
-
-: ${DIFF=diff}
-${DIFF} hello-test1.ok hello-test1.out
-result=$?
-
-rm -fr $tmpfiles
-
-exit $result
+Exit $fail
diff --git a/tests/last-1 b/tests/last-1
index e147c79..aa6769b 100755
--- a/tests/last-1
+++ b/tests/last-1
@@ -8,31 +8,12 @@
 # notice and this notice are preserved.
 # This script takes one argument.
 
-trap 'rm -fr $tmpfiles' 1 2 3 15
+. "${srcdir=.}/tests/init.sh"; path_prepend_ .
 
-# We force the C locale here, since we are checking normal output,
-# which will be translated.
-
-LANGUAGE=
-LC_ALL=C
-LC_MESSAGES=
-LANG=
-export LANGUAGE LC_ALL LC_MESSAGES LANG
-
-tmpfiles="last-test1.ok"
-cat <<EOF > last-test1.ok
+cat <<EOF >exp || framework_failure_
 my hello
 EOF
+hello -t -g 'my hello' >out || fail=1
+compare exp out || fail=1
 
-tmpfiles="$tmpfiles last-test1.out"
-: ${HELLO=hello}
-${HELLO} -t -g 'my hello' | tr -d '\r' \
-| tr -d '\r' >last-test1.out
-
-: ${DIFF=diff}
-${DIFF} last-test1.ok last-test1.out
-result=$?
-
-rm -fr $tmpfiles
-
-exit $result
+Exit $fail
diff --git a/tests/operand-1 b/tests/operand-1
index a48a680..09e32b8 100755
--- a/tests/operand-1
+++ b/tests/operand-1
@@ -7,26 +7,13 @@
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
 
-trap 'rm -fr $tmpfiles' 1 2 3 15
+. "${srcdir=.}/tests/init.sh"; path_prepend_ .
 
-tmpfiles="operand-test1.ok"
-cat <<EOF >operand-test1.ok
+cat <<EOF >exp || framework_failure_
 hello: extra operand: first
 Try 'hello --help' for more information.
 EOF
+returns_ 1 hello first second 2>err
+compare exp err || fail=1
 
-tmpfiles="$tmpfiles operand-test1.out"
-: ${HELLO=hello}
-${HELLO} first second 2>&1 | tr -d '\r' >operand-test1.out
-
-# remove \r (CR) characters from the output, so that the tests work on
-# platforms with CRLF line endings.  There is apparently no reliable
-# method (across Cygwin, MingW, etc.) to force an eol style.
-
-: ${DIFF=diff}
-${DIFF} operand-test1.ok operand-test1.out
-result=$?
-
-rm -fr $tmpfiles
-
-exit $result
+Exit $fail
diff --git a/tests/traditional-1 b/tests/traditional-1
index dc0509e..88db25e 100755
--- a/tests/traditional-1
+++ b/tests/traditional-1
@@ -7,30 +7,12 @@
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
 
-trap 'rm -fr $tmpfiles' 1 2 3 15
+. "${srcdir=.}/tests/init.sh"; path_prepend_ .
 
-# We force the C locale here, since we are checking normal output,
-# which will be translated.
-
-LANGUAGE=
-LC_ALL=C
-LC_MESSAGES=
-LANG=
-export LANGUAGE LC_ALL LC_MESSAGES LANG
-
-tmpfiles="traditional-test1.ok"
-cat <<EOF > traditional-test1.ok
+cat <<EOF >exp || framework_failure_
 hello, world
 EOF
+hello --traditional >out || fail=1
+compare exp out || fail=1
 
-tmpfiles="$tmpfiles traditional-test1.out"
-: ${HELLO=hello}
-${HELLO} --traditional | tr -d '\r' >traditional-test1.out
-
-: ${DIFF=diff}
-${DIFF} traditional-test1.ok traditional-test1.out
-result=$?
-
-rm -fr $tmpfiles
-
-exit $result
+Exit $fail
-- 
2.53.0


Reply via email to