* tests: Accommodate a shell that is not in /bin/sh
@ 2019-01-27 15:07 Bruno Haible
2019-01-27 15:57 ` test-framework-sh: Improve maintainability Bruno Haible
0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2019-01-27 15:07 UTC (permalink / raw)
To: bug-gnulib
On Android 4.3, I'm seeing these test failures:
FAIL: test-set-mode-acl-1.sh
============================
../../gltests/test-set-mode-acl-1.sh[13]: ../../gltests/test-set-mode-acl.sh: No such file or directory
FAIL test-set-mode-acl-1.sh (exit status: 1)
FAIL: test-set-mode-acl-2.sh
============================
../../gltests/test-set-mode-acl-2.sh[9]: ../../gltests/test-set-mode-acl.sh: No such file or directory
FAIL test-set-mode-acl-2.sh (exit status: 1)
FAIL: test-copy-acl-1.sh
========================
../../gltests/test-copy-acl-1.sh[13]: ../../gltests/test-copy-acl.sh: No such file or directory
FAIL test-copy-acl-1.sh (exit status: 1)
FAIL: test-copy-acl-2.sh
========================
../../gltests/test-copy-acl-2.sh[9]: ../../gltests/test-copy-acl.sh: No such file or directory
FAIL test-copy-acl-2.sh (exit status: 1)
FAIL: test-copy-file-1.sh
=========================
../../gltests/test-copy-file-1.sh[13]: ../../gltests/test-copy-file.sh: No such file or directory
../../gltests/test-copy-file-1.sh[15]: ../../gltests/test-copy-file.sh: No such file or directory
FAIL test-copy-file-1.sh (exit status: 1)
FAIL: test-copy-file-2.sh
=========================
../../gltests/test-copy-file-2.sh[9]: ../../gltests/test-copy-file.sh: No such file or directory
../../gltests/test-copy-file-2.sh[11]: ../../gltests/test-copy-file.sh: No such file or directory
FAIL test-copy-file-2.sh (exit status: 1)
FAIL: test-file-has-acl-1.sh
============================
../../gltests/test-file-has-acl-1.sh[13]: ../../gltests/test-file-has-acl.sh: No such file or directory
FAIL test-file-has-acl-1.sh (exit status: 1)
FAIL: test-file-has-acl-2.sh
============================
../../gltests/test-file-has-acl-2.sh[9]: ../../gltests/test-file-has-acl.sh: No such file or directory
FAIL test-file-has-acl-2.sh (exit status: 1)
FAIL: test-vc-list-files-git.sh
===============================
../../gltests/test-vc-list-files-git.sh[40]: vc-list-files: No such file or directory
FAIL test-vc-list-files-git.sh (exit status: 1)
The cause is the use of the hardcode file name /bin/sh as interpreter for
shell scripts. On Android, it is in /system/bin/sh, and you can assume it
is found in $PATH.
This patch fixes it, by defining a variable BOURNE_SHELL in init.sh, and
using the test framework in all places that need it.
It is similar to m4/sh-filename.m4, except that this variable BOURNE_SHELL
can be set to /bin/sh in 64-bit Cygwin environments (because the shell in
Cygwin can access /bin/sh, only 32-bit executables cannot).
2019-01-27 Bruno Haible <bruno@clisp.org>
tests: Accommodate a shell that is not in /bin/sh.
* tests/init.sh (setup_): Set srcdir and builddir.
(BOURNE_SHELL): New variable.
* modules/acl-tests (Depends-on): Add 'test-framework-sh'.
* modules/file-has-acl-tests (Depends-on): Likewise.
* modules/copy-file-tests (Depends-on): Likewise.
* tests/test-set-mode-acl-1.sh: Use the test framework. Invoke shell
scripts through $BOURNE_SHELL.
* tests/test-set-mode-acl-2.sh: Likewise.
* tests/test-copy-acl-1.sh: Likewise.
* tests/test-copy-acl-2.sh: Likewise.
* tests/test-file-has-acl-1.sh: Likewise.
* tests/test-file-has-acl-2.sh: Likewise.
* tests/test-copy-file-1.sh: Likewise.
* tests/test-copy-file-2.sh: Likewise.
* tests/test-set-mode-acl.sh (builddir): Consider value set by the
invoker.
* tests/test-copy-acl.sh (builddir): Likewise.
* tests/test-file-has-acl.sh (builddir): Likewise.
* tests/test-copy-file.sh (builddir): Likewise.
* tests/test-vc-list-files-cvs.sh: Don't create shims for executables in
build-aux/. Instead, invoke shell scripts through $BOURNE_SHELL.
* tests/test-vc-list-files-git.sh: Likewise.
diff --git a/modules/acl-tests b/modules/acl-tests
index 3438f14..76e2a36 100644
--- a/modules/acl-tests
+++ b/modules/acl-tests
@@ -15,6 +15,7 @@ file-has-acl-tests
read-file
unistd
xalloc
+test-framework-sh
configure.ac:
diff --git a/modules/copy-file-tests b/modules/copy-file-tests
index 299d49f..6b468af 100644
--- a/modules/copy-file-tests
+++ b/modules/copy-file-tests
@@ -10,6 +10,7 @@ acl
acl-tests
read-file
xalloc
+test-framework-sh
configure.ac:
diff --git a/modules/file-has-acl-tests b/modules/file-has-acl-tests
index 5a26020..ff069ec 100644
--- a/modules/file-has-acl-tests
+++ b/modules/file-has-acl-tests
@@ -7,6 +7,7 @@ tests/macros.h
Depends-on:
unistd
+test-framework-sh
configure.ac:
AC_CHECK_DECLS_ONCE([alarm])
diff --git a/tests/init.sh b/tests/init.sh
index 0d6ddee..9498d83 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -475,10 +475,18 @@ setup_ ()
initial_cwd_=$PWD
+ # Create and enter the temporary directory.
pfx_=`testdir_prefix_`
test_dir_=`mktempd_ "$initial_cwd_" "$pfx_-$ME_.XXXX"` \
|| fail_ "failed to create temporary directory in $initial_cwd_"
cd "$test_dir_" || fail_ "failed to cd to temporary directory"
+ # Set variables srcdir, builddir, for the convenience of the test.
+ case $srcdir in
+ /* | ?:*) ;;
+ *) srcdir="../$srcdir" ;;
+ esac
+ builddir=".."
+ export srcdir builddir
# As autoconf-generated configure scripts do, ensure that IFS
# is defined initially, so that saving and restoring $IFS works.
@@ -607,6 +615,15 @@ mktempd_ ()
fail_ "$err_"
}
+# The interpreter for Bourne-shell scripts.
+# No special standards compatibility requirements.
+# Some environments, such as Android, don't have /bin/sh.
+if test -f /bin/sh$EXEEXT; then
+ BOURNE_SHELL=/bin/sh
+else
+ BOURNE_SHELL=sh
+fi
+
# If you want to override the testdir_prefix_ function,
# or to add more utility functions, use this file.
test -f "$srcdir/init.cfg" \
diff --git a/tests/test-copy-acl-1.sh b/tests/test-copy-acl-1.sh
index 2f9880e..bb60091 100755
--- a/tests/test-copy-acl-1.sh
+++ b/tests/test-copy-acl-1.sh
@@ -3,6 +3,8 @@
# Test copy-acl on the file system of /var/tmp, which usually is a local
# file system.
+. "${srcdir=.}/init.sh"; path_prepend_ .
+
if test -d /var/tmp; then
TMPDIR=/var/tmp
else
@@ -10,4 +12,6 @@ else
fi
export TMPDIR
-exec "${srcdir}/test-copy-acl.sh"
+$BOURNE_SHELL "${srcdir}/test-copy-acl.sh"
+
+Exit $?
diff --git a/tests/test-copy-acl-2.sh b/tests/test-copy-acl-2.sh
index 984602d..a35c12e 100755
--- a/tests/test-copy-acl-2.sh
+++ b/tests/test-copy-acl-2.sh
@@ -3,7 +3,11 @@
# Test copy-acl on the file system of the build directory, which may be
# a local file system or NFS mounted.
+. "${srcdir=.}/init.sh"; path_prepend_ .
+
TMPDIR=`pwd`
export TMPDIR
-exec "${srcdir}/test-copy-acl.sh"
+$BOURNE_SHELL "${srcdir}/test-copy-acl.sh"
+
+Exit $?
diff --git a/tests/test-copy-acl.sh b/tests/test-copy-acl.sh
index 147bf56..a0a105d 100755
--- a/tests/test-copy-acl.sh
+++ b/tests/test-copy-acl.sh
@@ -41,7 +41,12 @@ func_tmpdir ()
}
func_tmpdir
-builddir=`pwd`
+# builddir may already be set by the script that invokes this one.
+case "$builddir" in
+ '') builddir=`pwd` ;;
+ /* | ?:*) ;;
+ *) builddir=`pwd`/$builddir ;;
+esac
cd "$builddir" ||
{
echo "$0: cannot determine build directory (unreadable parent dir?)" >&2
diff --git a/tests/test-copy-file-1.sh b/tests/test-copy-file-1.sh
index 8998ba5..c18f5e9 100755
--- a/tests/test-copy-file-1.sh
+++ b/tests/test-copy-file-1.sh
@@ -3,6 +3,8 @@
# Test copy-file on the file system of /var/tmp, which usually is a local
# file system.
+. "${srcdir=.}/init.sh"; path_prepend_ .
+
if test -d /var/tmp; then
TMPDIR=/var/tmp
else
@@ -10,11 +12,11 @@ else
fi
export TMPDIR
-"${srcdir}/test-copy-file.sh"
+$BOURNE_SHELL "${srcdir}/test-copy-file.sh"
ret1=$?
-NO_STDERR_OUTPUT=1 "${srcdir}/test-copy-file.sh"
+NO_STDERR_OUTPUT=1 $BOURNE_SHELL "${srcdir}/test-copy-file.sh"
ret2=$?
case $ret1 in
- 77 ) exit $ret2 ;;
- * ) exit $ret1 ;;
+ 77 ) Exit $ret2 ;;
+ * ) Exit $ret1 ;;
esac
diff --git a/tests/test-copy-file-2.sh b/tests/test-copy-file-2.sh
index 1756f7e..d3b7f0e 100755
--- a/tests/test-copy-file-2.sh
+++ b/tests/test-copy-file-2.sh
@@ -3,14 +3,16 @@
# Test copy-file on the file system of the build directory, which may be
# a local file system or NFS mounted.
+. "${srcdir=.}/init.sh"; path_prepend_ .
+
TMPDIR=`pwd`
export TMPDIR
-"${srcdir}/test-copy-file.sh"
+$BOURNE_SHELL "${srcdir}/test-copy-file.sh"
ret1=$?
-NO_STDERR_OUTPUT=1 "${srcdir}/test-copy-file.sh"
+NO_STDERR_OUTPUT=1 $BOURNE_SHELL "${srcdir}/test-copy-file.sh"
ret2=$?
case $ret1 in
- 77 ) exit $ret2 ;;
- * ) exit $ret1 ;;
+ 77 ) Exit $ret2 ;;
+ * ) Exit $ret1 ;;
esac
diff --git a/tests/test-copy-file.sh b/tests/test-copy-file.sh
index 98da280..cd2868d 100755
--- a/tests/test-copy-file.sh
+++ b/tests/test-copy-file.sh
@@ -35,7 +35,12 @@ func_tmpdir ()
}
func_tmpdir
-builddir=`pwd`
+# builddir may already be set by the script that invokes this one.
+case "$builddir" in
+ '') builddir=`pwd` ;;
+ /* | ?:*) ;;
+ *) builddir=`pwd`/$builddir ;;
+esac
cd "$builddir" ||
{
echo "$0: cannot determine build directory (unreadable parent dir?)" >&2
diff --git a/tests/test-file-has-acl-1.sh b/tests/test-file-has-acl-1.sh
index e3ad9c0..ab13a88 100755
--- a/tests/test-file-has-acl-1.sh
+++ b/tests/test-file-has-acl-1.sh
@@ -3,6 +3,8 @@
# Test file-has-acl on the file system of /var/tmp, which usually is a local
# file system.
+. "${srcdir=.}/init.sh"; path_prepend_ .
+
if test -d /var/tmp; then
TMPDIR=/var/tmp
else
@@ -10,4 +12,6 @@ else
fi
export TMPDIR
-exec "${srcdir}/test-file-has-acl.sh"
+$BOURNE_SHELL "${srcdir}/test-file-has-acl.sh"
+
+Exit $?
diff --git a/tests/test-file-has-acl-2.sh b/tests/test-file-has-acl-2.sh
index 6b92b1d..41561d6 100755
--- a/tests/test-file-has-acl-2.sh
+++ b/tests/test-file-has-acl-2.sh
@@ -3,7 +3,11 @@
# Test file-has-acl on the file system of the build directory, which may be
# a local file system or NFS mounted.
+. "${srcdir=.}/init.sh"; path_prepend_ .
+
TMPDIR=`pwd`
export TMPDIR
-exec "${srcdir}/test-file-has-acl.sh"
+$BOURNE_SHELL "${srcdir}/test-file-has-acl.sh"
+
+Exit $?
diff --git a/tests/test-file-has-acl.sh b/tests/test-file-has-acl.sh
index 26610c1..a2fa9c3 100755
--- a/tests/test-file-has-acl.sh
+++ b/tests/test-file-has-acl.sh
@@ -41,7 +41,12 @@ func_tmpdir ()
}
func_tmpdir
-builddir=`pwd`
+# builddir may already be set by the script that invokes this one.
+case "$builddir" in
+ '') builddir=`pwd` ;;
+ /* | ?:*) ;;
+ *) builddir=`pwd`/$builddir ;;
+esac
cd "$builddir" ||
{
echo "$0: cannot determine build directory (unreadable parent dir?)" >&2
diff --git a/tests/test-set-mode-acl-1.sh b/tests/test-set-mode-acl-1.sh
index 68c247c..7b16b37 100755
--- a/tests/test-set-mode-acl-1.sh
+++ b/tests/test-set-mode-acl-1.sh
@@ -3,6 +3,8 @@
# Test set-mode-acl on the file system of /var/tmp, which usually is a local
# file system.
+. "${srcdir=.}/init.sh"; path_prepend_ .
+
if test -d /var/tmp; then
TMPDIR=/var/tmp
else
@@ -10,4 +12,6 @@ else
fi
export TMPDIR
-exec "${srcdir}/test-set-mode-acl.sh"
+$BOURNE_SHELL "${srcdir}/test-set-mode-acl.sh"
+
+Exit $?
diff --git a/tests/test-set-mode-acl-2.sh b/tests/test-set-mode-acl-2.sh
index d1377df..2f7c8c0 100755
--- a/tests/test-set-mode-acl-2.sh
+++ b/tests/test-set-mode-acl-2.sh
@@ -3,7 +3,11 @@
# Test set-mode-acl on the file system of the build directory, which may be
# a local file system or NFS mounted.
+. "${srcdir=.}/init.sh"; path_prepend_ .
+
TMPDIR=`pwd`
export TMPDIR
-exec "${srcdir}/test-set-mode-acl.sh"
+$BOURNE_SHELL "${srcdir}/test-set-mode-acl.sh"
+
+Exit $?
diff --git a/tests/test-set-mode-acl.sh b/tests/test-set-mode-acl.sh
index f0b1641..b2f12cf 100755
--- a/tests/test-set-mode-acl.sh
+++ b/tests/test-set-mode-acl.sh
@@ -41,7 +41,12 @@ func_tmpdir ()
}
func_tmpdir
-builddir=`pwd`
+# builddir may already be set by the script that invokes this one.
+case "$builddir" in
+ '') builddir=`pwd` ;;
+ /* | ?:*) ;;
+ *) builddir=`pwd`/$builddir ;;
+esac
cd "$builddir" ||
{
echo "$0: cannot determine build directory (unreadable parent dir?)" >&2
diff --git a/tests/test-vc-list-files-cvs.sh b/tests/test-vc-list-files-cvs.sh
index b4c389c..9b2efef 100755
--- a/tests/test-vc-list-files-cvs.sh
+++ b/tests/test-vc-list-files-cvs.sh
@@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. */
: ${srcdir=.}
-. "$srcdir/init.sh"; path_prepend_ "$abs_aux_dir" .
+. "$srcdir/init.sh"; path_prepend_ .
tmpdir=vc-cvs
repo=`pwd`/$tmpdir/repo
@@ -44,7 +44,7 @@ for i in with-cvsu without; do
cvs -Q -d "$repo" import -m imp m M M0 &&
cvs -Q -d "$repo" co m && cd m &&
printf '%s\n' b c d/a > expected &&
- vc-list-files | sort > actual &&
+ $BOURNE_SHELL "$abs_aux_dir/vc-list-files" | sort > actual &&
compare expected actual &&
ok=1
test $ok = 0 && fail=1
diff --git a/tests/test-vc-list-files-git.sh b/tests/test-vc-list-files-git.sh
index b471050..15db4d0 100755
--- a/tests/test-vc-list-files-git.sh
+++ b/tests/test-vc-list-files-git.sh
@@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. */
: ${srcdir=.}
-. "$srcdir/init.sh"; path_prepend_ "$abs_aux_dir" .
+. "$srcdir/init.sh"; path_prepend_ .
tmpdir=vc-git-$$
GIT_DIR= GIT_WORK_TREE=; unset GIT_DIR GIT_WORK_TREE
@@ -35,7 +35,7 @@ mkdir $tmpdir && cd $tmpdir &&
git add . > /dev/null &&
git commit -q -a -m log &&
printf '%s\n' b c d/a > expected &&
- vc-list-files > actual &&
+ $BOURNE_SHELL "$abs_aux_dir/vc-list-files" > actual &&
compare expected actual &&
fail=0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: test-framework-sh: Improve maintainability
2019-01-27 15:07 tests: Accommodate a shell that is not in /bin/sh Bruno Haible
@ 2019-01-27 15:57 ` Bruno Haible
0 siblings, 0 replies; 2+ messages in thread
From: Bruno Haible @ 2019-01-27 15:57 UTC (permalink / raw)
To: bug-gnulib
While doing this change, I noticed that init.sh is a bit hard to grok,
because essentials of the test framework are mixed with mere convenience
functions (like 'compare'). So I took the opportunity to reorganize this
file.
2019-01-27 Bruno Haible <bruno@clisp.org>
test-framework-sh: Improve maintainability.
* tests/init.sh: Clarify what belongs together. Reorder definitions.
https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=07ff53ad5cf8419027a75874f0e0a9389fd0fdd6;ds=sidebyside
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-01-27 15:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-27 15:07 tests: Accommodate a shell that is not in /bin/sh Bruno Haible
2019-01-27 15:57 ` test-framework-sh: Improve maintainability Bruno Haible
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).