Source-Changes-HG archive

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

[src/trunk]: src/tests/bin/sh/dotcmd Allow for testing other than /bin/sh usi...



details:   https://anonhg.NetBSD.org/src/rev/d22a735f1052
branches:  trunk
changeset: 814562:d22a735f1052
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 27 14:57:50 2016 +0000

description:
Allow for testing other than /bin/sh using TEST_SH (from kre@)

diffstat:

 tests/bin/sh/dotcmd/Makefile       |  10 +++++++---
 tests/bin/sh/dotcmd/scoped_command |  25 +++++++++++++++++++++++--
 tests/bin/sh/dotcmd/t_dotcmd.sh    |   6 +++++-
 3 files changed, 35 insertions(+), 6 deletions(-)

diffs (106 lines):

diff -r 6ee37de3903f -r d22a735f1052 tests/bin/sh/dotcmd/Makefile
--- a/tests/bin/sh/dotcmd/Makefile      Sun Mar 27 14:53:17 2016 +0000
+++ b/tests/bin/sh/dotcmd/Makefile      Sun Mar 27 14:57:50 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2014/07/27 14:24:17 apb Exp $
+# $NetBSD: Makefile,v 1.3 2016/03/27 14:57:50 christos Exp $
 #
 
 .include <bsd.own.mk>
@@ -7,6 +7,10 @@
 
 TESTS_SH = t_dotcmd
 
+.if !defined(TEST_SH)
+TEST_SH = ${HOST_SH}
+.endif
+
 FILESDIR = ${TESTSDIR}/out
 
 # Testing scripts: dotcmd in various scopes includes a file with
@@ -19,7 +23,7 @@
 FILESBUILD_${cmd}_${cmd_scope} = yes
 
 ${cmd}_${cmd_scope}: scoped_command
-       ${HOST_SH} ${.CURDIR}/scoped_command '${cmd_scope}' '${cmd}' '${cmd}' \
+       ${TEST_SH} ${.CURDIR}/scoped_command '${cmd_scope}' '${cmd}' '${cmd}' \
                >'${.TARGET}'
 
 .  for dot_scope in case compound file for func subshell until while
@@ -31,7 +35,7 @@
 FILESMODE_${dot_scope}_${cmd}_${cmd_scope} = ${BINMODE}
 
 ${dot_scope}_${cmd}_${cmd_scope}: scoped_command
-       ${HOST_SH} ${.CURDIR}/scoped_command '${dot_scope}' \
+       ${TEST_SH} ${.CURDIR}/scoped_command '${dot_scope}' \
                '. "${cmd}_${cmd_scope}"' 'dotcmd' 'dotcmd' >'${.TARGET}'
 .  endfor
 . endfor
diff -r 6ee37de3903f -r d22a735f1052 tests/bin/sh/dotcmd/scoped_command
--- a/tests/bin/sh/dotcmd/scoped_command        Sun Mar 27 14:53:17 2016 +0000
+++ b/tests/bin/sh/dotcmd/scoped_command        Sun Mar 27 14:57:50 2016 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: scoped_command,v 1.1 2014/05/31 14:29:06 christos Exp $
+# $NetBSD: scoped_command,v 1.2 2016/03/27 14:57:50 christos Exp $
 #
 # Copyright (c) 2014 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -30,6 +30,27 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
+: ${TEST_SH:=/bin/sh}
+
+sane_sh()
+{
+       set -- ${TEST_SH}
+       case "$#" in
+       (0)   set /bin/sh;;
+       (1|2) ;;
+       (*)   set "$1";;   # Just ignore options if we cannot make them work
+       esac
+
+       case "$1" in
+       /*)     TEST_SH="$1${2+ }$2";;
+       ./*)    TEST_SH="${PWD}${1#.}${2+ }$2";;
+       */*)    TEST_SH="${PWD}/$1${2+ }$2";;
+       *)      TEST_SH="$( command -v "$1" )${2+ }$2";;
+       esac
+}
+
+sane_sh
+
 set -e
 
 # USAGE:
@@ -52,7 +73,7 @@
 ${2}
 echo 'after ${3}, return value:' ${?}"
 
-echo "#!/bin/sh"
+echo "#!${TEST_SH}"
 
 [ 'func' = "${1}" ] && cat <<EOF
 func()
diff -r 6ee37de3903f -r d22a735f1052 tests/bin/sh/dotcmd/t_dotcmd.sh
--- a/tests/bin/sh/dotcmd/t_dotcmd.sh   Sun Mar 27 14:53:17 2016 +0000
+++ b/tests/bin/sh/dotcmd/t_dotcmd.sh   Sun Mar 27 14:57:50 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_dotcmd.sh,v 1.1 2014/05/31 14:29:06 christos Exp $
+# $NetBSD: t_dotcmd.sh,v 1.2 2016/03/27 14:57:50 christos Exp $
 #
 # Copyright (c) 2014 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -33,6 +33,10 @@
 # in C/C++ so, for example, if the dotcmd is in a loop's body, a break in
 # the sourced file can be used to break out of that loop.
 
+# Note that the standard does not require this, and allows lexically
+# scoped interpretation of break/continue (and permits dynamic scope
+# as an optional extension.)
+
 cmds='return break continue'
 scopes='case compound file for func subshell until while'
 



Home | Main Index | Thread Index | Old Index