CVS commit: src/tests/bin/sh

2021-05-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed May 19 22:43:18 UTC 2021

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
Handle the (very) recent change to printf(1) - when writing to a closed
stdout printf(1) now issues an error message, hence stderr in such cases
should not be empty, rather than should be empty.   Adapt to that.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.10 src/tests/bin/sh/t_redir.sh:1.11
--- src/tests/bin/sh/t_redir.sh:1.10	Tue Nov 27 09:55:32 2018
+++ src/tests/bin/sh/t_redir.sh	Wed May 19 22:43:18 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.10 2018/11/27 09:55:32 kre Exp $
+# $NetBSD: t_redir.sh,v 1.11 2021/05/19 22:43:18 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -866,11 +866,11 @@ validate_fn_redirects_body()
 		${TEST_SH} -c ". ./f-def; f ; printf '%s\n' success1"
 	atf_check -s exit:0 -o inline:'success2\n' -e empty \
 		${TEST_SH} -c ". ./f-def; f >/dev/null; printf '%s\n' success2"
-	atf_check -s exit:0 -o inline:'success3\n' -e empty \
+	atf_check -s exit:0 -o inline:'success3\n' -e not-empty \
 		${TEST_SH} -c ". ./f-def; f >&- ; printf '%s\n' success3"
 	atf_check -s exit:0 -o inline:'In-Func\nsuccess4\n' -e empty \
 		${TEST_SH} -c ". ./f-def; f & wait; printf '%s\n' success4"
-	atf_check -s exit:0 -o inline:'success5\n' -e empty \
+	atf_check -s exit:0 -o inline:'success5\n' -e not-empty \
 		${TEST_SH} -c ". ./f-def; f >&- & wait; printf '%s\n' success5"
 	atf_check -s exit:0 -o inline:'In-Func\nIn-Func\nsuccess6\n' -e empty \
 		${TEST_SH} -c ". ./f-def; f;f; printf '%s\n' success6"



CVS commit: src/tests/bin/sh

2021-05-18 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue May 18 21:37:56 UTC 2021

Modified Files:
src/tests/bin/sh: t_builtins.sh

Log Message:
Add two new sub-tests to the echo test case of the t_builtins shell ATF test.

The first verifies that echo exits >0 when it encounters an I/O error on
its output (this part would have succeeded for a long time).  It also
verifies the POSIX requirement that when most standard utilities (or
perhaps many rather than most) exit(>0) they must write a message to stderr.
Our sh's built in echo did not do that (nor does /bin/echo but that's not
relevant here).

The second demonstrates (on an unfixed built-in echo) a bug reported in
private e-mail by Oguz  where once an instance of
the built-in echo has detected an I/O error, all later invocations of
the built-in echo, with no I/O errors of their own, also exit(1) (the error
status on stdout is not cleared, each echo sees the "I/O error occurred" and
does exit(1)).

In this second sub-test, the "2>&-" on the first echo command is simply
an artifact caused by the test harness - the "check" function verifies
that exit((>0) requires a message on stderr (and vice versa), but that
only applies to most (or many) utilities, echo is one, but sh is not.
In the second test, the exit status comes from sh - sh is permitted to
write to stderr (via the echo command it runs in this case) and still
exit(0).   But the check function in the test does not understand that
subtlety.   So, we simply suppress the stderr message by closing stderr
(the first of these two new sub-tests has verified that the message exists)..


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_builtins.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_builtins.sh
diff -u src/tests/bin/sh/t_builtins.sh:1.5 src/tests/bin/sh/t_builtins.sh:1.6
--- src/tests/bin/sh/t_builtins.sh:1.5	Wed Jan  9 10:51:23 2019
+++ src/tests/bin/sh/t_builtins.sh	Tue May 18 21:37:56 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_builtins.sh,v 1.5 2019/01/09 10:51:23 kre Exp $
+# $NetBSD: t_builtins.sh,v 1.6 2021/05/18 21:37:56 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -291,6 +291,9 @@ echo_body() {
 		done
 	done
 
+	check 'echo foo >&-' "" 1
+	check 'echo foo >&- 2>&-; echo $?; echo $?' "1${nl}0${nl}" 0
+
 	results
 }
 



CVS commit: src/tests/bin/sh

2019-01-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Jan 22 14:31:53 UTC 2019

Modified Files:
src/tests/bin/sh: t_here.sh

Log Message:
Add sub tests to the quoting test case, to demonstrate a parsing
bug (and its fix (depending upon whether the test is run against
an unfixed, or fixed, shell).

An obvious indication of the failure is the following (one of the
new sub-tests)

p=A
cat &2 "[$TEST_NUM] Expected output '$2', received '$result'"
@@ -473,6 +476,42 @@ quoting_body() {
 	EOF
 	'	'5string1 line1?-line2string1 -line2 ""'\'\'' string1 6' 0
 
+	# check that \ only quotes the magic chars, otherwise is retained
+	check 'p=A; cat <<-EOF
+		${p+\%$p\%}
+		${p+%$p%}
+	EOF
+	'	'\%A\% %A%' 0
+
+	# and check that " is not magic, so \ does not quote it
+	check 'p=A; cat <<-EOF
+		${p+\"$p\"}
+		${p+"$p"}
+	EOF
+	'	'\"A\" "A"' 0
+
+	# except in a ${var%} word, base syntax reapplies, and
+	# there quotes are magic again
+	check 'p=ABCD; cat <<-EOF
+		${p%B?D}
+		${p%B\?D}
+		${p%"BCD"}
+		"${p%??}"
+		${p#"${p%??}"}
+		"${p#"${p%?"?"}"}"
+	EOF
+	'	'A ABCD A "AB" CD ""'	0
+
+	check 'p=AB??; cat <<-EOF
+		${p%B?D}
+		${p%B\??}
+		${p%"B??"}
+		"${p%??}"
+		${p#"${p%??}"}
+		"${p#"${p%?"?"}"}"
+	EOF
+	'	'AB?? A A "AB" ?? "??"'	0
+
 	results
 }
 



CVS commit: src/tests/bin/sh

2019-01-09 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jan  9 10:51:24 UTC 2019

Modified Files:
src/tests/bin/sh: t_builtins.sh

Log Message:
Add several sub-tests to the test for the "eval" builtin,
including testing correct handling of error cases.
One of these new tests located a bug which will be fixed
within minutes of this commit ...

While doing this, move the test that was used only in the
echo builtin test case (testing if the NetBSD shell was being
tested) into a utility function, and also call it in the eval
test, so NetBSD specific behaviour of what is unspecified in
the standard can be checked to ensure it is not accidentally
altered.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_builtins.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_builtins.sh
diff -u src/tests/bin/sh/t_builtins.sh:1.4 src/tests/bin/sh/t_builtins.sh:1.5
--- src/tests/bin/sh/t_builtins.sh:1.4	Wed Dec 12 11:52:05 2018
+++ src/tests/bin/sh/t_builtins.sh	Wed Jan  9 10:51:23 2019
@@ -1,4 +1,4 @@
-# $NetBSD: t_builtins.sh,v 1.4 2018/12/12 11:52:05 kre Exp $
+# $NetBSD: t_builtins.sh,v 1.5 2019/01/09 10:51:23 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -73,6 +73,21 @@ have_builtin()
 	return 0
 }
 
+# And another to test if the shell being tested is the NetBSD shell,
+# as we use these tests both to test standards conformance (correctness)
+# which should be possible for all shells, and to test NetBSD
+# extensions (which we mostly do by testing if the extension exists)
+# and NetBSD sh behaviour for what is unspecified by the standard
+# (so we will be notified via test failure should that unspecified
+# behaviour alter) for which we have to discover if that shell is the
+# one being tested.
+
+is_netbsd_sh()
+{
+	unset NETBSD_SHELL 2>/dev/null
+	test -n "$( ${TEST_SH} -c 'printf %s "${NETBSD_SHELL}"')"
+}
+
 ### Helper functions
 
 nl='
@@ -222,8 +237,7 @@ echo_head() {
 echo_body() {
 	have_builtin echo || return 0
 
-	unset NETBSD_SHELL 2>/dev/null
-	if test -z "$( ${TEST_SH} -c 'printf %s "${NETBSD_SHELL}"')"; then
+	if ! is_netbsd_sh; then
 		atf_skip \
 	   "${TEST_SH%% *} is not the NetBSD shell, this test is for it alone"
 		return 0
@@ -290,6 +304,12 @@ eval_body() {
 	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'eval "exit 0"'
 	atf_check -s exit:1 -e empty -o empty ${TEST_SH} -c 'eval "exit 1"'
 	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c 'eval exit 0'
+	atf_check -s exit:1 -e empty -o empty ${TEST_SH} -c 'eval exit 1'
+
+	atf_check -s exit:0 -e empty -o inline:0 ${TEST_SH} -c \
+		'eval true; printf %d $?'
+	atf_check -s exit:0 -e empty -o inline:1 ${TEST_SH} -c \
+		'eval false; printf %d $?'
 
 	atf_check -s exit:0 -e empty -o inline:abc ${TEST_SH} -c \
 		'X=a Y=b Z=c; for V in X Y Z; do eval "printf %s \$$V"; done'
@@ -297,6 +317,54 @@ eval_body() {
 		'X=a Y=b Z=c; for V in X Y Z; do eval printf %s \$$V; done'
 	atf_check -s exit:0 -e empty -o inline:XYZ ${TEST_SH} -c \
 		'for V in X Y Z; do eval "${V}=${V}"; done; printf %s "$X$Y$Z"'
+
+	# make sure eval'd strings affect the shell environment
+
+	atf_check -s exit:0 -e empty -o inline:/b/ ${TEST_SH} -c \
+		'X=a; eval "X=b"; printf /%s/ "${X-unset}"'
+	atf_check -s exit:0 -e empty -o inline:/b/ ${TEST_SH} -c \
+		'X=a; Y=X; Z=b; eval "$Y=$Z"; printf /%s/ "${X-unset}"'
+	atf_check -s exit:0 -e empty -o inline:/unset/ ${TEST_SH} -c \
+		'X=a; eval "unset X"; printf /%s/ "${X-unset}"'
+	atf_check -s exit:0 -e empty -o inline:// ${TEST_SH} -c \
+		'unset X; eval "X="; printf /%s/ "${X-unset}"'
+	atf_check -s exit:0 -e empty -o inline:'2 y Z ' ${TEST_SH} -c \
+		'set -- X y Z; eval shift; printf "%s " "$#" "$@"'
+
+	# ensure an error in an eval'd string causes the shell to exit
+	# unless 'eval' is preceded by 'command' (in which case the
+	# string is not eval'd but execution continues)
+
+	atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
+		'eval "if done"; printf %s status=$?'
+
+	atf_check -s exit:0 -e not-empty -o 'match:status=[1-9]' \
+	${TEST_SH} -c \
+		'command eval "if done"; printf %s status=$?'
+
+	atf_check -s not-exit:0 -e not-empty \
+	-o 'match:status=[1-9]' -o 'not-match:[XY]' ${TEST_SH} -c \
+		 'command eval "printf X; if done; printf Y"
+		  S=$?; printf %s status=$S; exit $S'
+
+	# whether 'X' is output here is (or should be) unspecified.
+	atf_check -s not-exit:0 -e not-empty \
+	-o 'match:status=[1-9]' -o 'not-match:Y' ${TEST_SH} -c \
+		 'command eval "printf X
+		 		if done
+printf Y"
+		  S=$?; printf %s status=$S; exit $S'
+
+	if is_netbsd_sh
+	then
+		# but on NetBSD we expect that X to appear...
+		atf_check -s not-exit:0 -e not-empty  -o 'match:X' \
+		-o 'match:status=[1-9]' -o 'not-match:Y' ${TEST_SH} -c \
+			 'command eval "printf X
+	if done
+	printf Y"
+			  S=$?; 

CVS commit: src/tests/bin/sh

2018-12-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Dec 12 11:52:05 UTC 2018

Modified Files:
src/tests/bin/sh: t_builtins.sh

Log Message:
Add a new test case for NetBSD specific readonly tests.
Add more sub-tests to the export_nbsd test case.
In both cases the new -q and -p VAR options are tested.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_builtins.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_builtins.sh
diff -u src/tests/bin/sh/t_builtins.sh:1.3 src/tests/bin/sh/t_builtins.sh:1.4
--- src/tests/bin/sh/t_builtins.sh:1.3	Wed Dec 12 08:10:39 2018
+++ src/tests/bin/sh/t_builtins.sh	Wed Dec 12 11:52:05 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_builtins.sh,v 1.3 2018/12/12 08:10:39 kre Exp $
+# $NetBSD: t_builtins.sh,v 1.4 2018/12/12 11:52:05 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -416,6 +416,45 @@ export_nbsd_body() {
 
 	atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
 		'export VAR=exported; export -x VAR; export VAR=FOO'
+
+	have_builtin export '' 'export VAR;' '-q VAR' ' -q'  || return 0
+
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'unset VAR; VAR=set; export -q VAR'
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'export VAR=set; export -q VAR'
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'VAR=set; RW=set; export -q VAR RW'
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'VAR=set; export RO=set; export -q VAR RO'
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'export VAR=set RO=set; export -q VAR RO'
+
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'unset VAR; export -q VAR'
+	# next one is the same as the have_builtin test, so "cannot" fail...
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'unset VAR; export VAR; export -q VAR'
+
+	# if we have -q we should also have -p var...
+	# What's more, we are testing NetBSD sh, so we know output format.
+
+	atf_check -s exit:0 -e empty -o match:VAR=foobar \
+		${TEST_SH} -c \
+			'VAR=foobar ; export VAR ; export -p VAR'
+	atf_check -s exit:0 -e empty -o inline:1 \
+		${TEST_SH} -c \
+			'VAR=foobar ; export VAR ;
+			printf %d $(export -p VAR | wc -l)'
+	atf_check -s exit:0 -e empty \
+		-o inline:'export VAR=foobar\nexport OTHER\n' \
+		${TEST_SH} -c \
+			'VAR=foobar; export VAR OTHER; export -p VAR OTHER'
+	atf_check -s exit:0 -e empty \
+		-o inline:'export A=aaa\nexport B\nexport D='"''"'\n' \
+		${TEST_SH} -c \
+			'A=aaa D= C=foo; unset B; export A B D;
+			 export -p A B C D'
 }
 
 atf_test_case getopts
@@ -516,6 +555,51 @@ readonly_body() {
 		'unset VAR; readonly VAR=set; unset VAR; printf %s ${VAR-unset}'
 }
 
+atf_test_case readonly_nbsd
+readonly_nbsd_head() {
+	atf_set "descr" "Tests NetBSD extensions to 'readonly'"
+}
+readonly_nbsd_body() {
+	have_builtin readonly '' 'readonly VAR;' '-q VAR' ' -q'  || return 0
+
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'VAR=set; readonly -q VAR'
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'readonly VAR=set; readonly -q VAR'
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'VAR=set; RW=set; readonly -q VAR RW'
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'VAR=set; readonly RO=set; readonly -q VAR RO'
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'readonly VAR=set RO=set; readonly -q VAR RO'
+
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'unset VAR; readonly -q VAR'
+	# next one is the same as the have_builtin test, so "cannot" fail...
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'unset VAR; readonly VAR; readonly -q VAR'
+
+	# if we have -q we should also have -p var...
+	# What's more, we are testing NetBSD sh, so we know output format.
+
+	atf_check -s exit:0 -e empty -o match:VAR=foobar \
+		${TEST_SH} -c \
+			'VAR=foobar ; readonly VAR ; readonly -p VAR'
+	atf_check -s exit:0 -e empty -o inline:1 \
+		${TEST_SH} -c \
+			'VAR=foobar ; readonly VAR ;
+			printf %d $(readonly -p VAR | wc -l)'
+	atf_check -s exit:0 -e empty \
+		-o inline:'readonly VAR=foobar\nreadonly OTHER\n' \
+		${TEST_SH} -c \
+			'VAR=foobar; readonly VAR OTHER; readonly -p VAR OTHER'
+	atf_check -s exit:0 -e empty \
+		-o inline:'readonly A=aaa\nreadonly B\nreadonly D='"''"'\n' \
+		${TEST_SH} -c \
+			'A=aaa D= C=foo; unset B; readonly A B D;
+			 readonly -p A B C D'
+}
+
 atf_test_case cd_pwd
 cd_pwd_head() {
 	atf_set "descr" "Tests the shell builtins 'cd' & 'pwd'"
@@ -830,6 +914,7 @@ atf_init_test_cases() {
 	atf_add_test_case jobid
 	atf_add_test_case let
 	atf_add_test_case local
+	atf_add_test_case readonly_nbsd
 	atf_add_test_case setvar
 	# inputrc should probably be tested in libedit tests (somehow)
 



CVS commit: src/tests/bin/sh

2018-12-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Dec 12 08:10:39 UTC 2018

Modified Files:
src/tests/bin/sh: t_builtins.sh

Log Message:
Add more subtests to the export and readonly built-in commands test cases.

In particular, add a readonly test to detect the bug that was just fixed...
(but there is more than that one added here).

Also, allow zsh to run more of these tests than it did, what is a builtin
command most places (including in POSIX) can be a reserved word in zsh!


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_builtins.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_builtins.sh
diff -u src/tests/bin/sh/t_builtins.sh:1.2 src/tests/bin/sh/t_builtins.sh:1.3
--- src/tests/bin/sh/t_builtins.sh:1.2	Wed Dec  5 02:48:04 2018
+++ src/tests/bin/sh/t_builtins.sh	Wed Dec 12 08:10:39 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_builtins.sh,v 1.2 2018/12/05 02:48:04 kre Exp $
+# $NetBSD: t_builtins.sh,v 1.3 2018/12/12 08:10:39 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -62,6 +62,7 @@ have_builtin()
 	LC_ALL=C ${TEST_SH} -c \
 	'case "$( (type '"$1"') 2>&1)" in
 		(*built*)	exit 0 ;;
+		(*reserved*)	exit 0 ;;   # zsh!! (reserved words are builtin)
 	 esac
 	 exit 1'	||
 	{
@@ -346,6 +347,32 @@ export_body() {
 		'unset VAR || exit 7; export VAR;
 		 VAR=ABC; printenv VAR; VAR=XYZ; printenv VAR'
 
+	# don't check VAR=value, some shells provide meaningless quoting...
+	atf_check -s exit:0 -e empty -o match:VAR= -o match:foobar \
+		${TEST_SH} -c \
+			'VAR=foobar ; export VAR ; export -p'
+	atf_check -s exit:0 -e empty -o match:VAR= -o match:foobar \
+		${TEST_SH} -c \
+			'export VAR=foobar ; export -p'
+	atf_check -s exit:0 -e empty -o match:VAR\$ ${TEST_SH} -c \
+			'unset VAR ; export VAR ; export -p'
+	atf_check -s exit:0 -e empty -o not-match:VAR ${TEST_SH} -c \
+			'export VAR ; unset VAR ; export -p'
+	atf_check -s exit:0 -e empty -o not-match:VAR -o not-match:foobar \
+		${TEST_SH} -c \
+			'VAR=foobar; export VAR ; unset VAR ; export -p'
+
+	atf_check -s exit:0 -e empty -o match:VAR= -o match:FOUND=foobar \
+		${TEST_SH} -c \
+			'export VAR=foobar; V=$(export -p);
+			 unset VAR; eval "$V"; export -p;
+			 printf %s\\n FOUND=${VAR-unset}'
+	atf_check -s exit:0 -e empty -o match:VAR -o match:FOUND=unset \
+		${TEST_SH} -c \
+			'export VAR; V=$(export -p);
+			 unset VAR; eval "$V"; export -p;
+			 printf %s\\n FOUND=${VAR-unset}'
+
 	atf_check -s exit:1 -e empty -o inline:ABC\\nXYZ\\n ${TEST_SH} -c \
 		'VAR=ABC; export VAR; printenv VAR; VAR=XYZ; printenv VAR;
 		unset VAR; printenv VAR; VAR=PQR; printenv VAR'
@@ -441,9 +468,42 @@ readonly_body() {
 		'unset VAR; readonly VAR; printf %s ${VAR-unset}'
 	atf_check -s exit:0 -e empty -o inline:set ${TEST_SH} -c \
 		'unset VAR; readonly VAR=set; printf %s ${VAR-unset}'
+	atf_check -s exit:0 -e empty -o inline:set ${TEST_SH} -c \
+		'VAR=initial; readonly VAR=set; printf %s ${VAR-unset}'
 	atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
 		'readonly VAR=initial; VAR=new; printf %s "${VAR}"'
 
+	# don't check VAR=value, some shells provide meaningless quoting...
+	atf_check -s exit:0 -e empty -o match:VAR= -o match:foobar \
+		${TEST_SH} -c \
+			'VAR=foobar ; readonly VAR ; readonly -p'
+	atf_check -s exit:0 -e empty -o match:VAR= -o match:foobar \
+		${TEST_SH} -c \
+			'readonly VAR=foobar ; readonly -p'
+	atf_check -s exit:0 -e empty -o match:VAR= -o match:foobar \
+		-o not-match:badvalue ${TEST_SH} -c \
+			'VAR=badvalue; readonly VAR=foobar ; readonly -p'
+	atf_check -s exit:0 -e empty -o match:VAR\$ ${TEST_SH} -c \
+			'unset VAR ; readonly VAR ; readonly -p'
+
+	# checking that readonly -p works (to reset stuff) is a pain...
+	# particularly since not all shells say "readonly..." by default
+	atf_check -s exit:0 -e empty -o match:MYVAR= -o match:FOUND=foobar \
+		${TEST_SH} -c \
+			'V=$(readonly MYVAR=foobar; readonly -p | grep " MYVAR")
+			 unset MYVAR; eval "$V"; readonly -p;
+			 printf %s\\n FOUND=${MYVAR-unset}'
+	atf_check -s exit:0 -e empty -o match:MYVAR\$ -o match:FOUND=unset \
+		${TEST_SH} -c \
+			'V=$(readonly MYVAR; readonly -p | grep " MYVAR")
+			 unset MYVAR; eval "$V"; readonly -p;
+			 printf %s\\n "FOUND=${MYVAR-unset}"'
+	atf_check -s exit:0 -e empty -o match:MYVAR= -o match:FOUND=empty \
+		${TEST_SH} -c \
+			'V=$(readonly MYVAR=; readonly -p | grep " MYVAR")
+			 unset VAR; eval "$V"; readonly -p;
+			 printf %s\\n "FOUND=${MYVAR-unset&}${MYVAR:-empty}"'
+
 	# don't test stderr, some shells inist on generating a message for an
 	# unset of a readonly var (rather than simply having unset make $?=1)
 



CVS commit: src/tests/bin/sh

2018-12-04 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Dec  5 02:48:05 UTC 2018

Modified Files:
src/tests/bin/sh: t_builtins.sh

Log Message:
Oops, this is 2018, not 2017 ... cut  (affects just copyright notice)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_builtins.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_builtins.sh
diff -u src/tests/bin/sh/t_builtins.sh:1.1 src/tests/bin/sh/t_builtins.sh:1.2
--- src/tests/bin/sh/t_builtins.sh:1.1	Wed Dec  5 02:45:06 2018
+++ src/tests/bin/sh/t_builtins.sh	Wed Dec  5 02:48:04 2018
@@ -1,6 +1,6 @@
-# $NetBSD: t_builtins.sh,v 1.1 2018/12/05 02:45:06 kre Exp $
+# $NetBSD: t_builtins.sh,v 1.2 2018/12/05 02:48:04 kre Exp $
 #
-# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without



CVS commit: src/tests/bin/sh/dotcmd

2018-12-04 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Dec  4 09:47:26 UTC 2018

Modified Files:
src/tests/bin/sh/dotcmd: scoped_command

Log Message:
Supply a missing \ ... this missing has meant that these tests
have not been testing everything they should have been testing.
Never mind, they still all succeed.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/dotcmd/scoped_command

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/dotcmd/scoped_command
diff -u src/tests/bin/sh/dotcmd/scoped_command:1.2 src/tests/bin/sh/dotcmd/scoped_command:1.3
--- src/tests/bin/sh/dotcmd/scoped_command:1.2	Sun Mar 27 14:57:50 2016
+++ src/tests/bin/sh/dotcmd/scoped_command	Tue Dec  4 09:47:25 2018
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: scoped_command,v 1.2 2016/03/27 14:57:50 christos Exp $
+# $NetBSD: scoped_command,v 1.3 2018/12/04 09:47:25 kre Exp $
 #
 # Copyright (c) 2014 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -71,7 +71,7 @@ set -e
 # don't rely on command lists (';')
 cmd="echo 'before ${3}'
 ${2}
-echo 'after ${3}, return value:' ${?}"
+echo 'after ${3}, return value:' \${?}"
 
 echo "#!${TEST_SH}"
 



CVS commit: src/tests/bin/sh

2018-11-27 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Nov 27 09:59:30 UTC 2018

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
Add two new test cases to add more tests for $@ expansions
(and a few more subtests in an existing test case).

The two new test cases currently fail, because of issues with
expanding "${1+$@}" which will (hopefully) be fixed soon.
(This looks to have been broken sometime during 2013 ... then I
made it even worse with some of the parser changes a while ago,
though the end result is that it appears less broken than it
really is.)


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.19 src/tests/bin/sh/t_expand.sh:1.20
--- src/tests/bin/sh/t_expand.sh:1.19	Sat Apr 21 21:28:35 2018
+++ src/tests/bin/sh/t_expand.sh	Tue Nov 27 09:59:30 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.19 2018/04/21 21:28:35 kre Exp $
+# $NetBSD: t_expand.sh,v 1.20 2018/11/27 09:59:30 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -63,6 +63,28 @@ dollar_at_body() {
 		'set -- -; shift; n_arg() { echo $#; }; n_arg "$@"'
 }
 
+atf_test_case dollar_at_unquoted_or_conditional
+dollar_at_unquoted_or_conditional_head() {
+	atf_set "descr" 'Sometime during 2013 the expansion of "${1+$@}"' \
+			' (where $1 and $2 (and maybe more) are set)' \
+			' seems to have broken.  Check for this bug.'
+}
+dollar_at_unquoted_or_conditional_body() {
+
+	atf_check -s exit:0 -o inline:'a\na\nb\nb\n' -e empty \
+		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n $@'
+	atf_check -s exit:0 -o inline:'a\na\nb\nb\n' -e empty \
+		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n ${1+$@}'
+	atf_check -s exit:0 -o inline:'a a\nb b\n' -e empty \
+		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n "$@"'
+	atf_check -s exit:0 -o inline:'a a\nb b\n' -e empty \
+		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n ${1+"$@"}'
+
+	# This is the one that fails when the bug is present
+	atf_check -s exit:0 -o inline:'a a\nb b\n' -e empty \
+		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n "${1+$@}"'
+}
+
 atf_test_case dollar_at_with_text
 dollar_at_with_text_head() {
 	atf_set "descr" "Test \$@ expansion when it is surrounded by text" \
@@ -106,26 +128,231 @@ EOF
 	for f in 1 2
 	do
 		atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
+			". ./h-f${f}; "'set -- ; delim_argv $@'
+		atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
 			". ./h-f${f}; "'set -- ; delim_argv "$@"'
 		atf_check -s exit:0 -o inline:'>foobar<\n' -e empty \
 			${TEST_SH} -c \
 			". ./h-f${f}; "'set -- ; delim_argv "foo$@bar"'
+		atf_check -s exit:0 -o inline:'>foobar<\n' -e empty \
+			${TEST_SH} -c \
+			". ./h-f${f}; "'set -- ; delim_argv foo"$@"bar'
 		atf_check -s exit:0 -o inline:'>foo  bar<\n' -e empty \
 			${TEST_SH} -c \
 			". ./h-f${f}; "'set -- ; delim_argv "foo $@ bar"'
+		atf_check -s exit:0 -o inline:'>foo  bar<\n' -e empty \
+			${TEST_SH} -c \
+			". ./h-f${f}; "'set -- ; delim_argv foo" $@ "bar'
 
 		atf_check -s exit:0 -o inline:'>a< >b< >c<\n' -e empty \
 			${TEST_SH} -c \
 			". ./h-f${f}; "'set -- a b c; delim_argv "$@"'
+
 		atf_check -s exit:0 -o inline:'>fooa< >b< >cbar<\n' -e empty \
 			${TEST_SH} -c \
 			". ./h-f${f}; "'set -- a b c; delim_argv "foo$@bar"'
+
 		atf_check -s exit:0 -o inline:'>foo a< >b< >c bar<\n' -e empty \
 			${TEST_SH} -c \
 			". ./h-f${f}; "'set -- a b c; delim_argv "foo $@ bar"'
 	done
 }
 
+atf_test_case dollar_at_empty_and_conditional
+dollar_at_empty_and_conditional_head() {
+	atf_set "descr" 'Test $@ expansion when there are no args, and ' \
+	'when conditionally expanded.'
+}
+dollar_at_empty_and_conditional_body() {
+
+	# same task, implementation different from previous,
+	# that these work is also a test...
+
+	cat <<'EOF' > h-f3
+
+delim_argv() {
+	str=
+	for Arg; do
+		str="${str:+${str} }>${Arg}<"
+	done
+	printf '%s\n' "${str}"
+}
+
+EOF
+
+	chmod +x h-f3
+
+	# in these we give printf a first arg of "", which makes
+	# the first output char be \n, then the $@ produces anything else
+	# (we need to make sure we don't end up with:
+	#	printf %s\\n
+	# -- that is, no operands for the %s, that's unspecified)
+
+	atf_check -s exit:0 -o inline:'\na a\nb b\n' -e empty \
+		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n "" "$@"'
+	atf_check -s exit:0 -o inline:'\n' -e empty \
+		${TEST_SH} -c 'set -- ; printf %s\\n "" "$@"'
+	atf_check -s exit:0 -o inline:'\n' -e empty \
+		${TEST_SH} -c 'set -- ; printf %s\\n ""${1+"$@"}'
+	atf_check -s exit:0 -o inline:'\n' -e empty \
+		${TEST_SH} -c 'set -- ; printf %s\\n """${1+$@}"'
+
+	# in these we prefix (concat) the $@ expansion with "" to make
+	# sure there is always at least one arg for the %s in printf
+	# If there 

CVS commit: src/tests/bin/sh

2018-11-27 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Nov 27 09:55:32 UTC 2018

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
Add a new test case to test <> (open for input & output),
includion a test to make sure that the file doesn't get truncated.

Add new subtests to the "incorrect redirections" test case, to
validate correct behaviour of the shell when redirections fail in
various scenarios, including when the redirect is the whole command.

More along these lines are really needed, but this is better than nothing.

All the added tests pass on the /bin/sh currently in netbsd HEAD.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.9 src/tests/bin/sh/t_redir.sh:1.10
--- src/tests/bin/sh/t_redir.sh:1.9	Sat May 14 00:33:02 2016
+++ src/tests/bin/sh/t_redir.sh	Tue Nov 27 09:55:32 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.9 2016/05/14 00:33:02 kre Exp $
+# $NetBSD: t_redir.sh,v 1.10 2018/11/27 09:55:32 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -326,6 +326,74 @@ nl='
 "#$T: Incorrect Out2: Should be 'line 1\\nline 2\\nline 3' is '$(cat Out2)'"
 }
 
+atf_test_case do_redirect_input_output
+do_redirect_input_output_head()
+{
+	atf_set "descr" "Test Input+Output (BiDir) redirections"
+}
+do_redirect_input_output_body()
+{
+nl='
+'
+	T=0
+	i() { T=$(expr "$T" + 1); }
+
+	rm -f Output 2>/dev/null || :
+	test -f Output && atf_fail "Unable to remove Output file"
+#1
+	i; atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '<> Output'
+	test -f Output || atf_fail "#$T: Did not make Output file"
+
+#2
+	echo data >Output 2>/dev/null || :
+	i
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'<>Output'
+	test -f Output || atf_fail "#$T: Removed Output file"
+	test -s Output || atf_fail "#$T: Did not keep data in Output file"
+	test "$(cat Output)" = "data" ||
+	  atf_fail "#$T: Incorrect Output: Should be 'data' is '$(cat Output)'"
+
+#3
+	rm -f Output 2>/dev/null || :
+	i
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'echo Hello 1<>Output'
+	test -s Output || atf_fail "#$T: Did not keep non-empty Output file"
+	test "$(cat Output)" = "Hello" ||
+	  atf_fail "#$T: Incorrect Output: Should be 'Hello' is '$(cat Output)'"
+
+#4
+	printf data >Output 2>/dev/null || :
+	i
+	atf_check -s exit:0 -o inline:'data' -e empty ${TEST_SH} -c \
+		'cat <>Output'
+	test -f Output || atf_fail "#$T: Removed Output file"
+	test -s Output || atf_fail "#$T: Did not keep data in Output file"
+	test "$(cat Output)" = "data" ||
+	  atf_fail "#$T: Incorrect Output: Should be 'data' is '$(cat Output)'"
+
+#5
+	echo data >Output 2>/dev/null || :
+	i
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'echo Hello 1<>Output'
+	test -s Output || atf_fail "#$T: Did not make non-empty Output file"
+	test "$(cat Output)" = "Hello" ||
+	  atf_fail "#$T: Incorrect Output: Should be 'Hello' is '$(cat Output)'"
+
+#6
+	printf data >Output 2>/dev/null || :
+	i
+	atf_check -s exit:0 -o inline:data -e empty ${TEST_SH} -c \
+		'{ cat >&3; printf file; } <>Output 3>&1 >&0'
+	test -f Output || atf_fail "#$T: Removed Output file"
+	test -s Output || atf_fail "#$T: Did not keep data in Output file"
+	test "$(cat Output)" = "datafile" ||
+	  atf_fail \
+	  "#$T: Incorrect Output: Should be 'datafile' is '$(cat Output)'"
+}
+
 atf_test_case fd_redirections
 fd_redirections_head()
 {
@@ -583,6 +651,37 @@ incorrect_redirections_body() {
 	test -f '>' || atf_file "File '>' not created when it should"
 	test "$(cat '>')" = 'A Line Output' || atf_fail \
 	"Output file ('>') contains '$(cat '>')' instead of 'A Line Output'"
+
+	rm -fr OutDir
+	atf-check -s not-exit:0 -o empty -e not-empty \
+		${TEST_SH} -c ': > OutDir/stdout; printf foo'
+	atf-check -s not-exit:0 -o empty -e not-empty \
+		${TEST_SH} -c ': > OutDir/stdout || printf foo; printf bar'
+	atf-check -s exit:0 -o inline:bar -e not-empty \
+		${TEST_SH} -c '> OutDir/stdout; printf bar'
+	atf-check -s exit:0 -o inline:foobar -e not-empty \
+		${TEST_SH} -c '> OutDir/stdout || printf foo; printf bar'
+	atf-check -s exit:0 -o inline:bar -e not-empty \
+		${TEST_SH} -c 'command : > OutDir/stdout; printf bar'
+	atf-check -s exit:0 -o inline:foobar -e not-empty ${TEST_SH} -c \
+		'command : > OutDir/stdout || printf foo; printf bar'
+	atf-check -s not-exit:0 -o empty -e not-empty \
+		${TEST_SH} -c ': <> OutDir/stdout; printf foo'
+
+	atf-check -s not-exit:0 -o empty -e not-empty \
+		${TEST_SH} -c ': >&8 ; printf foo'
+	atf-check -s not-exit:0 -o empty -e not-empty \
+		${TEST_SH} -c ': >&8 || printf foo; printf bar'
+	atf-check -s exit:0 -o inline:bar -e not-empty \
+		${TEST_SH} -c '>&8 ; printf bar'
+	atf-check -s exit:0 -o inline:foobar -e not-empty \

CVS commit: src/tests/bin/sh

2018-11-18 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Nov 18 13:41:24 UTC 2018

Modified Files:
src/tests/bin/sh: t_patterns.sh

Log Message:
It turns out there are more cases where escaping of meta-chars
was not being done properly (too many different code paths inside sh)
so add even more subtests to the case_matching test case to verify
that all (that I can think of for now anyway) get fixed when this
gets cleaned up.   The case_matching test case still fails, but now
6 of its subtests should fail (until sh is corrected ... soon).


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_patterns.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_patterns.sh
diff -u src/tests/bin/sh/t_patterns.sh:1.3 src/tests/bin/sh/t_patterns.sh:1.4
--- src/tests/bin/sh/t_patterns.sh:1.3	Sun Nov 18 01:24:44 2018
+++ src/tests/bin/sh/t_patterns.sh	Sun Nov 18 13:41:24 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_patterns.sh,v 1.3 2018/11/18 01:24:44 kre Exp $
+# $NetBSD: t_patterns.sh,v 1.4 2018/11/18 13:41:24 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -675,10 +675,28 @@ case_matching_body() {
 	# The first of the "set" tests pair was reported as broken bu
 	# Martijn Dekker (private mail) (Nov 2018).
 
-	cm "'\'" "'\'"			#262
-	cm "'\'" '"$var"' "var='\\'"; cf "'\'" '$var' "var='\\'"	#264
-	cm '$1' '"$2"' 'set -- \\ \\'; cf '$1' '$2' 'set -- \\ \\'	#266
-	cf '$1' '"$2"' 'set -- \\ '; cm '$1' '$2' 'set -- \\ '	#268
+	cm "'\\'" "'\\'"; cf "'\\'" "''"#263
+	cm "'\\'" '"$var"' "var='\\'"; cf "'\\'" '$var' "var='\\'"	#265
+	cm '$1' '"$2"' 'set -- \\ \\'; cf '$1' '$2' 'set -- \\ \\'	#267
+	cf '$1' '"$2"' 'set -- \\ '; cm '$1' '$2' 'set -- \\ '	#269
+	cm "'\\'" "\$( echo '' )"; cf "'\\'" "\$( echo '\\' )"	#271
+	cm "'\\'" "\"\$( echo '\\' )\""	#272
+	cf "'\\'" "\"\$( echo '' )\""#273
+
+	if X=$( ${TEST_SH} -c 'printf %s '"\$''" 2>/dev/null ) &&
+	[ "$X" = '\' ]
+	then
+		# TEST_SH supports $'...' so we can test it as well
+		# note these are $'\\' and $'' as patterns.
+		# They should be identical to '\' and '\\'
+		cm "'\\'" "\$''"; cf "'\\'" "\$''"		#275
+	else
+		# uncomment this if we need to keep sub-test numbering sane
+		# it isn't needed as long as this remains last.
+		# (nb: this is just a repeat of sub-test 263)
+
+		# cm "'\\'" "'\\'"; cf "'\\'" "''"			#275
+	fi
 
 	results
 }



CVS commit: src/tests/bin/sh

2018-11-17 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Nov 18 01:24:44 UTC 2018

Modified Files:
src/tests/bin/sh: t_patterns.sh

Log Message:
Add some tests to detect the presence of a bug in sh reported by
Martijn Dekker (private e-mail.)   Variable expansions that are
double quoted result in literal characters (nver pattern matching
meta chars.)  This includes '\' (that one was the bug.)
[On the other hand, a variable in a case pattern expansion that is
unquoted, produces a pattern, and in that the \ character can be
used to excape other pattern meta-chars (and itself.]

This addition will cause the case_matching test case to fail (two
of the newly added sub-tests fail) until fixes to /bin/sh are made.
(That is comiung soon, the code exists already.)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_patterns.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_patterns.sh
diff -u src/tests/bin/sh/t_patterns.sh:1.2 src/tests/bin/sh/t_patterns.sh:1.3
--- src/tests/bin/sh/t_patterns.sh:1.2	Fri Jul 20 18:25:56 2018
+++ src/tests/bin/sh/t_patterns.sh	Sun Nov 18 01:24:44 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_patterns.sh,v 1.2 2018/07/20 18:25:56 kre Exp $
+# $NetBSD: t_patterns.sh,v 1.3 2018/11/18 01:24:44 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -671,6 +671,15 @@ case_matching_body() {
 	cf '"["' '[!][:alpha:][!]'; cf a; cm 0; cf !; cf "']'"; cm %	#256
 	cf a '[$var]' 'var="![:alpha:]"'; cm 0; cm !; cm "']'"; cm @	#261
 
+	# Next some tests of patterns containing (intended literal) '\'
+	# The first of the "set" tests pair was reported as broken bu
+	# Martijn Dekker (private mail) (Nov 2018).
+
+	cm "'\'" "'\'"			#262
+	cm "'\'" '"$var"' "var='\\'"; cf "'\'" '$var' "var='\\'"	#264
+	cm '$1' '"$2"' 'set -- \\ \\'; cf '$1' '$2' 'set -- \\ \\'	#266
+	cf '$1' '"$2"' 'set -- \\ '; cm '$1' '$2' 'set -- \\ '	#268
+
 	results
 }
 



CVS commit: src/tests/bin/sh

2018-11-13 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Nov 14 02:37:51 UTC 2018

Modified Files:
src/tests/bin/sh: t_syntax.sh

Log Message:
Add a test for the bug in PR bin/53712   ( " { } > out " core dump )
Tested with both fixed, and unfixed, versions of /bin/sh (and in
posix mode, where that is a syntax error).


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/bin/sh/t_syntax.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.9 src/tests/bin/sh/t_syntax.sh:1.10
--- src/tests/bin/sh/t_syntax.sh:1.9	Mon Aug 21 00:56:22 2017
+++ src/tests/bin/sh/t_syntax.sh	Wed Nov 14 02:37:51 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.9 2017/08/21 00:56:22 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.10 2018/11/14 02:37:51 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -1197,6 +1197,34 @@ z_PR_52426_body() {
 		'case break in (/);; (\/);; (/\|/\));; (\\//);; esac'
 }
 
+atf_test_case z_PR_53712
+z_PR_53712_head() {
+	atf_set "descr" "Check for avoiding the core dump from PR bin/53712"
+}
+z_PR_53712_body() {
+	atf_require_prog sysctl
+	atf_require_prog rm
+
+	# Don't want to have to deal with all the possible ways
+	# that the systcm might be configured to drop core files...
+	sysctl -w proc.$$.corename=core ||
+		atf_skip "Unable to set file name for core dump file"
+	rm -f core
+
+	${TEST_SH} -c '{ } > out'; S=$?
+	test -f core &&
+		atf_fail "PR bin/53712: ${TEST_SH} dumps core: status=$S"
+	test "$S" -lt 128 ||
+		atf_fail "PR bin/53712: ${TEST_SH} reported status $S (core?)"
+
+	# It doesn't matter here whether or not there was an error
+	# from the empty compound, or whether "out" was created
+	# just that no core dump appeared, and the shell did not
+	# exit because of a signal.
+
+	return 0
+}
+
 atf_init_test_cases() {
 	atf_add_test_case a_basic_tokenisation
 	atf_add_test_case b_comments
@@ -1219,4 +1247,5 @@ atf_init_test_cases() {
 
 	atf_add_test_case z_PR_48498
 	atf_add_test_case z_PR_52426
+	atf_add_test_case z_PR_53712
 }



CVS commit: src/tests/bin/sh

2018-07-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jul 20 18:25:56 UTC 2018

Modified Files:
src/tests/bin/sh: t_patterns.sh

Log Message:
Several improvements to this test...

In the filename expansion test, don't insist on testing cases
of [^a] anything not an a) (etc) - while almost all shells allow
^ there (as in regular expressions) this is not standard sh/glob syntax
(! is used for that, not ^).  Use of ^ as first char after '[' in a []
match has unspecified behaviour.   So, check if the shell being
tested supports ^ used this way before running the tests of ^ in [].
This makes no difference at all when testing the NetBSD sh which
does allow ^ for that use case.

Fix an obvious (in hindsight) stupidity in the case pattern tests
(a cut/paste/forget-to-fix type error).

Many cleanups, including some additional sub-tests, for the var
substring matching (just a couple of actual fixes to the tests).
(This was the last added, and least polished part - still is.)

This makes no difference to the filename expansion tests (11 of 167
still fail), the fix reduces the failing case match tests from
14 of 261 to 13 of 261.   For var substring tests, the failure
has changed from 6 of 87 to 8 of 99.   (Some) Fixes to sh will appear
soon.

For comparison, using this version of the test, dash passes all case
and var substring tests, and (aside from the [^...] tests which it
does not implement) fails 4 of the filename tests.   bash fails one
case test (a bash oddity in interpretation of the spec, which is unique
to bash amongst shells I have tested)  and one filename expansion (all
var substring tests pass).  Other shells are much worse (though the
freebsd shell results were coloured by the version of their shell I
tested still having the [[:xxx:]] always matches '[' bug, which is
fixed in later versions of their shell)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_patterns.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_patterns.sh
diff -u src/tests/bin/sh/t_patterns.sh:1.1 src/tests/bin/sh/t_patterns.sh:1.2
--- src/tests/bin/sh/t_patterns.sh:1.1	Tue Jul 10 06:49:29 2018
+++ src/tests/bin/sh/t_patterns.sh	Fri Jul 20 18:25:56 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_patterns.sh,v 1.1 2018/07/10 06:49:29 kre Exp $
+# $NetBSD: t_patterns.sh,v 1.2 2018/07/20 18:25:56 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -491,6 +491,10 @@ filename_expansion_body() {
 
 	# '^' as the first char in a bracket expr is unspecified by POSIX,
 	# but for compat with REs everyone (sane) makes it the same as !
+
+	# But just in case we are testing an insane shell ...
+${TEST_SH} -c 'case "^" in ([^V^]) exit 1;; (*) exit 0;; esac' && {
+
 	check 'printf "%s\n" [^ab] | wc -l'		'24'	0
 	check 'printf "%s\n" [^ab]* | wc -l'		'5281'	0
 	check 'printf "%s\n" [^A-D]* | wc -l'		'5692'	0
@@ -515,6 +519,8 @@ filename_expansion_body() {
 	check 'printf "%s\n" [!^-b]? | wc -l'		'487'	0
 	check 'printf "%s\n" [^!-b]? | wc -l'		'63'	0
 
+}
+
 	# No need to clean up the directory, we're in the ATF working
 	# directory, and ATF cleans up for us.
 
@@ -630,7 +636,7 @@ case_matching_body() {
 
 	cm "'\z'" '"\z"'; cf z; cm '\\z'; cm '$var' '' 'var="\z"'	#144
 	cm '${var}' '' "var='\z'"; cm '"${var}"'			#146
-	cf '${var}' '${var}' "var='\z'"; cf '${var}' '"${var}"' "var='\z'" #148
+	cf '${var}' '${var}' "var='\z'"; cm '${var}' '"${var}"' "var='\z'" #148
 	cf "'${var}'"; cm "'${var}'" "'${var}'" "var='\z'"		#150
 
 	cf abc '"$*"' 'IFS=?; set -- a c';cf '"a c"';cm "'a?c'";cm '"$*"' #154
@@ -694,82 +700,87 @@ var_substring_matching_body() {
 	reset var_substring_matching
 
 	vm abc \# a bc; vm aaab \# a aab; vm aaab \## 'a*a' b		#  3
-	vm aaab % ab aa; vm xawab %% 'a*ab' x; vm abcd \# xyz abcd	#  6
-	vm file.c % .c 'f le' IFS=i ; vm file.c % .c file IFS=i Q	#  8
-	vm file.c % ?c file ; vm file.c % '"?c"' file.c			# 10
+	vm aaab % ab aa; vm xawab %% 'a*ab' x; vm abcd \# xyz abcd
+	vm file.c % .c 'f le' IFS=i ; vm file.c % .c file IFS=i Q
+	vm file.c % ?c file ; vm file.c % '"?c"' file.c			# 9 10
 
-	vm abcabcabcded \# 'a*b' cabcabcded; vm abcabcabcded \## 'a*b' cded # 12
-	vm abcabcabcded % 'c*d' abcabcab; vm abcabcabcded %% 'c*d' ab	# 14
+	vm abcabcabcded \# 'a*b' cabcabcded; vm abcabcabcded \## 'a*b' cded
+	vm abcabcabcded % 'c*d' abcabcab; vm abcabcabcded %% 'c*d' ab
 
 	vm abc.jpg % '.[a-z][!0-9]?' abc# 15
 
-	vm xxxyyy \# '${P}' yyy P=xxx; vm xxxyyy \# '${P}' yyy 'P=x?x'	# 17
-	vm xxxyyy \# '${P}' yyy 'P=x?x' Q# 18
-	vm 'x?xyyy' \# '${P}' yyy 'P=x[?]x';vm xxxyyy \# '${P}' xxxyyy 'P=x[?]x'
-	vm 'x?xyyy' \# '${P}' yyy 'P=x?x' Q;vm xxxyyy \# '${P}' yyy 'P=x?x' Q
-	vm 'x?xyyy' \# '${P}' 'x?xyyy' 'P="x\?x"'			# 23
-	vm 'x?xyyy' \# '${P}' 'x?xyyy' 'P="x\?x"' Q			# 24
+	vm xxxyyy \# '${P}' yyy P=xxx; vm xxxyyy \# '${P}' yyy 'P=x?x'
+	vm xxxyyy \# 

CVS commit: src/tests/bin/sh

2018-04-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Apr 21 21:28:35 UTC 2018

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
Add a test case for PR bin/53201

Currently this test case will fail, a fix is coming soon (not worth
marking this as an expected failure.)

This test case and the initial bug report comes from
Martijn Dekker's modernish (shell/test set).


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.18 src/tests/bin/sh/t_expand.sh:1.19
--- src/tests/bin/sh/t_expand.sh:1.18	Fri Oct  6 17:05:05 2017
+++ src/tests/bin/sh/t_expand.sh	Sat Apr 21 21:28:35 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.18 2017/10/06 17:05:05 kre Exp $
+# $NetBSD: t_expand.sh,v 1.19 2018/04/21 21:28:35 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -997,6 +997,58 @@ dollar_star_in_quoted_word_body() {
 	results	  # FIXED: 'PR bin/52090 - 2 of 26 subtests expected to fail'
 }
 
+atf_test_case embedded_nl
+embedded_nl_head() {
+	atf_set "descr" 'Test literal \n in xxx string in ${var-xxx}'
+}
+embedded_nl_body() {
+
+	atf_check -s exit:0 -o inline:'a\nb\n' -e empty ${TEST_SH} <<- 'EOF'
+		unset V
+		X="${V-a
+		b}"
+		printf '%s\n' "${X}"
+		EOF
+
+	atf_check -s exit:0 -o inline:'a\nb\n' -e empty ${TEST_SH} <<- 'EOF'
+		unset V
+		X=${V-"a
+		b"}
+		printf '%s\n' "${X}"
+		EOF
+
+	# This should not generate a syntax error, see PR bin/53201
+	atf_check -s exit:0 -o inline:'abc\n' -e empty ${TEST_SH} <<- 'EOF'
+		V=abc
+		X=${V-a
+		b}
+		printf '%s\n' "${X}"
+		EOF
+
+	# Nor should any of these...
+	atf_check -s exit:0 -o inline:'a\nb\n' -e empty ${TEST_SH} <<- 'EOF'
+		unset V
+		X=${V-a
+		b}
+		printf '%s\n' "${X}"
+		EOF
+
+	atf_check -s exit:0 -o inline:'a\nb\n' -e empty ${TEST_SH} <<- 'EOF'
+		unset V
+		X=${V:=a
+		b}
+		printf '%s\n' "${X}"
+		EOF
+
+	atf_check -s exit:0 -o inline:'xa\nby\na\nb\n' -e empty \
+	${TEST_SH} <<- 'EOF'
+		unset V
+		X=x${V:=a
+		b}y
+		printf '%s\n' "${X}" "${V}"
+		EOF
+}
+
 atf_init_test_cases() {
 	# Listed here in the order ATF runs them, not the order from above
 
@@ -1009,6 +1061,7 @@ atf_init_test_cases() {
 	atf_add_test_case dollar_star_in_word
 	atf_add_test_case dollar_star_in_word_empty_ifs
 	atf_add_test_case dollar_star_with_empty_ifs
+	atf_add_test_case embedded_nl
 	atf_add_test_case iteration_on_null_parameter
 	atf_add_test_case iteration_on_quoted_null_parameter
 	atf_add_test_case iteration_on_null_or_null_parameter



CVS commit: src/tests/bin/sh

2017-11-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Nov 16 19:41:42 UTC 2017

Modified Files:
src/tests/bin/sh: t_option.sh

Log Message:
Add a test case for "set -X".

Currently (or when testing any shell that does not support -X) the
test will be skipped (also for [m]ksh (but not ksh93 etc) where there
is an absurdly badly named -X option, skip the new test for them as well.)

When -X appears in /bin/sh, this will verify that it is probably working
(the test is MUCH more gruelling than any rational use of -X would be.)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_option.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_option.sh
diff -u src/tests/bin/sh/t_option.sh:1.5 src/tests/bin/sh/t_option.sh:1.6
--- src/tests/bin/sh/t_option.sh:1.5	Sat Jul 15 18:52:21 2017
+++ src/tests/bin/sh/t_option.sh	Thu Nov 16 19:41:41 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_option.sh,v 1.5 2017/07/15 18:52:21 kre Exp $
+# $NetBSD: t_option.sh,v 1.6 2017/11/16 19:41:41 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -77,7 +77,7 @@ test_option_on_off()
 			# if we do not do this, -x tracing splatters stderr
 			# for some shells, -v does as well (is that correct?)
 			case "${opt}" in
-			(*[xv]*)	exec 2>/dev/null;;
+			(*[xXv]*)	exec 2>/dev/null;;
 			esac
 
 			o="$-"
@@ -498,6 +498,329 @@ set_x_body() {
 	   'set -x; for i in 111 222 333; do printf "%s" $i; done; echo; exit 0'
 }
 
+atf_test_case set_X
+set_X_head() {
+	atf_set "descr" "Tests that 'set -X' turns on command exec logging " \
+	"and that it enables set -x and retains a single fd"
+}
+set_X_body() {
+
+	# First we need to verify that $TEST_SH supports -X
+	test_optional_on_off X	||
+		atf_skip "$TEST_SH does not support -X"
+
+	# and that the -X it implements is the -X we expect
+	$TEST_SH -c 'exec 2>/dev/null;
+		set +x; set -X;
+		case "$-" in (*x*) exit 0;; esac;
+		exit 1'		||
+			atf_skip "$TEST_SH supports -X but not 'the' -X"
+
+	# Above has already tested that set -X => set -x
+	# Now test that set +X => set +x
+	# and that set -x and set +x do not affect -X
+
+	atf_check -s exit:0 -o empty -e ignore ${TEST_SH} -c \
+		'set -x; set +X; case "$-" in (*x*) echo FAIL; exit 1;; esac'
+
+	atf_check -s exit:0 -o empty -e ignore ${TEST_SH} -c \
+		'set -X; set +x;
+		 case "$-" in (*x*) echo FAIL; exit 1;; esac
+		 case "$-" in (*X*) exit 0;; esac; echo ERROR; exit 2'
+
+	atf_check -s exit:0 -o empty -e ignore ${TEST_SH} -c \
+		'set -X; set +x; set -x;
+		 case "$-" in (*x*X*|*X*x*) exit 0;; esac; echo ERROR; exit 2'
+
+	atf_check -s exit:0 -o empty -e ignore ${TEST_SH} -c \
+		'set +X; set -x;
+		 case "$-" in (*X*) echo FAIL; exit 1;; esac
+		 case "$-" in (*x*) exit 0;; esac; echo ERROR; exit 2'
+
+	atf_check -s exit:0 -o empty -e ignore ${TEST_SH} -c \
+		'set +X; set -x; set +x;
+		 case "$-" in (*[xX]*) echo FAULT; exit 3;; esac'
+
+	# The following just verify regular tracing using -X instead of -x
+	# These are the same tests as the -x test (set_x) performs.
+
+	# check that cmd output appears after -X is enabled
+	atf_check -s exit:0 \
+			-o match:OKOK -o not-match:echo -o not-match:printf \
+			-e not-match:printf -e match:OK -e match:echo \
+		${TEST_SH} -ec 'printf "%s" OK; set -X; echo OK; exit 0'
+
+	# and that it stops again afer -X is disabled
+	atf_check -s exit:0 \
+			-o match:OKOK -o not-match:echo -o not-match:printf \
+			-e match:printf -e match:OK -e not-match:echo \
+	${TEST_SH} -ec 'set -X; printf "%s" OK; set +X; echo OK; exit 0'
+
+	# also check that PS4 is output correctly
+	atf_check -s exit:0 \
+			-o match:OK -o not-match:echo \
+			-e match:OK -e match:Run:echo \
+		${TEST_SH} -ec 'PS4=Run:; set -X; echo OK; exit 0'
+
+	# end copies of -x tests ...
+
+	# now check that we can move stderr around without affecting -X output
+
+	atf_check -s exit:0 \
+			-o match:OKOK -o not-match:echo -o not-match:printf \
+			-e match:printf -e match:OK -e match:echo \
+		${TEST_SH} -ecX 'printf "%s" OK; exec 2>/dev/null; echo OK'
+	atf_check -s exit:0 \
+			-o match:OKOK -o not-match:echo -o not-match:printf \
+			-e match:printf -e match:OK -e match:echo \
+		${TEST_SH} -ecX 'printf "%s" OK; exec 2>&1; echo OK'
+	atf_check -s exit:0 \
+			-o match:OKOK -o not-match:echo -o not-match:printf \
+			-e match:printf -e match:OK -e match:echo \
+		${TEST_SH} -ecX 'printf "%s" OK; exec 2>&-; echo OK'
+
+	# and that we can put tracing on an external file, leaving stderr alone
+
+	atf_require_prog grep
+
+	rm -f X-trace
+	atf_check -s exit:0 \
+			-o match:OKOK -o not-match:echo -o not-match:printf \
+			-e empty \
+		${TEST_SH} -ec 'PS4=; set -X 2>X-trace; printf "%s" OK; echo OK'
+	test -s X-trace || atf_fail "T1: Failed to create trace output file"
+	grep >/dev/null 2>&1 'printf.*%s.*OK' X-trace ||
+		atf_fail "T1: -X 

CVS commit: src/tests/bin/sh

2017-10-06 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Oct  6 17:05:05 UTC 2017

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
Add a new sub-test to validate ~ expansions.

Currently testing ~user is too much effort to contemplate (other than
assuming that it works in order to verify that it works...) so only bare ~
is being tested for now.   Maybe someday...

Right now (@ time of commit), this new test is expected to fail, as ~
expansions are horribly badly broken (have been for months, some forms
for much longer) in all but the simplest of uses.   Fix for that coming
very soon.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.17 src/tests/bin/sh/t_expand.sh:1.18
--- src/tests/bin/sh/t_expand.sh:1.17	Sat Jun  3 14:45:59 2017
+++ src/tests/bin/sh/t_expand.sh	Fri Oct  6 17:05:05 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.17 2017/06/03 14:45:59 kre Exp $
+# $NetBSD: t_expand.sh,v 1.18 2017/10/06 17:05:05 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -200,6 +200,66 @@ ne%\
 	done
 }
 
+atf_test_case tilde
+tilde_head() {
+	atf_set "descr" "Checks that the ~ expansions work"
+}
+tilde_body() {
+	for HOME in '' / /home/foo \
+/a/very/long/home/directory/path/that/might/push/the/tilde/expansion/code/beyond/what/it/would/normally/ever/see/on/any/sane/system/and/perhaps/expose/some/bugs
+	do
+		export HOME
+
+		atf_check -s exit:0 -e empty \
+			-o inline:'HOME\t'"${HOME}"'
+~\t'"${HOME}"'
+~/foobar\t'"${HOME}"'/foobar
+"$V"\t'"${HOME}"'
+"$X"\t~
+"$Y"\t'"${HOME}"':'"${HOME}"'
+"$YY"\t'"${HOME}"'/foo:'"${HOME}"'/bar
+"$Z"\t'"${HOME}"'/~
+${U:-~}\t'"${HOME}"'
+$V\t'"${HOME}"'
+$X\t~
+$Y\t'"${HOME}"':'"${HOME}"'
+$YY\t'"${HOME}"'/foo:'"${HOME}"'/bar
+$Z\t'"${HOME}"'/~
+${U:=~}\t'"${HOME}"'
+${UU:=~:~}\t'"${HOME}"':'"${HOME}"'
+${UUU:=~/:~}\t'"${HOME}"'/:'"${HOME}"'
+${U4:=~/:~/}\t'"${HOME}"'/:'"${HOME}"'/\n' \
+			${TEST_SH} -s <<- \EOF
+unset -v U UU UUU U4
+V=~
+X="~"
+Y=~:~ YY=~/foo:~/bar
+Z=~/~
+printf '%s\t%s\n' \
+	'HOME' "${HOME}" \
+	'~' ~ \
+	'~/foobar' ~/foobar \
+	'"$V"' "$V" \
+	'"$X"' "$X" \
+	'"$Y"' "$Y" \
+	'"$YY"' "$YY" \
+	'"$Z"' "$Z" \
+	'${U:-~}' ''${U:-~} \
+	'$V' ''$V \
+	'$X' ''$X \
+	'$Y' ''$Y \
+	'$YY' ''$YY \
+	'$Z' ''$Z \
+	'${U:=~}' ''${U:=~} \
+	'${UU:=~:~}' ''${UU:=~:~} \
+	'${UUU:=~/:~}' ''${UUU:=~/:~} \
+	'${U4:=~/:~/}' ''${U4:=~/:~/}
+			EOF
+	done
+
+	# Testing ~user is harder, so, perhaps later...
+}
+
 atf_test_case varpattern_backslashes
 varpattern_backslashes_head() {
 	atf_set "descr" "Tests that protecting wildcards with backslashes" \
@@ -955,6 +1015,7 @@ atf_init_test_cases() {
 	atf_add_test_case iteration_on_null_or_missing_parameter
 	atf_add_test_case shell_params
 	atf_add_test_case strip
+	atf_add_test_case tilde
 	atf_add_test_case wrap_strip
 	atf_add_test_case var_with_embedded_cmdsub
 	atf_add_test_case varpattern_backslashes



CVS commit: src/tests/bin/sh

2017-08-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Aug 21 00:56:22 UTC 2017

Modified Files:
src/tests/bin/sh: t_syntax.sh

Log Message:
Make the $'...' syntax tests test what is supposed to work, rather than
what I thought was required (just a couple of changes...).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/bin/sh/t_syntax.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.8 src/tests/bin/sh/t_syntax.sh:1.9
--- src/tests/bin/sh/t_syntax.sh:1.8	Sat Aug 19 21:18:47 2017
+++ src/tests/bin/sh/t_syntax.sh	Mon Aug 21 00:56:22 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.8 2017/08/19 21:18:47 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.9 2017/08/21 00:56:22 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -324,7 +324,8 @@ d_cstrings_body() {
 	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
 		"test \$'\\r-\\n-\\f' = \$'\\cm-\\cj-\\cl'"
 	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
-		"test \$'\\u0123' = \$'\\304\\243'"
+		"unset LC_ALL; export LC_CTYPE=en_AU.UTF-8;
+		test \$'\\u0123' = \$'\\304\\243'"
 	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
 		"test \$'\\u0123' = \$'\\xC4\\xA3'"
 	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
@@ -348,17 +349,13 @@ d_cstrings_body() {
 	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
 		": \$'\\uDEFF'"
 	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
-		": \$'\\u00'"
-	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
-		": \$'\\u8'"
-	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
 		": \$'abcd"
 	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
 		": \$'abcd\\"
 
-	# anything that generates \0 ends the $'...' immediately (\u cannot)
-	atf_check -s exit:0 -e empty -o inline:'aAa' ${TEST_SH} -c \
-		"printf '%s' \$'a\\0x'\$'A\\x00X'\$'a\\c@x'"
+	# anything that generates \0 ends the $'...' immediately
+	atf_check -s exit:0 -e empty -o inline:'aAaA' ${TEST_SH} -c \
+		"printf '%s' \$'a\\0x'\$'A\\x00X'\$'a\\c@x'\$'A\\uX'"
 
 	# \newline in a $'...' is dropped (just like in "" strings)
 	atf_check -s exit:0 -e empty -o inline:'abcdef' ${TEST_SH} -c \



CVS commit: src/tests/bin/sh

2017-08-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Aug 19 21:18:47 UTC 2017

Modified Files:
src/tests/bin/sh: t_syntax.sh

Log Message:
Add a few more sub-tests to the $'...' syntax tests.
Remove dome debug noise accidentally left in when the test was first added.
(This still does not matter just yet, but should do soon.)


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/bin/sh/t_syntax.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.7 src/tests/bin/sh/t_syntax.sh:1.8
--- src/tests/bin/sh/t_syntax.sh:1.7	Fri Aug 18 21:22:30 2017
+++ src/tests/bin/sh/t_syntax.sh	Sat Aug 19 21:18:47 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.7 2017/08/18 21:22:30 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.8 2017/08/19 21:18:47 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -300,8 +300,8 @@ d_cstrings_head() {
 	atf_set "descr" "Check processing of $' ' quoting (C style strings)"
 }
 d_cstrings_body() {
-	set -xv
 	unset ENV
+
 	if ! ${TEST_SH} -c ": \$'abc'" ||
 	 test $( ${TEST_SH} -c "printf %s \$'abc'" ) != abc
 	then
@@ -335,7 +335,6 @@ d_cstrings_body() {
 	# all the \X sequences for a single char X (ie: not hex/octal/unicode)
 	atf_check -s exit:0 -e empty -o inline:'\n\r\t\n' \
 		${TEST_SH} -c "printf '%s\\n' \$'\\a\\b\\e\\f\\n\\r\\t\\v'"
-#	atf_check -s exit:0 -e empty -o inline:'\7\10\33\14\12\15\11\13' \
 	atf_check -s exit:0 -e empty -o inline:'\n\r\t\n' \
 	   ${TEST_SH} -c "printf '%s\\n' \$'\\cG\\cH\\x1b\\cl\\cJ\\cm\\cI\\ck'"
 	atf_check -s exit:0 -e empty -o inline:"'"'"\\\n' \
@@ -363,8 +362,24 @@ d_cstrings_body() {
 
 	# \newline in a $'...' is dropped (just like in "" strings)
 	atf_check -s exit:0 -e empty -o inline:'abcdef' ${TEST_SH} -c \
-		"printf '%s' \$'abc\\
+"printf '%s' \$'abc\\
+def'"
+	# but a normal newline in a $'...' is just a newline
+	atf_check -s exit:0 -e empty -o inline:'abc\ndef' ${TEST_SH} -c \
+"printf '%s' \$'abc
 def'"
+	# and should work when elided line wrap occurs between $ and '
+	atf_check -s exit:0 -e empty -o inline:'abc\ndef' ${TEST_SH} -c \
+"printf '%s' \$\\
+'abc\\ndef'"
+
+	# $'...' only works when the $ is unquoted.
+	atf_check -s exit:0 -e empty -o inline:"abc\$'def'g" ${TEST_SH} -c \
+		"printf '%s' \"abc\$'def'g\""
+	atf_check -s exit:0 -e empty -o inline:'abc$defg' ${TEST_SH} -c \
+		"printf '%s' abc\\\$'def'g"
+	atf_check -s exit:0 -e empty -o inline:'abc$def' ${TEST_SH} -c \
+		"printf '%s' abc'\$'def"
 }
 
 atf_test_case f_redirects



CVS commit: src/tests/bin/sh

2017-08-18 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Aug 18 21:22:30 UTC 2017

Modified Files:
src/tests/bin/sh: t_syntax.sh

Log Message:
Add a basic test for $'...' quoting (roughly C ctyle strings).
This test will be skipped on shells (such as /bin/sh in -current as of
the date of this commit) which do not support $'...'

While here fix a typo in a comment (there are probably more...)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/bin/sh/t_syntax.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.6 src/tests/bin/sh/t_syntax.sh:1.7
--- src/tests/bin/sh/t_syntax.sh:1.6	Wed Jul 26 17:50:20 2017
+++ src/tests/bin/sh/t_syntax.sh	Fri Aug 18 21:22:30 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.6 2017/07/26 17:50:20 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.7 2017/08/18 21:22:30 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -261,7 +261,7 @@ c_line_wrapping_body() {
 	done
 
 	# inspired by pkgsrc/pkgtools/cwrappers :: libnbcompat/configure
-	# failure with (broken) sh LINENO core .. avoid recurrence
+	# failure with (broken) sh LINENO code .. avoid recurrence
 	# This test would have failed.
 	cat <<- 'DONE' | atf_check -s exit:0 -o inline:'/tmp\n' ${TEST_SH}
 		dn=/tmp/foo
@@ -295,11 +295,83 @@ c_line_wrapping_body() {
 	return 0
 }
 
-atf_test_case d_redirects
-d_redirects_head() {
+atf_test_case d_cstrings
+d_cstrings_head() {
+	atf_set "descr" "Check processing of $' ' quoting (C style strings)"
+}
+d_cstrings_body() {
+	set -xv
+	unset ENV
+	if ! ${TEST_SH} -c ": \$'abc'" ||
+	 test $( ${TEST_SH} -c "printf %s \$'abc'" ) != abc
+	then
+		atf_skip "\$'...' (C style quoted strings) not supported"
+	fi
+
+	# simple stuff
+	atf_check -s exit:0 -e empty -o inline:'abc\tdef\n' ${TEST_SH} -c \
+		"printf '%s\\n' \$'abc\tdef'"
+	atf_check -s exit:0 -e empty -o inline:'abc\tdef\n' ${TEST_SH} -c \
+		"printf '%s\\n' \$'abc\011def'"
+	atf_check -s exit:0 -e empty -o inline:'abc\tdef\n' ${TEST_SH} -c \
+		"printf '%s\\n' \$'abc\x09'def"
+	atf_check -s exit:0 -e empty -o inline:'abc$def\n' ${TEST_SH} -c \
+		"def=xyz; printf '%s\\n' \$'abc\$def'"
+
+	# control chars (\c) and unicode \u
+	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
+		"test \$'\\1-\\2-\\3' = \$'\\ca-\\cb-\\cc'"
+	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
+		"test \$'\\r-\\n-\\f' = \$'\\cm-\\cj-\\cl'"
+	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
+		"test \$'\\u0123' = \$'\\304\\243'"
+	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
+		"test \$'\\u0123' = \$'\\xC4\\xA3'"
+	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
+		"test \$'\\c' = \$'\\x1C'"
+	atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
+		"test \$'\\c[\\c]\\c^\\c_\\c?' = \$'\\x1B\\x1D\\x1E\\x1F\\x7F'"
+
+	# all the \X sequences for a single char X (ie: not hex/octal/unicode)
+	atf_check -s exit:0 -e empty -o inline:'\n\r\t\n' \
+		${TEST_SH} -c "printf '%s\\n' \$'\\a\\b\\e\\f\\n\\r\\t\\v'"
+#	atf_check -s exit:0 -e empty -o inline:'\7\10\33\14\12\15\11\13' \
+	atf_check -s exit:0 -e empty -o inline:'\n\r\t\n' \
+	   ${TEST_SH} -c "printf '%s\\n' \$'\\cG\\cH\\x1b\\cl\\cJ\\cm\\cI\\ck'"
+	atf_check -s exit:0 -e empty -o inline:"'"'"\\\n' \
+		${TEST_SH} -c "printf '%s\\n' \$'\\'\\\"'"
+
+	# various invalid $'...' sequences
+	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
+		": \$'\\q'"
+	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
+		": \$'\\c\\q'"
+	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
+		": \$'\\uDEFF'"
+	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
+		": \$'\\u00'"
+	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
+		": \$'\\u8'"
+	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
+		": \$'abcd"
+	atf_check -s not-exit:0 -e not-empty -o ignore ${TEST_SH} -c \
+		": \$'abcd\\"
+
+	# anything that generates \0 ends the $'...' immediately (\u cannot)
+	atf_check -s exit:0 -e empty -o inline:'aAa' ${TEST_SH} -c \
+		"printf '%s' \$'a\\0x'\$'A\\x00X'\$'a\\c@x'"
+
+	# \newline in a $'...' is dropped (just like in "" strings)
+	atf_check -s exit:0 -e empty -o inline:'abcdef' ${TEST_SH} -c \
+		"printf '%s' \$'abc\\
+def'"
+}
+
+atf_test_case f_redirects
+f_redirects_head() {
 	atf_set "descr" "Check parsing of redirect operators"
 }
-d_redirects_body() {
+f_redirects_body() {
 
 	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'>/dev/null'
@@ -355,11 +427,11 @@ d_redirects_body() {
 	return 0
 }
 
-atf_test_case f_variable_syntax
-f_variable_syntax_head() {
+atf_test_case g_variable_syntax
+g_variable_syntax_head() {
 	atf_set "descr" "Check that var names of all legal forms work"
 }
-f_variable_syntax_body() {
+g_variable_syntax_body() {
 	# don't test _ as a variable, it 

CVS commit: src/tests/bin/sh

2017-07-26 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jul 26 17:50:21 UTC 2017

Modified Files:
src/tests/bin/sh: t_syntax.sh

Log Message:
PR bin/48498   PR bin/52426

Add two new sh syntax test cases to check for bug fixes for the parser
problems (syntax errors unidentified) reported in the two PRs.

In the latter case, also include some tests that test similar
looking, valid, syntax - to make sure the fix for the PR does not
break code that should not fail.  This is not needed for the earlier
PR as other tests, and just normal parsing, is sufficient.

These tests have been verified to fail with a current /bin/sh and to
pass with the sh updates that are to be committed soon -- and because that
fix is expected within hours, the tests are not marked as expected to
fail, just let them actually fail for now.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_syntax.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.5 src/tests/bin/sh/t_syntax.sh:1.6
--- src/tests/bin/sh/t_syntax.sh:1.5	Sat Jun 24 11:09:42 2017
+++ src/tests/bin/sh/t_syntax.sh	Wed Jul 26 17:50:20 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.5 2017/06/24 11:09:42 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.6 2017/07/26 17:50:20 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -988,6 +988,131 @@ x_functions_body() {
 		'f1() { eval "$1() { :; }"; }; f1 f2; f2'
 }
 
+atf_test_case z_PR_48498
+z_PR_48498_head() {
+	atf_set "descr" "Check for detecting the syntax error from PR bin/48498"
+}
+z_PR_48498_body() {
+
+	# reserved words/operators that end things,
+	# were completely ignored after a ';' or '&'
+	# many of these tests lifted directly from the PR
+
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true; fi'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'false; fi'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'false; then echo wut'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true; then echo wut'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true; do echo wut'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true; then'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true; else'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true; do'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true; done'
+		# {
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		': ; }'
+		# (
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		':;)'
+
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true& fi'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'false& fi'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'false& then echo wut'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true& then echo wut'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true& do echo wut'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true& then'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true& else'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true& do'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'true'
+		# {
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		':&}'
+		# (
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		':&)'
+}
+
+atf_test_case z_PR_52426
+z_PR_52426_head() {
+	atf_set "descr" "Check for detecting the syntax error from PR bin/52426"
+}
+z_PR_52426_body() {
+	# Absoluely anything was permitted as a pattern of a case
+	# statement, any token (except 'esac') would serve
+	# What follows are a few "pretty" examples that were accepted.
+	# The first is the example from the PR
+
+	# Note we use only ;; type case lists, ;& should do the same, but
+	# only for shells that support it, we do not want the shell to
+	# object to any of these just because it does not support ;&
+
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'case x in <|() ;; esac'
+
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'case x in ((|)) ;; esac'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'case x in _|() ;; esac'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'case x in ()|() ;; esac'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'case x in -|;) ;; esac'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'case x in (;|-) ;; esac'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'case x in ;;|;) ;; esac'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \

CVS commit: src/tests/bin/sh

2017-07-15 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jul 15 18:52:21 UTC 2017

Modified Files:
src/tests/bin/sh: t_option.sh

Log Message:
Add some tests for the (likely forthcoming) pipefail option (modelled
after than in ksh and bash, and the similar thing in zsh) for which a
request has been made for support in the NetBSD sh.

Until the support is committed, the test will be skipped.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_option.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_option.sh
diff -u src/tests/bin/sh/t_option.sh:1.4 src/tests/bin/sh/t_option.sh:1.5
--- src/tests/bin/sh/t_option.sh:1.4	Fri Jun  2 01:38:44 2017
+++ src/tests/bin/sh/t_option.sh	Sat Jul 15 18:52:21 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_option.sh,v 1.4 2017/06/02 01:38:44 kre Exp $
+# $NetBSD: t_option.sh,v 1.5 2017/07/15 18:52:21 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -598,6 +598,56 @@ vi_emacs_VE_toggle_body() {
 	'
 }
 
+atf_test_case pipefail
+pipefail_head() {
+	atf_set "descr" "Basic tests of the pipefail option"
+}
+pipefail_body() {
+	${TEST_SH} -c 'set -o pipefail' 2>/dev/null ||
+		atf_skip "pipefail option not supported by ${TEST_SH}"
+
+	atf_check -s exit:0 -o match:'pipefail.*off' -e empty ${TEST_SH} -c \
+		'set -o | grep pipefail'
+	atf_check -s exit:0 -o match:'pipefail.*on' -e empty ${TEST_SH} -c \
+		'set -o pipefail; set -o | grep pipefail'
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'(exit 1) | (exit 2) | (exit 0)'
+	atf_check -s exit:2 -o empty -e empty ${TEST_SH} -c \
+		'set -o pipefail; (exit 1) | (exit 2) | (exit 0)'
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'set -o pipefail; (exit 1) | (exit 0) | (exit 0)'
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'set -o pipefail; (exit 0) | (exit 0) | (exit 0)'
+
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'! (exit 1) | (exit 2) | (exit 0)'
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'set -o pipefail; ! (exit 1) | (exit 2) | (exit 0)'
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'set -o pipefail; ! (exit 1) | (exit 0) | (exit 0)'
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+		'set -o pipefail; ! (exit 0) | (exit 0) | (exit 0)'
+
+	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+		'(exit 1) | (exit 2) | (exit 0); echo $?'
+	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
+		'set -o pipefail; (exit 1) | (exit 2) | (exit 0); echo $?'
+	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+		'set -o pipefail; (exit 1) | (exit 0) | (exit 0); echo $?'
+	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+		'set -o pipefail; (exit 0) | (exit 0) | (exit 0); echo $?'
+
+	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+		'! (exit 1) | (exit 2) | (exit 0); echo $?'
+	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+		'set -o pipefail; ! (exit 1) | (exit 2) | (exit 0); echo $?'
+	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+		'set -o pipefail; ! (exit 1) | (exit 0) | (exit 0); echo $?'
+	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+		'set -o pipefail; ! (exit 0) | (exit 0) | (exit 0); echo $?'
+}
+
 atf_test_case xx_bogus
 xx_bogus_head() {
 	atf_set "descr" "Tests that attempting to set a nonsense option fails."
@@ -672,5 +722,8 @@ atf_init_test_cases() {
 	atf_add_test_case set_x
 
 	atf_add_test_case vi_emacs_VE_toggle
+
+	atf_add_test_case pipefail
+
 	atf_add_test_case xx_bogus
 }



CVS commit: src/tests/bin/sh

2017-07-15 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jul 15 18:50:42 UTC 2017

Modified Files:
src/tests/bin/sh: t_arith.sh

Log Message:
Add basic tests for the forthcoming ',' '++' and '--' operators.
Until the support for those is committed to /bin/sh (and when testing
any other sh that does not support them) the new tests will be skipped.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/bin/sh/t_arith.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_arith.sh
diff -u src/tests/bin/sh/t_arith.sh:1.7 src/tests/bin/sh/t_arith.sh:1.8
--- src/tests/bin/sh/t_arith.sh:1.7	Fri Jun  2 01:50:48 2017
+++ src/tests/bin/sh/t_arith.sh	Sat Jul 15 18:50:42 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_arith.sh,v 1.7 2017/06/02 01:50:48 kre Exp $
+# $NetBSD: t_arith.sh,v 1.8 2017/07/15 18:50:42 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -937,6 +937,46 @@ operator_precedence_body()
 
 	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
 		'echo $(( 0xfD & 0xF == 0xF ))'
+
+	${TEST_SH} -c ': $(( 1 , 2 , 3 ))' 2>/dev/null  && {
+		atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
+			'echo $(( 3 * 7 , 2 << 8 ,  9 - 7 ))'
+		atf_check -s exit:0 -o inline:'4\n' -e empty ${TEST_SH} -c \
+			'echo $(( 1 ? 2 : 3 , 0 ? 1 : 4 ))'
+	}
+
+	return 0
+}
+
+atf_test_case optional_comma
+optional_comma_head()
+{
+	atf_set "descr" "Test the optional comma operator"
+}
+optional_comma_body()
+{
+	# First, see if it is supported or not.
+	${TEST_SH} -c ': $(( 1 , 2 , 3 ))' 2>/dev/null  || atf_skip \
+	"${TEST_SH} does not implement the ',' operator in"' $(( ))'
+
+
+	# Note ',' should be set off from numbers by spaces, as in some
+	# locales it is a valid chacacter in a number, and we want to
+	# avoid any possibility of confusing the parser.
+
+	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
+		'echo $(( 1 , 2 ))'
+	atf_check -s exit:0 -o inline:'3\n' -e empty ${TEST_SH} -c \
+		'echo $(( 1 , 2 , 3 ))'
+	atf_check -s exit:0 -o inline:'4\n' -e empty ${TEST_SH} -c \
+		'echo $(( 1 , 2 , 3 , 4 ))'
+
+	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
+		'echo $(( , 2 ))'
+	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
+		'echo $(( 2 , ))'
+	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
+		'echo $(( 1 , , 2 ))'
 }
 
 parentheses_head()
@@ -999,9 +1039,16 @@ parentheses_body()
 		'echo $(( 2 << ((3 >= 3) << 2) ))'
 
 	# sh inherits C's crazy operator precedence...
-
 	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
 		'echo $(( (0xfD & 0xF) == 0xF ))'
+
+	${TEST_SH} -c ': $(( 1 , 2 , 3 ))' 2>/dev/null  && {
+		atf_check -s exit:0 -o inline:'24\n' -e empty ${TEST_SH} -c \
+			'echo $(( 3 * (7 , 2) << (8 ,  9 - 7) ))'
+		atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+			'echo $(( 0 ? 2 : ( ( 0 , 3 ) ? 1 : 4) ))'
+	}
+	return 0
 }
 
 atf_test_case var_assign
@@ -1059,6 +1106,173 @@ var_assign_body()
 		'set -u; unset x; echo $(( x + 3 )); echo $x'
 	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
 		'set -u; unset x; echo $(( x+=3 )); echo $x'
+
+	${TEST_SH} -c ': $(( 1 , 2 , 3 ))' 2>/dev/null  && {
+		atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+			'echo $((x=2 , x|=1)); echo $x'
+		atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+			'set -u; echo $((x = 2   ,x |= 1)); echo $x'
+		atf_check -s exit:0 -o inline:'6\n1:2:3:6\n' -e empty \
+			${TEST_SH} -c \
+		'echo $((a=1 , b=2 , c = 3 , x=a+b + c)); echo $a:$b:$c:$x'
+		atf_check -s exit:0 -o inline:'6\n1:2:3:6\n' -e empty \
+			${TEST_SH} -c \
+		'set -u;echo $((a=1 ,b=2 ,c=3 ,x=a+b+c)); echo $a:$b:$c:$x'
+	}
+	return 0
+}
+
+atf_test_case var_postinc
+var_postinc_head()
+{
+	atf_set "descr" "Test suffix ++ operator"
+}
+var_postinc_body()
+{
+	${TEST_SH} -c 'X=1; : $(( X++ ))' 2>/dev/null ||
+		atf_skip "${TEST_SH} does not support the suffix ++ operator"
+
+	unset X		; # just in case ...
+
+	atf_check -s exit:0 -o inline:'1\n2\n' -e empty ${TEST_SH} -c \
+		'X=1; echo $(( X++ )); echo $X'
+	atf_check -s exit:0 -o inline:'0\n1\n' -e empty ${TEST_SH} -c \
+		'echo $(( X++ )); echo $X'
+
+	atf_check -s exit:0 -o inline:'0\n1:0\n' -e empty ${TEST_SH} -c \
+		'unset Y; echo $(( Y = X++ )); echo $X:$Y'
+	atf_check -s exit:0 -o inline:'12\n4:5\n' -e empty ${TEST_SH} -c \
+		'X=3 Y=4; echo $(( Y++*X++ )); echo $X:$Y'
+
+	atf_check -s exit:0 -o inline:'1\n2\n' -e empty ${TEST_SH} -c \
+		'set -u; X=1; echo $(( X++ )); echo $X'
+	atf_check -s exit:0 -o inline:'0\n1:0\n' -e empty ${TEST_SH} -c \
+		'set -u; X=0; unset Y; echo $(( Y = X++ )); echo $X:$Y'
+	atf_check -s exit:0 -o inline:'12\n4:5\n' -e empty ${TEST_SH} -c \
+		'set -u; X=3 Y=4; echo $(( Y++*X++ )); echo $X:$Y'
+
+	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
+		'set -u; 

CVS commit: src/tests/bin/sh

2017-06-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jun 24 11:09:42 UTC 2017

Modified Files:
src/tests/bin/sh: t_syntax.sh

Log Message:
Give this test a promotion!   This was the test that enabled the sh's
STACKSTRNUL() bug to eventually be found.   Not any of the test cases
directly - the shell running the tests (the same /bin/sh) managed to
build one of the f_variable_syntax sub-tests incorrectly, and that was
enough to eventually allow the bug to be located and squashed.

Like all good promotions, this one comes with increased work, and no extra pay.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_syntax.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.4 src/tests/bin/sh/t_syntax.sh:1.5
--- src/tests/bin/sh/t_syntax.sh:1.4	Fri Jun 16 07:30:32 2017
+++ src/tests/bin/sh/t_syntax.sh	Sat Jun 24 11:09:42 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.4 2017/06/16 07:30:32 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.5 2017/06/24 11:09:42 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -364,7 +364,9 @@ f_variable_syntax_body() {
 	for vname in a ab _a _9 a123 a_1_2_3 __ ___  __1__ _0 \
 	A AA AAA AaBb _A_a A_a_ a1_ abc_123 ab_12_cd_ef_34_99 \
 	abcdefghijklmnopqrstuvwzyz ABCDEFGHIJKLMNOPQRSTUVWXYZ_ \
-	A_VERY_LONG_VARIABLE_NAME_that_is_probably_longer_than_most_used_in_the_average_shell_script_already_about_100_chars_in_this_one_but_there_is_not_supposed_to_be_any_limit_on_the_length_at_all xyzzy \
+	A_VERY_LONG_VARIABLE_NAME_that_is_probably_longer_than_most_used_in_the_average_shell_script_already_about_100_chars_in_this_one_but_there_is_not_supposed_to_be_any_limit_on_the_length_at_all \
+	Then_Make_it_Even_Longer_by_Multiplying_it___A_VERY_LONG_VARIABLE_NAME_that_is_probably_longer_than_most_used_in_the_average_shell_script_already_about_100_chars_in_this_one_but_there_is_not_supposed_to_be_any_limit_on_the_length_at_all__A_VERY_LONG_VARIABLE_NAME_that_is_probably_longer_than_most_used_in_the_average_shell_script_already_about_100_chars_in_this_one_but_there_is_not_supposed_to_be_any_limit_on_the_length_at_all__A_VERY_LONG_VARIABLE_NAME_that_is_probably_longer_than_most_used_in_the_average_shell_script_already_about_100_chars_in_this_one_but_there_is_not_supposed_to_be_any_limit_on_the_length_at_all__A_VERY_LONG_VARIABLE_NAME_that_is_probably_longer_than_most_used_in_the_average_shell_script_already_about_100_chars_in_this_one_but_there_is_not_supposed_to_be_any_limit_on_the_length_at_all \
+	xyzzy __0123454321__ _0_1_2_3_4_5_6_7_8_9_ ABBA X_ Y__ Z___ \
 	_
 	do
 		atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
@@ -383,6 +385,54 @@ f_variable_syntax_body() {
 			"${vname}=GOOD; unset ${vname}x; printf %s \$${vname}"
 		atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 			"unset ${vname}x; ${vname}=GOOD; printf %s \$${vname}x"
+		atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
+			"${vname}=GOOD; ${vname}_=BAD; printf %s \$${vname}"
+
+		case "${vname}" in
+		?)	continue;;
+		esac
+
+		# The following tests do not work for 1 char var names.
+		# hence the check and "continue" above to skip the remaining
+		# tests for that case
+
+		atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
+			"${vname}=GOOD; unset ${vname%?}; printf %s \$${vname}"
+
+		# (this next would work, but becomes just a duplicate of
+		# an earlier test, so is pointless for 1 ch names)
+		atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
+	"${vname}=GOOD; unset ${vname}x ${vname%?}; printf %s \$${vname}"
+
+		atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+			"unset ${vname%?};${vname}=GOOD; printf %s \$${vname%?}"
+
+		atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
+			"${vname}=GOOD; ${vname%?}=BAD; printf %s \$${vname}"
+
+		# all the remaining tests require the 2nd char of the
+		# variable name to be a legal first character.  That
+		# is, not a digit, so skip the rest if we have a digit
+		# second...
+		case "${vname}" in
+		?[0-9]*)	continue;;
+		esac
+
+		atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
+			"${vname}=GOOD; unset ${vname#?}; printf %s \$${vname}"
+		atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+			"unset ${vname#?};${vname}=GOOD; printf %s \$${vname#?}"
+
+		atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
+			"${vname}=GOOD; ${vname#?}=BAD; printf %s \$${vname}"
+
+		atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+			"unset ${vname%?} ${vname#?} ${vname}x; ${vname}=GOOD;
+			printf %s \$${vname%?}\$${vname#?}\$${vname}x"
+
+		atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
+			"${vname}=GOOD; ${vname%?}=BAD; ${vname}_=BAD;
+			${vname#?}=BAD; printf %s \$${vname}"
 	done
 
 

CVS commit: src/tests/bin/sh

2017-06-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jun 24 11:06:17 UTC 2017

Modified Files:
src/tests/bin/sh: t_fsplit.sh

Log Message:
NFC:   Added some comments (about other comments)

We currently parse var expansions like "${x-"a b c"}" incorrectly
according to POSIX (and ancient tradition) though in a way that is
generally unexpcted (there are 2 quoted strings there, according
to the standard, "${x-" and "}" and 'a b c' is unquoted.)  This has
never been fixed in our sh, as like in many other shells, it is just
a little unbelievable, most people expect that inside the {} is a
whole new ballpark, and everything starts again, and it does in cases
like "${x%"a b c"}" (the newer matching operators.)  There have been
comments in this test explaining how the test is actually testing for
incorrect behaviour for a while now.

But I have since learned of POSIX bug #221 (2010), the resolution of which is
to make the problem case unspecified.  This will not actually become part
of posix until the next major version (POSIX 8) whenever that appears (still
years away I expect) - but at least we now can feel happier about the
way our code works and not worry quite so much about testing that incorrect
code keeps working incorrectly


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/bin/sh/t_fsplit.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_fsplit.sh
diff -u src/tests/bin/sh/t_fsplit.sh:1.6 src/tests/bin/sh/t_fsplit.sh:1.7
--- src/tests/bin/sh/t_fsplit.sh:1.6	Sat Jun  3 15:15:49 2017
+++ src/tests/bin/sh/t_fsplit.sh	Sat Jun 24 11:06:17 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_fsplit.sh,v 1.6 2017/06/03 15:15:49 kre Exp $
+# $NetBSD: t_fsplit.sh,v 1.7 2017/06/24 11:06:17 kre Exp $
 #
 # Copyright (c) 2007-2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -145,6 +145,13 @@ default_val_body() {
 	# and not ksh93 (as of Mar 1, 2016, and still in June 2017)
 	# The likely correct interp of the next one is 'za bz zcz zdz'
 
+	# That and the "should be" below are correct as of POSIX 7 TC2
+	# But this is going to change to "unspecified" in POSIX 8
+	# (resolution of bug 221)  so instead of being incorrect (as now)
+	# the NetBSD shell will simply be implementing is version
+	# of unspecified behaviour.  Just beware that shells differ,
+	# a shell that fails this test is not incorrect because of it.
+
 	# should be: qq uuu q uuu   (unquoted/quoted) no nesting.
 	check 'for i in ${x-"a ${x-"b c"}" d}; do echo "z${i}z"; done' \
 		'za b cz zdz'
@@ -212,6 +219,8 @@ replacement_val_body() {
 	check 'x=BOGUS; for i in ${x+"a ${x+b c}" d};   do echo "z${i}z"; done'\
 		'za b cz zdz'
 
+	# see the (extended) comment in the default_val test.  This will be
+	# unspecified, hence we are OK (will be) but expect differences.
 	# also incorrect: qq uuu q uuu
 	check 'x=BOGUS; for i in ${x+"a ${x+"b c"}" d}; do echo "z${i}z"; done'\
 		'za b cz zdz'
@@ -241,6 +250,7 @@ ifs_alpha_body() {
 		'zaqbqcz zdz'
 
 	# this is another almost certainly incorrect expectation
+	# (but again, see comment in default_val test - becoming unspecified.)
 	#uu qq uuu q uu	(quoted/unquoted)
 	check 'IFS=q; for i in ${x-"aq${x-"bqc"}"qd}; do echo "z${i}z"; done' \
 		'zaqbqcz zdz'
@@ -262,6 +272,7 @@ quote_body() {
 	check 'set "${x-a b c}";   echo $#' 1
 
 	# this is another almost certainly incorrect expectation
+	# (but again, see comment in default_val test - becoming unspecified.)
 	#    uuu qqq  	(quoted/unquoted)  $1 is a $# is 2
 	check 'set "${x-"a b" c}"; echo $1' 'a b c'
 



CVS commit: src/tests/bin/sh

2017-06-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jun 16 07:37:41 UTC 2017

Modified Files:
src/tests/bin/sh: t_cmdsub.sh

Log Message:
Add a new test to verify correct operation when a command substitution
produces output with a very large number of consecutive embegged \n
characters.

This test is currently expected to fail (as of commit date) but is not
marked as atf_expect_fail as the shell should be fixed to avoid the
problem quite soon.   Until then almost anything might happen to the
sh that runs this test (from just plain wrong results, to core dumps,
even possibly the right results, though that's unlikely).

Whie doing this, get rid of the duplicate implementation of the
nested_cmdsubs_in_heredoc test (which was achieving nothing).  I know
how I managed to do that, but on advice of counsel, I ...   (it was
just a harmless waste of a tiny amount of CPU time "compiling" the test,
just like writing "x=0;" on consecutive lines)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_cmdsub.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_cmdsub.sh
diff -u src/tests/bin/sh/t_cmdsub.sh:1.4 src/tests/bin/sh/t_cmdsub.sh:1.5
--- src/tests/bin/sh/t_cmdsub.sh:1.4	Mon Apr  4 12:40:13 2016
+++ src/tests/bin/sh/t_cmdsub.sh	Fri Jun 16 07:37:41 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_cmdsub.sh,v 1.4 2016/04/04 12:40:13 christos Exp $
+# $NetBSD: t_cmdsub.sh,v 1.5 2017/06/16 07:37:41 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -678,31 +678,31 @@ x_heredoc_outside_backticks_body() {
 			'
 }
 
-atf_test_case t_nested_cmdsubs_in_heredoc
-t_nested_cmdsubs_in_heredoc_head() {
-	atf_set "descr" "Checks nested command substitutions in here docs"
-}
-t_nested_cmdsubs_in_heredoc_body() {
-	atf_require_prog cat
-	atf_require_prog rm
-
-	rm -f * 2>/dev/null || :
-	echo "Hello" > File
-
-	atf_check -s exit:0 -o inline:'Hello U\nHelp me!\n' -e empty \
-	${TEST_SH} -c 'cat <<- EOF
-		$(cat File) U
-		$( V=$(cat File); echo "${V%lo}p" ) me!
-		EOF'
-
-	rm -f * 2>/dev/null || :
-	echo V>V ; echo A>A; echo R>R
-	echo Value>VAR
-
-	atf_check -s exit:0 -o inline:'$2.50\n' -e empty \
-	${TEST_SH} -c 'cat <<- EOF
-	$(Value='\''$2.50'\'';eval echo $(eval $(cat V)$(cat A)$(cat R)=\'\''\$$(cat $(cat V)$(cat A)$(cat R))\'\''; eval echo \$$(set -- *;echo ${3}${1}${2})))
-		EOF'
+atf_test_case y_many_embedded_nl
+y_many_embedded_nl_head() {
+	atf_set "descr" "Checks command substitutions that return many lines"
+}
+y_many_embedded_nl_body() {
+	atf_require_prog wc
+	atf_require_prog seq
+
+	# first make sure it should work
+	atf_check -s exit:0 -o match:'1002' -e empty \
+	${TEST_SH} -c "{ printf '%s\n' x
+		for a in \$( seq 1000 ); do printf '\n'; done
+		printf '%s\n' y; } | wc -l"
+
+	# then use a cmd-sub to get the same thing
+	atf_check -s exit:0 -o match:'1002' -e empty \
+	${TEST_SH} -c "printf '%s\n' \"\$( printf '%s\n' x
+		for a in \$( seq 1000 ); do printf '\n'; done
+		printf '%s\n' y )\" | wc -l"
+
+	# and a much bigger one.
+	atf_check -s exit:0 -o match:'10002' -e empty \
+	${TEST_SH} -c "printf '%s\n' \"\$( printf '%s\n' x
+		for a in \$( seq 1 ); do printf '\n'; done
+		printf '%s\n' y )\" | wc -l"
 }
 
 atf_test_case z_absurd_heredoc_cmdsub_combos
@@ -779,5 +779,6 @@ atf_init_test_cases() {
 	atf_add_test_case v_cmdsub_paren_tests
 	atf_add_test_case w_heredoc_outside_cmdsub
 	atf_add_test_case x_heredoc_outside_backticks
+	atf_add_test_case y_many_embedded_nl
 	atf_add_test_case z_absurd_heredoc_cmdsub_combos
 }



CVS commit: src/tests/bin/sh

2017-06-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jun 16 07:30:32 UTC 2017

Modified Files:
src/tests/bin/sh: t_syntax.sh

Log Message:
Fix a really stupid typo/thinko that was preventing many of the
redirect syntax sub-tests from being attempted.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_syntax.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.3 src/tests/bin/sh/t_syntax.sh:1.4
--- src/tests/bin/sh/t_syntax.sh:1.3	Fri Jun  9 23:49:58 2017
+++ src/tests/bin/sh/t_syntax.sh	Fri Jun 16 07:30:32 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.3 2017/06/09 23:49:58 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.4 2017/06/16 07:30:32 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -316,40 +316,40 @@ d_redirects_body() {
 	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'>/dev/null>/dev/null>/dev/null'
 
-	atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'echo hello >/dev/null'
-	atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'echo >/dev/null hello'
-	atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'>/dev/null echo hello'
-	atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'echo hello >/dev/null world'
-	atf-check -s exit:0 -o 'inline:hello world\n' -e empty ${TEST_SH} -c \
+	atf_check -s exit:0 -o 'inline:hello world\n' -e empty ${TEST_SH} -c \
 		'echo hello &1'
-	atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'2>& 1'
-	atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'FD=1; 2>&"${FD}"'
-	atf-check -s exit:0 -o 'inline:hello\n' -e empty ${TEST_SH} -c \
+	atf_check -s exit:0 -o 'inline:hello\n' -e empty ${TEST_SH} -c \
 		'FD=1; echo hello 2>&"${FD}" >&2'
 
-	atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'2>&- 3<&- 4>&-'
 
 	return 0



CVS commit: src/tests/bin/sh

2017-06-09 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jun  9 23:49:58 UTC 2017

Modified Files:
src/tests/bin/sh: t_syntax.sh

Log Message:
Add two new sub-tests to the c_line_wrapping test case.

These should detect if the errors that caused MAKDEV to fail and
pkgsrc/pkgtools/cwrappers to fail to build (problem detected in
libnbcompat/configure) ever return.

Also fixed one of the other sub-tests so that it actually does what
it should - no idea how this one has been passing, it did not for me
when I was checking the new ones (but perhaps in the interim I have
fixed something else in sh, the problem was in the area I have been
playing, and I originally debugged the new tests using a newer version
of /bin/sh than has yet been committed.)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_syntax.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.2 src/tests/bin/sh/t_syntax.sh:1.3
--- src/tests/bin/sh/t_syntax.sh:1.2	Fri Jun  2 01:45:06 2017
+++ src/tests/bin/sh/t_syntax.sh	Fri Jun  9 23:49:58 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.2 2017/06/02 01:45:06 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.3 2017/06/09 23:49:58 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -208,12 +208,13 @@ c_line_wrapping_body() {
 		${V\
 		AR}\
 		}\
-		}}
+		}"}
 		printf '%s' ${V\
 		1?V1\
 		 \
 		FAIL}
 	DONE
+
 	cat <<- 'DONE' | atf_check -s exit:0 -o inline:'2\n' ${TEST_SH}
 		l\
 		s=7 bi\
@@ -224,6 +225,74 @@ c_line_wrapping_body() {
 		( ls /bin )\
 		)
 	DONE
+
+	# Inspired by src/etc/MAKEDEV.tmpl failure with (broken)
+	# sh LINENO code...  avoid it happening again...
+	for VARS in 1:0:0:0 0:1:0:0 0:0:1:0 0:0:0:1 \
+		1:0:0:1 1:0:1:0 1:1:0:0 0:1:1:0 \
+		0:0:0:0 1:1:0:1 0:1:1:1 1:1:1:1
+	do
+		eval $(
+			IFS=:
+			set -- $VARS
+			test $(( $1 + $2 + $3 + $4 )) -eq 1 &&
+R=OK || R=BAD
+			printf "R=%s;" $R
+			for v in a b c d
+			do
+case $1 in
+(0)	printf "export %s=false;" $v;;
+(1)	printf "export %s=true;"  $v;;
+esac
+shift
+			done
+		)
+
+		cat <<- 'DONE' | atf_check -s exit:0 -o inline:"${R}" ${TEST_SH}
+			case $(( $($a && echo 1 || echo 0) + \
+ $($b && echo 1 || echo 0) + \
+ $($c && echo 1 || echo 0) + \
+ $($d && echo 1 || echo 0) ))
+			in
+			(1)	printf OK ;;
+			(*)	printf BAD ;;
+			esac
+		DONE
+	done
+
+	# inspired by pkgsrc/pkgtools/cwrappers :: libnbcompat/configure
+	# failure with (broken) sh LINENO core .. avoid recurrence
+	# This test would have failed.
+	cat <<- 'DONE' | atf_check -s exit:0 -o inline:'/tmp\n' ${TEST_SH}
+		dn=/tmp/foo
+
+		D=`dirname -- "${dn}" ||
+		expr	X"${dn}" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+			X"${dn}" : 'X\(//\)[^/]' \| \
+			X"${dn}" : 'X\(//\)$' \| \
+			X"${dn}" : 'X\(/\)' \| . 2>/dev/null ||
+		echo X"${dn}" |
+		sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+			s//\1/
+			q
+			  }
+			  /^X\(\/\/\)[^/].*/{
+			s//\1/
+			q
+			  }
+			  /^X\(\/\/\)$/{ 
+			s//\1/
+			q
+			  } 
+			  /^X\(\/\).*/{
+			s//\1/
+			q
+			  }
+			  s/.*/./; q'`
+
+		echo "${D}"
+	DONE
+	return 0
 }
 
 atf_test_case d_redirects



CVS commit: src/tests/bin/sh

2017-06-03 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jun  3 15:15:49 UTC 2017

Modified Files:
src/tests/bin/sh: t_fsplit.sh

Log Message:
Paranoia:   add a new test case testing that $(( )) results get split
by IFS just the same as any other expansion (split when they should be,
and not when they shouldn't).

Good thing I did ... this discovered a regression in the new expand
code (from an hour or three ago) where quoted arith expansions are
being split, and shouldn't be.  (on the other hand, when they should
be split, they are being split correctly, so that's good...)

No need to worry too much about this, in real life (as opposed to
torture tests) no-one ever puts digits in IFS, and a $(( )) expansion
only ever contains digits, so in practice, splitting never happens,
whether because it is quoted, or just becaue there is nothing to split.

The FreeBSD shell does it correctly (they do word splitting using a
totally different mechanism than we do) - I will find where I missed
testing for quoted expansions later tonight.  Until that happens,
expect a test failure from t_fsplit:split_arith

While here add more comments in the other test casess (one had a comment
already) that our shell parses incorrectly (this is a parsing problem,
not an expansion problem, and the bug has existed forever .. and is
shared by bash).

That is, in an expression like "${var:-word}" the whole thing (including
word) is quoted by the double quotes, and in "${var:-"word"}" the
expansion is quoted, but 'word' is not, the 2nd " (the one before 'w')
ends the opening quote, and the third (before }) turns quoting on
again (it is required that there be an even number of unquoted quotes inside
a ${} expression, so things like "${var:-"word} are simply invalid.)
Another way of saying this, is that if the { is quoted (for which the
only way is using " to get to this kind of expansion at all) the }
must also be quoted (" quoted).  There is no quote nesting here.

This also means that in "${var:-'word'}" the single quotes are just
characters, they are quoted by the "" that surround them, just as in
"a 'string' containing quotes", but "${var:-"'word'"}} is valid and
contains a single quoted word.

Note that this is different than the patetrn-match/trim expansions
( ${var%pattern} etc) where any surrounding quotes do not affect the
pattern, and all forms of quoting can be used in it - but it always
parses as a pattern, and is never subject to filename expansion, so
a '*' in it that is to mean "match any string" does not need special
quoting to avoid it expanding to file names, regardless of whether
the ${var%*} is quoted or not, but a * that is to be matched as a
character literally does need to be quoted.

I will probably file a PR about this bug sometime, but as it is
very old, and doesn't every seem to bother anyone (and is shared by
bash) there isn't any big hurry to open yet another verry messy can
of excrement to fix it...

This does mean that the FreeBSD shell "fails" some of our tests.
(The test is wrong, their shell is correct.)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_fsplit.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_fsplit.sh
diff -u src/tests/bin/sh/t_fsplit.sh:1.5 src/tests/bin/sh/t_fsplit.sh:1.6
--- src/tests/bin/sh/t_fsplit.sh:1.5	Sat Jun  3 10:27:05 2017
+++ src/tests/bin/sh/t_fsplit.sh	Sat Jun  3 15:15:49 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_fsplit.sh,v 1.5 2017/06/03 10:27:05 kre Exp $
+# $NetBSD: t_fsplit.sh,v 1.6 2017/06/03 15:15:49 kre Exp $
 #
 # Copyright (c) 2007-2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -33,7 +33,7 @@
 # the "${x-" and "}" were absent from the input line.
 #
 # So: sh -c 'set ${x-a b c}; echo $#' should give 3.
-# and: sh -c 'set -- ${x-}' echo $#' shold give 0
+# and: sh -c 'set -- ${x-}' echo $#' should give 0
 #
 
 # the implementation of "sh" to test
@@ -79,6 +79,8 @@ check()
 	then
 		  atf_fail "TEST ${TEST} '$1' failed ($STATUS)"
 	fi
+
+	return 0
 }
 
 atf_test_case for
@@ -209,8 +211,11 @@ replacement_val_body() {
 		'za bz zcz'
 	check 'x=BOGUS; for i in ${x+"a ${x+b c}" d};   do echo "z${i}z"; done'\
 		'za b cz zdz'
+
+	# also incorrect: qq uuu q uuu
 	check 'x=BOGUS; for i in ${x+"a ${x+"b c"}" d}; do echo "z${i}z"; done'\
 		'za b cz zdz'
+
 	check 'x=BOGUS; for i in ${x+a ${x+"b c"} d};   do echo "z${i}z"; done'\
 		'zaz zb cz zdz'
 	check 'x=BOGUS; for i in ${x+a ${x+b c} d}; do echo "z${i}z"; done'\
@@ -234,8 +239,12 @@ ifs_alpha_body() {
 		'zaqbz zcz'
 	check 'IFS=q; for i in ${x-"aq${x-bqc}"qd};   do echo "z${i}z"; done' \
 		'zaqbqcz zdz'
+
+	# this is another almost certainly incorrect expectation
+	#uu qq uuu q uu	(quoted/unquoted)
 	check 'IFS=q; for i in ${x-"aq${x-"bqc"}"qd}; do echo "z${i}z"; done' \
 		'zaqbqcz zdz'
+
 	check 'IFS=q; for i in 

CVS commit: src/tests/bin/sh

2017-06-03 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jun  3 14:45:59 UTC 2017

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
Complete the special request by quoting chapter & verse from POSIX
as to why ${011} is ${11} and not ${9} (that is, why we interpret it
that way, the "why could it not be the other way?" is just "because
that is not how it was ever implemented".


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.16 src/tests/bin/sh/t_expand.sh:1.17
--- src/tests/bin/sh/t_expand.sh:1.16	Sat Jun  3 11:23:01 2017
+++ src/tests/bin/sh/t_expand.sh	Sat Jun  3 14:45:59 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.16 2017/06/03 11:23:01 kre Exp $
+# $NetBSD: t_expand.sh,v 1.17 2017/06/03 14:45:59 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -424,6 +424,11 @@ shell_params_body() {
 			'0=a 1=b 2=c' 0
 
 	# by special request, for PaulG...  (${0...} is not octal!)
+
+	# Posix XCU 2.5.1 (Issue 7 TC2 pg 2349 lines 74835..6):
+	#   The digits denoting the positional parameters shall always
+	#   be interpreted as a decimal value, even if there is a leading zero.
+
 	check \
 	'set -- a b c d e f g h i j k l m; echo "$#: ${08} ${010} ${011}"' \
 		'13: h j k' 0



CVS commit: src/tests/bin/sh

2017-06-03 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jun  3 11:23:01 UTC 2017

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
By special request, add a check that ${011} is ${11} not ${9} (etc) and
that ${08} is not an error.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.15 src/tests/bin/sh/t_expand.sh:1.16
--- src/tests/bin/sh/t_expand.sh:1.15	Fri Jun  2 01:48:13 2017
+++ src/tests/bin/sh/t_expand.sh	Sat Jun  3 11:23:01 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.15 2017/06/02 01:48:13 kre Exp $
+# $NetBSD: t_expand.sh,v 1.16 2017/06/03 11:23:01 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -423,6 +423,11 @@ shell_params_body() {
 	check "${TEST_SH} -c 'echo 0=\${00} 1=\${01} 2=\${02}' a b c" \
 			'0=a 1=b 2=c' 0
 
+	# by special request, for PaulG...  (${0...} is not octal!)
+	check \
+	'set -- a b c d e f g h i j k l m; echo "$#: ${08} ${010} ${011}"' \
+		'13: h j k' 0
+
 	results
 }
 



CVS commit: src/tests/bin/sh

2017-06-03 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jun  3 10:27:05 UTC 2017

Modified Files:
src/tests/bin/sh: t_fsplit.sh

Log Message:
Add some extra sub-tests checking splitting of ${#var} - just for my
piece of mind (to verify I was not breaking anything here.)

Also added some commentary better explaining why one of the tests of splitting
quoted variable expansions is almost certainly incorrect (both the tests,
and what sh does) ... though bash does the same as us, so all is not lost!


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_fsplit.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_fsplit.sh
diff -u src/tests/bin/sh/t_fsplit.sh:1.4 src/tests/bin/sh/t_fsplit.sh:1.5
--- src/tests/bin/sh/t_fsplit.sh:1.4	Sun Mar 27 14:50:01 2016
+++ src/tests/bin/sh/t_fsplit.sh	Sat Jun  3 10:27:05 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_fsplit.sh,v 1.4 2016/03/27 14:50:01 christos Exp $
+# $NetBSD: t_fsplit.sh,v 1.5 2017/06/03 10:27:05 kre Exp $
 #
 # Copyright (c) 2007-2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -137,11 +137,13 @@ default_val_body() {
 	check 'for i in ${x-a ${x-b c} d}; do echo "z${i}z"; done' \
 		'zaz zbz zcz zdz'
 
-	# I am not sure these two are correct, the rules on quoting word
-	# in ${var-word} are peculiar, and hard to fathom...
-	# They are what the NetBSD shell does, and bash, not the freebsd shell
-	# (as of Mar 1, 2016)
+	# I am not sure the first of these two is correct, the rules on
+	# quoting word in ${var-word} are peculiar, and hard to fathom...
+	# It is what the NetBSD shell does, and bash, not the freebsd shell
+	# and not ksh93 (as of Mar 1, 2016, and still in June 2017)
+	# The likely correct interp of the next one is 'za bz zcz zdz'
 
+	# should be: qq uuu q uuu   (unquoted/quoted) no nesting.
 	check 'for i in ${x-"a ${x-"b c"}" d}; do echo "z${i}z"; done' \
 		'za b cz zdz'
 	check 'for i in ${x-a ${x-"b c"} d};   do echo "z${i}z"; done' \
@@ -337,6 +339,7 @@ var_length_body() {
 	long=12345678123456781234567812345678
 	long=$long$long$long$long
 	export long
+	unset x
 
 	# first test that the test method works...
 	check 'set -u; : ${long}; echo ${#long}' '128'
@@ -344,8 +347,13 @@ var_length_body() {
 	# Check that we apply IFS to ${#var}
 	check 'echo ${#long}; IFS=2; echo ${#long}; set 1 ${#long};echo $#' \
 		'128 1 8 3'
-	check 'IFS=2; set ${x-${#long}};   IFS=" "; echo $* $#'   '1 8 2'
-	check 'IFS=2; set ${x-"${#long}"}; IFS=" "; echo $* $#'   '128 1'
+	check 'IFS=2; set ${x-${#long}};   IFS=" "; echo $* $#' '1 8 2'
+	check 'IFS=2; set ${x-"${#long}"}; IFS=" "; echo $* $#' '128 1'
+	check 'IFS=2; set "${x-${#long}}"; IFS=" "; echo $* $#' '128 1'
+	check 'IFS=2; set ${x-${#long}};   :  ; echo $* $#' '1 8 '
+	check 'IFS=2; set ${x-${#long}};   :  ; echo $* "$#"'   '1 8 2'
+	check 'IFS=2; set ${x-${#long}};   :  ; echo "$*" "$#"' '128 2'
+	check 'IFS=2; set ${x-${#long}};   :  ; echo "$@" "$#"' '1 8 2'
 }
 
 atf_init_test_cases() {



CVS commit: src/tests/bin/sh

2017-06-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jun  2 01:50:48 UTC 2017

Modified Files:
src/tests/bin/sh: t_arith.sh

Log Message:
Add a new test case "nested_arith" (that is, things like $(( 1 + $(( 2 )) ))
which will currently fail (some of the sub-tests, but this one stops on
first failure, so the test simply fails.)  This will be corrected later today.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/bin/sh/t_arith.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_arith.sh
diff -u src/tests/bin/sh/t_arith.sh:1.6 src/tests/bin/sh/t_arith.sh:1.7
--- src/tests/bin/sh/t_arith.sh:1.6	Mon Mar 20 11:32:51 2017
+++ src/tests/bin/sh/t_arith.sh	Fri Jun  2 01:50:48 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_arith.sh,v 1.6 2017/03/20 11:32:51 kre Exp $
+# $NetBSD: t_arith.sh,v 1.7 2017/06/02 01:50:48 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -818,6 +818,30 @@ logical_or_body()
 		'echo $(( 0x33 || 0xF0F0 ))'
 }
 
+atf_test_case nested_arith
+nested_arith_head()
+{
+	atf_set "descr" 'Test nested arithmetic $(( $(( )) ))'
+}
+nested_arith_body()
+{
+	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+		'echo $(( $(( 0 )) ))'
+	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+		'echo $(( 1 + $(( 2 - 2 )) ))'
+	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+		'echo $(( $(( 3 / 3 )) + $((1*1*1)) - $(( 7 % 6 '
+	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+		'echo $(($(($(($(($((1))'
+
+	atf_check -s exit:0 -o inline:'246\n' -e empty ${TEST_SH} -c \
+		'echo $(( 2$((2 * 2))6 ))'
+	atf_check -s exit:0 -o inline:'291117\n' -e empty ${TEST_SH} -c \
+		'echo $(( $((1 + 1))$((3 * 3))$(( 99-88 ))$(( 17'
+	atf_check -s exit:0 -o inline:'123456789\n' -e empty ${TEST_SH} -c \
+	  'echo $(( 1$((2$((1+2))4$((2 + 2 + 1))6))7$((4 * 2))$(($((81/9))'
+}
+
 atf_test_case make_selection
 make_selection_head()
 {
@@ -1082,6 +1106,7 @@ atf_init_test_cases() {
 	atf_add_test_case logical_and
 	atf_add_test_case logical_or
 	atf_add_test_case make_selection
+	atf_add_test_case nested_arith
 	atf_add_test_case operator_precedence
 	atf_add_test_case parentheses
 	# atf_add_test_case progressive			# build up big expr



CVS commit: src/tests/bin/sh

2017-06-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jun  2 01:48:13 UTC 2017

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
Add 3 new subtests to the shell_params test case.   These test currently
broken behaviour (so for now, 3 of 15 subtests will fail).   This will
be corrected later today.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.14 src/tests/bin/sh/t_expand.sh:1.15
--- src/tests/bin/sh/t_expand.sh:1.14	Mon May 29 22:27:47 2017
+++ src/tests/bin/sh/t_expand.sh	Fri Jun  2 01:48:13 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.14 2017/05/29 22:27:47 kre Exp $
+# $NetBSD: t_expand.sh,v 1.15 2017/06/02 01:48:13 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -418,6 +418,11 @@ shell_params_body() {
 	   'abab?cbb:bab?cbb+abab?cb-b?cbb_a%bab?cbb=abab?cb/abab' 0
 	check 'set -- a "" c "" e; echo "${2:=b}"' '' 1
 
+	check 'set -- a b c d; echo ${4294967297}' '' 0  # result 'a' => ${1}
+	check 'set -- a b c; echo ${01}' 'a' 0
+	check "${TEST_SH} -c 'echo 0=\${00} 1=\${01} 2=\${02}' a b c" \
+			'0=a 1=b 2=c' 0
+
 	results
 }
 



CVS commit: src/tests/bin/sh

2017-06-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jun  2 01:45:06 UTC 2017

Modified Files:
src/tests/bin/sh: t_syntax.sh

Log Message:
One more weird test of parsing (and correctly understanding) words
whose meaning is defined entirely by context.

For those who read commit messages, and want a (small) challenge,
work out where (and what) to insert as punctuation/operator chars
in the following to produce 3 ines of output, and what those will be:

for in in in do in do case in in in echo do do echo in esac done

(There are no comments, quotes of any kind, or any kind of sub-shell,
including cmd substitutions)  With correct non alpha-numeric chars added,
it works.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_syntax.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.1 src/tests/bin/sh/t_syntax.sh:1.2
--- src/tests/bin/sh/t_syntax.sh:1.1	Sat May 20 16:35:55 2017
+++ src/tests/bin/sh/t_syntax.sh	Fri Jun  2 01:45:06 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.1 2017/05/20 16:35:55 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.2 2017/06/02 01:45:06 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -632,6 +632,8 @@ q_for_loop_body() {
 		'for for in do;do : ;done'
 	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'for in in in;do : ; done'
+	atf_check -s exit:0 -o 'inline:do\nin\ndo\n' -e empty ${TEST_SH} -c \
+   'for in in in do in;do case $in in in)echo do;;do)echo in;;esac; done'
 	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
 		'for in in for;do : ; done'
 	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \



CVS commit: src/tests/bin/sh

2017-06-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jun  2 01:38:45 UTC 2017

Modified Files:
src/tests/bin/sh: t_option.sh

Log Message:
Guard against EVN being set, and possibly referencing an unset
variable, when we are running tests with sh -u


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_option.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_option.sh
diff -u src/tests/bin/sh/t_option.sh:1.3 src/tests/bin/sh/t_option.sh:1.4
--- src/tests/bin/sh/t_option.sh:1.3	Tue Mar  8 14:19:28 2016
+++ src/tests/bin/sh/t_option.sh	Fri Jun  2 01:38:44 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_option.sh,v 1.3 2016/03/08 14:19:28 christos Exp $
+# $NetBSD: t_option.sh,v 1.4 2017/06/02 01:38:44 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -356,6 +356,8 @@ set_u_head() {
 set_u_body() {
 	test_option_on_off u
 
+	unset ENV	# make sure there is nothing there to cause problems
+
 	# first make sure it is OK to unset an unset variable
 	atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -ce \
 		'unset _UNSET_VARIABLE_; echo OK'



CVS commit: src/tests/bin/sh

2017-05-29 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon May 29 22:27:47 UTC 2017

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
Add a new test case wrap_strip based upon strip (ie: cut to start)
but with \ newline line continuations inserted at strange places.

For the shell as it is today, since strip passes, wrap_strip should
automaticallty pass as well (and does), as the \ newline combination
is simply removed, producing identical input to that of strip.

However, for accurate line counting ($LINENO: coming soon) newlines (no
matter the context) cannot simply "go away" - we have to know where they
occur(ed) (perhaps long after the text was read)  so we know what line
number we are actually processing.   This new test case is (perhaps just
part) of future-proofing that the modified code does not break anything.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.13 src/tests/bin/sh/t_expand.sh:1.14
--- src/tests/bin/sh/t_expand.sh:1.13	Mon May 15 19:53:40 2017
+++ src/tests/bin/sh/t_expand.sh	Mon May 29 22:27:47 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.13 2017/05/15 19:53:40 kre Exp $
+# $NetBSD: t_expand.sh,v 1.14 2017/05/29 22:27:47 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -156,6 +156,50 @@ strip_body() {
 	done
 }
 
+atf_test_case wrap_strip
+wrap_strip_head() {
+	atf_set "descr" "Checks that the %% operator works and strips" \
+	"the contents of a variable from the given point" \
+			'to the end, and that \ \n sequences do not break it'
+}
+wrap_strip_body() {
+	line='#define bindir "/usr/bin" /* comment */'
+	stripped='#define bindir "/usr/bin" '
+
+	for exp in \
+		'${line\
+%%/\**}'	\
+		'${line%%"/\
+*"*}'		\
+		'${line%%'"'"'/*'"'"'\
+*}'		\
+		'"${li\
+ne%%/\**}"'	\
+		'"${line%%"\
+/*"*}"'		\
+		'"${line%\
+%'"'"'/*'"'"'*}"'\
+		'${line\
+%\
+/\*\
+*\
+}'		\
+		'${line%"/*\
+"*\
+}'		\
+		'${line\
+%\
+'"'"'/*'"'"'*}'	\
+		'"$\
+{li\
+ne%\
+'"'"'/*'"'"'*}"'
+	do
+		atf_check -o inline:":$stripped:\n" -e empty ${TEST_SH} -c \
+			"line='${line}'; echo :${exp}:"
+	done
+}
+
 atf_test_case varpattern_backslashes
 varpattern_backslashes_head() {
 	atf_set "descr" "Tests that protecting wildcards with backslashes" \
@@ -896,6 +940,7 @@ atf_init_test_cases() {
 	atf_add_test_case iteration_on_null_or_missing_parameter
 	atf_add_test_case shell_params
 	atf_add_test_case strip
+	atf_add_test_case wrap_strip
 	atf_add_test_case var_with_embedded_cmdsub
 	atf_add_test_case varpattern_backslashes
 }



CVS commit: src/tests/bin/sh

2017-05-27 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat May 27 13:11:50 UTC 2017

Modified Files:
src/tests/bin/sh: t_redircloexec.sh

Log Message:
Skip the test of non-posix behaviour if we are deliberately trying
to be posix compatible (POSIXLY_CORRECT is set).


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_redircloexec.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redircloexec.sh
diff -u src/tests/bin/sh/t_redircloexec.sh:1.4 src/tests/bin/sh/t_redircloexec.sh:1.5
--- src/tests/bin/sh/t_redircloexec.sh:1.4	Sun May 14 17:28:46 2017
+++ src/tests/bin/sh/t_redircloexec.sh	Sat May 27 13:11:50 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_redircloexec.sh,v 1.4 2017/05/14 17:28:46 kre Exp $
+# $NetBSD: t_redircloexec.sh,v 1.5 2017/05/27 13:11:50 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -50,6 +50,8 @@ exec_redir_closed_head() {
 }
 exec_redir_closed_body() {
 
+	[ -n "${POSIXLY_CORRECT+set}" ] && atf_skip "tests non-posix behaviour"
+
 	mkhelper exec 6 \
 		"exec 6> out; echo exec1 >&6; ${TEST_SH} exec2; exec 6>&-"
 



CVS commit: src/tests/bin/sh

2017-05-15 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon May 15 19:53:40 UTC 2017

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
More test sub-cases for the dollar_hash ( ${#...} ) test.
Upi really (really!) don't want to know!

Also, add a comment (in another section) and avoid giving messages
to atf_fail that include newlines - AFT really doesn't like that.
Instead, convert the \n's to ;'s so at least the content is retained.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.12 src/tests/bin/sh/t_expand.sh:1.13
--- src/tests/bin/sh/t_expand.sh:1.12	Sun May 14 11:28:49 2017
+++ src/tests/bin/sh/t_expand.sh	Mon May 15 19:53:40 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.12 2017/05/14 11:28:49 kre Exp $
+# $NetBSD: t_expand.sh,v 1.13 2017/05/15 19:53:40 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -259,6 +259,7 @@ check()
 
 		# don't actually fail just because of wrong exit code
 		# unless we either expected, or received "good"
+		# or something else is detected as incorrect as well.
 		case "$3/${STATUS}" in
 		(*/0|0/*) fail=true;;
 		esac
@@ -307,7 +308,10 @@ check()
 		TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
 		return 0
 	}
-	$fail && atf_fail "Test[$TEST_NUM] of '$1' failed${nl}${MSG}"
+	$fail && atf_fail "Test[$TEST_NUM] failed: $(
+	# ATF does not like newlines in messages, so change them...
+		printf '%s' "${MSG}" | tr '\n' ';'
+	)"
 	return 0
 }
 
@@ -441,6 +445,9 @@ dollar_hash_body() {
 #	need a test of its own, and used in that way, it really doesn't.
 #	But when we add braces ${#} we need to deal with the three
 #	(almost 4) different meanings of a # inside a ${} expansion...
+#
+#	Note that some of these are just how we treat expansions that
+#	are unspecified by posix (as noted below.)
 #	
 #		1.   ${#} is just $# (number of params)
 #		1.a	${\#} is nothing at all (error: invalid expansion)
@@ -450,18 +457,24 @@ dollar_hash_body() {
 #		3${VAR#pat} is the value of VAR with leading pat removed
 #		3.a	Including ${VAR#} which just removes leading nothing
 #			This is relevant in case of ${VAR#${X}} with X=''
+#nb: not required by posix, see XCU 2.6.2
 #		3.b	${##} is not a case of 3.a but rather 2.a 
 #		3.c	Yet ${##pat} is a case of 3.a
 #			Including ${##${X}} where X='' or X='#'
+#nb: not required by posix, see XCU 2.6.2
 #		3.d	And ${#\#} is invalid (error)
 #		3.e	But ${##\#} removes a leading # from the value of $#
 #			(so is just $# as there is no leading # there)
+#nb: not required by posix, see XCU 2.6.2
 #		4${VAR##pat} is the value of VAR with longest pat removed
 #		4.a	Including ${VAR##} which removes the longest nothing
 #		4.b	Which in this case includes ${###} (so is == $#)
+#nb: not required by posix, see XCU 2.6.2
 #		4.c	But not ${##\#} which is $# with a leading '#' removed
 #			(and so is also == $#), i.e.: like ${###} but different.
+#nb: not required by posix, see XCU 2.6.2
 #		4.d	As is ${###\#} or just ${} - remove  # (so just $#)
+#nb: not required by posix, see XCU 2.6.2
 #
 
 	reset dollar_hash
@@ -584,7 +597,53 @@ dollar_hash_body() {
 	check 'set -- a b c; echo ${#:=bogus}'		'3'		0  #85
 	check 'set -- a b c; echo ${#=bogus}'		'3'		0  #86
 
-	results
+	for n in 0 1 10 25 100#87 #88 #89 #90 #91
+	do
+		check "(exit $n)"'; echo ${#?}'		"${#n}"		0
+	done
+
+	results		# results so far anyway...
+
+# now we have some harder to verify cases, as they (must) check unknown values
+# and hence the resuls cannot just be built into the script, but we have
+# to use some tricks to validate them, so for these, just do regular testing
+# and don't attempt to use the check helper function, nor to include
+# these tests in the result summary.   If anything has already failed, we
+# do not get this far...   From here on, first failure ends this test.
+
+	for opts in '' '-a' '-au' '-auf' '-aufe' # options safe enough to set
+	do
+		# Note the shell might have other (or these) opts set already
+
+		RES=$(${TEST_SH} -c "test -n '${opts}' && set ${opts};
+			printf '%s' \"\$-\";printf ' %s\\n' \"\${#-}\"") ||
+			atf_fail '${#-} test exited with status '"$?"
+		LEN="${RES##* }"
+		DMINUS="${RES% ${LEN}}"
+		if [ "${#DMINUS}" != "${LEN}" ]
+		then
+			atf_fail \
+		   '${#-} test'" produced ${LEN} for opts ${DMINUS} (${RES})"
+		fi
+	done
+
+	for seq in a b c d e f g h i j
+	do
+		# now we are tryin to generate different pids for $$ and $!
+		# so we just run the test a number of times, and hope...
+		# On NetBSD pid randomisation will usually help the tests
+
+		eval "$(${TEST_SH} -c \
+		'(exit 0)& BG=$! LBG=${#!};
+	printf "SH=%s BG=%s LSH=%s LBG=%s" "$$" "$BG" "${#$}" "$LBG";
+		  wait')"
+

CVS commit: src/tests/bin/sh

2017-05-14 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun May 14 17:28:46 UTC 2017

Modified Files:
src/tests/bin/sh: t_redircloexec.sh

Log Message:
Add a test for opening files with exec "when" in posix mode (close-on-exec
should not get set.)  While here, remove the (unused) runhelper() function.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_redircloexec.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redircloexec.sh
diff -u src/tests/bin/sh/t_redircloexec.sh:1.3 src/tests/bin/sh/t_redircloexec.sh:1.4
--- src/tests/bin/sh/t_redircloexec.sh:1.3	Sun May 15 15:44:43 2016
+++ src/tests/bin/sh/t_redircloexec.sh	Sun May 14 17:28:46 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_redircloexec.sh,v 1.3 2016/05/15 15:44:43 kre Exp $
+# $NetBSD: t_redircloexec.sh,v 1.4 2017/05/14 17:28:46 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -39,10 +39,6 @@ mkhelper() {
 	echo "echo ${name}2" ">&${fd}" > ./"${name}2"
 }
 
-runhelper() {
-	${TEST_SH} "./${1}1"
-}
-
 cleanhelper() {
 	# not really needed, atf cleans up...
 	rm -f ./"${1}1" ./"${1}2" out
@@ -168,6 +164,77 @@ subshell_redir_open_body() {
 	cleanhelper comp
 }
 
+atf_test_case posix_exec_redir
+posix_exec_redir_head() {
+	atf_set "descr" "Tests that redirections created by exec" \
+		" in posix mode  are not closed on exec"
+}
+posix_exec_redir_body() {
+
+	# This test mostly just expects the opposite results than
+	# exec_redir_closed ...
+
+	# First work out how to get shell into posix mode
+	POSIX=
+
+	# This should succeed only if "set -o posix" succeeds.
+	# If it fails, whether it fails and exits the shell, or
+	# just returns a "false" from set (exit != 0), with or
+	# without errs on stderr, should not matter
+
+	if ${TEST_SH} -c "set -o posix && exit 0 || exit 1" 2>/dev/null
+	then
+		# If we have this method, use it, as we can expect
+		# this really should mean the shell is in posix mode.
+
+		POSIX='set -o posix;'
+
+	else
+		# This one is just a guess, and there is no assurance
+		# that it will do anything at all.  What's more, since
+		# we do not know what the shell being tested does
+		# differently in posix and non-posix modes, if it
+		# even has that concept, there's nothing we can test
+		# to find out.
+
+		# A shell that always operates in posix mode (at least
+		# with regard to redirects on exec and close-on-exec
+		# should pass this test, in any case.
+
+		POSIXLY_CORRECT=true ; export POSIXLY_CORRECT
+
+	fi
+
+	mkhelper exec 6 \
+	"${POSIX} exec 6> out; echo exec1 >&6; ${TEST_SH} exec2; exec 6>&-"
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} ./exec1
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -e ./exec1
+
+	mkhelper exec 9 \
+		"${POSIX} exec 9> out; echo exec1 >&9; ${TEST_SH} exec2"
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} ./exec1
+
+	mkhelper exec 8 \
+		"${POSIX}"\
+		"exec 8> out; printf OK; echo exec1 >&8;" \
+		"printf OK; ${TEST_SH} exec2; printf GOOD"
+
+	atf_check -s exit:0 -o match:OKOKGOOD -e empty \
+		${TEST_SH} -e ./exec1
+
+	mkhelper exec 7 \
+		"${POSIX}"\
+		"exec 7> out; printf OK; echo exec1 >&7;" \
+		"printf OK; ${TEST_SH} exec2 || printf ERR"
+
+	atf_check -s exit:0 -o match:OKOK -o not-match:ERR -e empty \
+		${TEST_SH} ./exec1
+
+	cleanhelper exec
+}
+
 atf_init_test_cases() {
 	atf_add_test_case exec_redir_closed
 	atf_add_test_case exec_redir_open
@@ -175,4 +242,5 @@ atf_init_test_cases() {
 	atf_add_test_case compound_redir_open
 	atf_add_test_case simple_redir_open
 	atf_add_test_case subshell_redir_open
+	atf_add_test_case posix_exec_redir
 }



CVS commit: src/tests/bin/sh

2017-05-14 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun May 14 11:28:49 UTC 2017

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
Add a test case for the various ways that ${xxx} expansions, which
contain a # character, can get parsed (which amounts to 86 extra checks,
any Australian can tell you why I decided to stop there and not add one
more...)


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.11 src/tests/bin/sh/t_expand.sh:1.12
--- src/tests/bin/sh/t_expand.sh:1.11	Mon Mar 20 11:48:41 2017
+++ src/tests/bin/sh/t_expand.sh	Sun May 14 11:28:49 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.11 2017/03/20 11:48:41 kre Exp $
+# $NetBSD: t_expand.sh,v 1.12 2017/05/14 11:28:49 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -430,13 +430,170 @@ var_with_embedded_cmdsub_body() {
 	results
 }
 
+atf_test_case dollar_hash
+dollar_hash_head() {
+	atf_set "descr" 'Test expansion of various aspects of $#'
+}
+dollar_hash_body() {
+
+#
+#	$# looks like it should be so simple that it doesn't really
+#	need a test of its own, and used in that way, it really doesn't.
+#	But when we add braces ${#} we need to deal with the three
+#	(almost 4) different meanings of a # inside a ${} expansion...
+#	
+#		1.   ${#} is just $# (number of params)
+#		1.a	${\#} is nothing at all (error: invalid expansion)
+#		1.b	${\#...} (anything after) is the same (invalid)
+#		2.   ${#VAR} is the length of the value VAR
+#		2.a	Including ${##} - the length of ${#}
+#		3${VAR#pat} is the value of VAR with leading pat removed
+#		3.a	Including ${VAR#} which just removes leading nothing
+#			This is relevant in case of ${VAR#${X}} with X=''
+#		3.b	${##} is not a case of 3.a but rather 2.a 
+#		3.c	Yet ${##pat} is a case of 3.a
+#			Including ${##${X}} where X='' or X='#'
+#		3.d	And ${#\#} is invalid (error)
+#		3.e	But ${##\#} removes a leading # from the value of $#
+#			(so is just $# as there is no leading # there)
+#		4${VAR##pat} is the value of VAR with longest pat removed
+#		4.a	Including ${VAR##} which removes the longest nothing
+#		4.b	Which in this case includes ${###} (so is == $#)
+#		4.c	But not ${##\#} which is $# with a leading '#' removed
+#			(and so is also == $#), i.e.: like ${###} but different.
+#		4.d	As is ${###\#} or just ${} - remove  # (so just $#)
+#
+
+	reset dollar_hash
+
+	check 'set -- ; echo $#'			'0'		0  # 1
+	check 'set -- a b c; echo $#'			'3'		0  # 2
+	check 'set -- a b c d e f g h i j; echo $#'	'10'		0  # 3
+# rule 1
+	check 'set -- ; echo ${#}'			'0'		0  # 4
+	check 'set -- a b c; echo ${#}'			'3'		0  # 5
+	check 'set -- a b c d e f g h i j; echo ${#}'	'10'		0  # 6
+# rule 1.a
+	check 'set -- a b c; echo ${\#}'		''		2  # 7
+# rule 1.b
+	check 'set -- a b c; echo ${\#:-foo}'		''		2  # 8
+# rule 2
+	check 'VAR=12345; echo ${#VAR}'			'5'		0  # 9
+	check 'VAR=123456789012; echo ${#VAR}'		'12'		0  #10
+# rule 2.a
+	check 'set -- ; echo ${##}'			'1'		0  #11
+	check 'set -- a b c; echo ${##}'		'1'		0  #12
+	check 'set -- a b c d e f g h i j; echo ${##}'	'2'		0  #13
+# rule 3
+	check 'VAR=12345; echo ${VAR#1}'		'2345'		0  #14
+	check 'VAR=12345; echo ${VAR#2}'		'12345'		0  #15
+	check 'VAR=#2345; echo ${VAR#\#}'		'2345'		0  #16
+	check 'X=1; VAR=12345; echo ${VAR#${X}}'	'2345'		0  #17
+	check 'X=1; VAR=#2345; echo ${VAR#${X}}'	'#2345'		0  #18
+# rule 3.a
+	check 'VAR=12345; echo ${VAR#}'			'12345'		0  #19
+	check 'X=; VAR=12345; echo ${VAR#${X}}'		'12345'		0  #20
+# rule 3.b (tested above, rule 2.a)
+# rule 3.c
+	check 'set -- ; echo ${##0}'			''		0  #21
+	check 'set -- a b c; echo ${##1}'		'3'		0  #22
+	check 'set -- a b c d e f g h i j; echo ${##1}'	'0'		0  #23
+	check 'X=0; set -- ; echo ${##${X}}'		''		0  #24
+	check 'X=; set -- ; echo ${##${X}}'		'0'		0  #25
+	check 'X=1; set -- a b c; echo ${##${X}}'	'3'		0  #26
+	check 'X=1; set -- a b c d e f g h i j; echo ${##${X}}'	'0'	0  #27
+	check 'X=; set -- a b c d e f g h i j; echo ${##${X}}'	'10'	0  #28
+	check 'X=#; VAR=#2345; echo ${VAR#${X}}'	'2345'		0  #29
+	check 'X=#; VAR=12345; echo ${VAR#${X}}'	'12345'		0  #30
+# rule 3.d
+	check 'set -- a b c; echo ${#\#}'		''		2  #31
+# rule 3.e
+	check 'set -- ; echo ${##\#}'			'0'		0  #32
+	check 'set -- a b c d e f g h i j; echo ${##\#}' '10'		0  #33
+
+# rule 4
+	check 'VAR=12345; echo ${VAR##1}'		'2345'		0  #34
+	check 'VAR=12345; echo ${VAR##\1}'		'2345'		0  #35
+# rule 4.a
+	check 'VAR=12345; echo ${VAR##}'		'12345'		0  #36
+# rule 4.b
+	check 'set -- ; echo ${###}'			'0'		0  #37
+	check 'set -- a b c d e f g h i j; echo ${###}'	'10'		0  #38
+# rule 4.c
+	check 'VAR=12345; echo ${VAR#\#}'		'12345'		0  #39
+	check 'VAR=12345; echo ${VAR#\#1}'		'12345'		0  #40
+	check 'VAR=#2345; 

CVS commit: src/tests/bin/sh

2017-03-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Mar 20 11:48:41 UTC 2017

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
PR bin/52090 - the $* tests are no longer expected to fail.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.10 src/tests/bin/sh/t_expand.sh:1.11
--- src/tests/bin/sh/t_expand.sh:1.10	Sun Mar 19 20:29:30 2017
+++ src/tests/bin/sh/t_expand.sh	Mon Mar 20 11:48:41 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.10 2017/03/19 20:29:30 kre Exp $
+# $NetBSD: t_expand.sh,v 1.11 2017/03/20 11:48:41 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -557,7 +557,7 @@ dollar_star_with_empty_ifs_body() {
 	check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
 			'1 ab c'	0  #14
 
-	results			'PR bin/52090 expect 7 of 14 subtests to fail'
+	results	  # FIXED: 'PR bin/52090 expect 7 of 14 subtests to fail'
 }
 
 atf_test_case dollar_star_in_word_empty_ifs
@@ -599,7 +599,7 @@ dollar_star_in_word_empty_ifs_body() {
 	check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
 '1 ab c'  0  #14
 
-	results		'PR bin/52090 expect 7 of 14 subtests to fail'
+	results	  # FIXED: 'PR bin/52090 expect 7 of 14 subtests to fail'
 }
 
 atf_test_case dollar_star_in_quoted_word
@@ -659,7 +659,7 @@ dollar_star_in_quoted_word_body() {
 	check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
 '1 ab c'  0  #26
 
-	results		 'PR bin/52090 - 2 of 26 subtests expected to fail'
+	results	  # FIXED: 'PR bin/52090 - 2 of 26 subtests expected to fail'
 }
 
 atf_init_test_cases() {



CVS commit: src/tests/bin/sh

2017-03-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Mar 20 11:32:51 UTC 2017

Modified Files:
src/tests/bin/sh: t_arith.sh

Log Message:
Add tests for the $(( )) assignment operators  PR bin/50958


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_arith.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_arith.sh
diff -u src/tests/bin/sh/t_arith.sh:1.5 src/tests/bin/sh/t_arith.sh:1.6
--- src/tests/bin/sh/t_arith.sh:1.5	Thu May 12 14:25:11 2016
+++ src/tests/bin/sh/t_arith.sh	Mon Mar 20 11:32:51 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_arith.sh,v 1.5 2016/05/12 14:25:11 kre Exp $
+# $NetBSD: t_arith.sh,v 1.6 2017/03/20 11:32:51 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -980,6 +980,63 @@ parentheses_body()
 		'echo $(( (0xfD & 0xF) == 0xF ))'
 }
 
+atf_test_case var_assign
+var_assign_head()
+{
+	atf_set "descr" "Test assignment operators in arithmetic expressions"
+}
+var_assign_body()
+{
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'unset x; echo $(( x = 3 )); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'unset x; echo $((x=3)); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'x=5; echo $((x=3)); echo $x'
+
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'set +u;unset x; echo $((x+=3)); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'x=2; echo $((x+=1)); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'x=4; echo $((x-=1)); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'x=3; echo $((x*=1)); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'x=3; echo $((x/=1)); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'x=28; echo $((x%=5)); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'x=7; echo $((x&=3)); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'x=2; echo $((x|=1)); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'x=6; echo $((x^=5)); echo $x'
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'x=7; echo $((x>>=1)); echo $x'
+	atf_check -s exit:0 -o inline:'2\n2\n' -e empty ${TEST_SH} -c \
+		'x=1; echo $((x<<=1)); echo $x'
+
+	atf_check -s exit:0 -o inline:'2\n3\n' -e empty ${TEST_SH} -c \
+		'x=2; echo $(( (x+=1)-1 )); echo $x'
+	atf_check -s exit:0 -o inline:'4\n3\n' -e empty ${TEST_SH} -c \
+		'x=4; echo $(( (x-=1)+1 )); echo $x'
+
+	atf_check -s exit:0 -o inline:'36\n5 7\n' -e empty ${TEST_SH} -c \
+		'unset x y; echo $(( (x=5) * (y=7) + 1 )); echo $x $y'
+	atf_check -s exit:0 -o inline:'36\n5 7\n' -e empty ${TEST_SH} -c \
+		'x=99; y=17; echo $(( (x=5) * (y=7) + 1 )); echo $x $y'
+	atf_check -s exit:0 -o inline:'36\n5 7\n' -e empty ${TEST_SH} -c \
+		'x=4; y=9; echo $(( (x+=1) * (y-=2) + 1 )); echo $x $y'
+
+	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
+		'set -u; unset x; echo $(( x = 3 )); echo $x'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'set -u; unset x; echo $(( x + 3 )); echo $x'
+	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
+		'set -u; unset x; echo $(( x+=3 )); echo $x'
+}
+
 atf_test_case arithmetic_fails
 arithmetic_fails_head()
 {
@@ -1030,6 +1087,6 @@ atf_init_test_cases() {
 	# atf_add_test_case progressive			# build up big expr
 	# atf_add_test_case test_errors			# erroneous input
 	# atf_add_test_case torture		# hard stuff (if there is any)
-	# atf_add_test_case var_assign			# assignment ops
+	atf_add_test_case var_assign			# assignment ops
 	# atf_add_test_case vulgarity	# truly evil inputs (syntax in vars...)
 }



CVS commit: src/tests/bin/sh

2017-03-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Mar 19 20:29:30 UTC 2017

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
PR bin/52090

Add 5 new test cases to test various ways that $* can be expanded.
Currently 3 of the 5 are marked as "expected to fail" because of the
bug in this PR.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.9 src/tests/bin/sh/t_expand.sh:1.10
--- src/tests/bin/sh/t_expand.sh:1.9	Sun Mar 12 00:39:47 2017
+++ src/tests/bin/sh/t_expand.sh	Sun Mar 19 20:29:30 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.9 2017/03/12 00:39:47 kre Exp $
+# $NetBSD: t_expand.sh,v 1.10 2017/03/19 20:29:30 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -227,6 +227,8 @@ iteration_on_null_or_missing_parameter_b
 		'N=; set -- ${N:-}; for X; do echo "[$X]"; done'
 }
 
+### The remaining tests use the following helper functions ...
+
 nl='
 '
 reset()
@@ -311,6 +313,8 @@ check()
 
 results()
 {
+	test -n "$1" && atf_expect_fail "$1"
+
 	test -z "${TEST_ID}" && return 0
 	test -z "${TEST_FAILURES}" && return 0
 
@@ -318,10 +322,13 @@ results()
 	echo >&2 "While testing '${TEST_ID}'"
 	echo >&2 " - - - - - - - - - - - - - - - - -"
 	echo >&2 "${TEST_FAILURES}"
+
 	atf_fail \
  "Test ${TEST_ID}: $TEST_FAIL_COUNT (of $TEST_NUM) subtests failed - see stderr"
 }
 
+### End helpers
+
 atf_test_case shell_params
 shell_params_head() {
 	atf_set "descr" "Test correct operation of the numeric parameters"
@@ -423,16 +430,255 @@ var_with_embedded_cmdsub_body() {
 	results
 }
 
+atf_test_case dollar_star
+dollar_star_head() {
+	atf_set "descr" 'Test expansion of various aspects of $*'
+}
+dollar_star_body() {
+
+	reset # dollar_star
+
+	check 'set -- a b c; echo $# $*'		'3 a b c'	0  # 1
+	check 'set -- a b c; echo $# "$*"'		'3 a b c'	0  # 2
+	check 'set -- a "b c"; echo $# $*'		'2 a b c'	0  # 3
+	check 'set -- a "b c"; echo $# "$*"'		'2 a b c'	0  # 4
+	check 'set -- a b c; set -- $* ; echo $# $*'	'3 a b c'	0  # 5
+	check 'set -- a b c; set -- "$*" ; echo $# $*'	'1 a b c'	0  # 6
+	check 'set -- a "b c"; set -- $* ; echo $# $*'	'3 a b c'	0  # 7
+	check 'set -- a "b c"; set -- "$*" ; echo $# $*' \
+			'1 a b c'	0  # 8
+
+	check 'IFS=". "; set -- a b c; echo $# $*'	'3 a b c'	0  # 9
+	check 'IFS=". "; set -- a b c; echo $# "$*"'	'3 a.b.c'	0  #10
+	check 'IFS=". "; set -- a "b c"; echo $# $*'	'2 a b c'	0  #11
+	check 'IFS=". "; set -- a "b c"; echo $# "$*"'	'2 a.b c'	0  #12
+	check 'IFS=". "; set -- a "b.c"; echo $# $*'	'2 a b c'	0  #13
+	check 'IFS=". "; set -- a "b.c"; echo $# "$*"'	'2 a.b.c'	0  #14
+	check 'IFS=". "; set -- a b c; set -- $* ; echo $# $*' \
+			'3 a b c'	0  #15
+	check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# $*' \
+			'1 a b c'	0  #16
+	check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# $*' \
+			'3 a b c'	0  #17
+	check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# $*' \
+			'1 a b c'	0  #18
+	check 'IFS=". "; set -- a b c; set -- $* ; echo $# "$*"' \
+			'3 a.b.c'	0  #19
+	check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# "$*"' \
+			'1 a.b.c'	0  #20
+	check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# "$*"' \
+			'3 a.b.c'	0  #21
+	check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
+			'1 a.b c'	0  #22
+
+	results
+}
+
+atf_test_case dollar_star_in_word
+dollar_star_in_word_head() {
+	atf_set "descr" 'Test expansion $* occurring in word of ${var:-word}'
+}
+dollar_star_in_word_body() {
+
+	reset dollar_star_in_word
+
+	unset xXx			; # just in case!
+
+	# Note that the expected results for these tests are identical
+	# to those from the dollar_star test.   It should never make
+	# a difference whether we expand $* or ${unset:-$*}
+
+	# (note expanding ${unset:-"$*"} is different, that is not tested here)
+
+	check 'set -- a b c; echo $# ${xXx:-$*}'		'3 a b c' 0  # 1
+	check 'set -- a b c; echo $# "${xXx:-$*}"'		'3 a b c' 0  # 2
+	check 'set -- a "b c"; echo $# ${xXx:-$*}'		'2 a b c' 0  # 3
+	check 'set -- a "b c"; echo $# "${xXx:-$*}"'		'2 a b c' 0  # 4
+	check 'set -- a b c; set -- ${xXx:-$*} ; echo $# $*'	'3 a b c' 0  # 5
+	check 'set -- a b c; set -- "${xXx:-$*}" ; echo $# $*'	'1 a b c' 0  # 6
+	check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# $*'	'3 a b c' 0  # 7
+	check 'set -- a "b c"; set -- "${xXx:-$*}" ; echo $# $*' \
+'1 a b c' 0  # 8
+
+	check 'IFS=". "; set -- a b c; echo $# ${xXx:-$*}'	'3 a b c' 0  # 9
+	check 'IFS=". "; set -- a b c; echo $# "${xXx:-$*}"'	'3 a.b.c' 0  #10
+	check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-$*}'	'2 a b c' 0  #11
+	check 'IFS=". "; set -- a "b c"; echo $# "${xXx:-$*}"'	'2 a.b c' 0  #12
+	check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-$*}'	'2 a b c' 0  

CVS commit: src/tests/bin/sh

2017-03-11 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Mar 12 00:39:47 UTC 2017

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
Add new test case in to check (coming) bug fix for newly discovered
ash based shell bug
echo ${unset_var##$(echo a)}$(echo b)
should say "b" but instead says "a" ... the first "echo a" is not
evaluated because it cannot possibly match an unset variable, but is
not removed from the list of command substitutions, when the shell
needs to execute the 2nd cmdsub, "echo b" should be at the head of
the list, but isn't, "echo a" is still there...

This test should fail (for now) - should show 4 of 40 subtests failing.
It isn't marked as atf_expect_fail as the fix for this will be coming
later today (I will just wait at least 1 b5 build cycle so the failure
can be observed).

Detecting the bug, and the fix, are from FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.8 src/tests/bin/sh/t_expand.sh:1.9
--- src/tests/bin/sh/t_expand.sh:1.8	Fri Apr 29 18:29:17 2016
+++ src/tests/bin/sh/t_expand.sh	Sun Mar 12 00:39:47 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.8 2016/04/29 18:29:17 christos Exp $
+# $NetBSD: t_expand.sh,v 1.9 2017/03/12 00:39:47 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -319,7 +319,7 @@ results()
 	echo >&2 " - - - - - - - - - - - - - - - - -"
 	echo >&2 "${TEST_FAILURES}"
 	atf_fail \
- "Test ${TEST_ID}: $TEST_FAIL_COUNT subtests (of $TEST_NUM) failed - see stderr"
+ "Test ${TEST_ID}: $TEST_FAIL_COUNT (of $TEST_NUM) subtests failed - see stderr"
 }
 
 atf_test_case shell_params
@@ -366,6 +366,63 @@ shell_params_body() {
 	results
 }
 
+atf_test_case var_with_embedded_cmdsub
+var_with_embedded_cmdsub_head() {
+	atf_set "descr" "Test expansion of vars with embedded cmdsub"
+}
+var_with_embedded_cmdsub_body() {
+
+	reset var_with_embedded_cmdsub
+
+	check 'unset x; echo ${x-$(echo a)}$(echo b)'  'ab' 0	#1
+	check 'unset x; echo ${x:-$(echo a)}$(echo b)' 'ab' 0	#2
+	check 'x=""; echo ${x-$(echo a)}$(echo b)' 'b'  0	#3
+	check 'x=""; echo ${x:-$(echo a)}$(echo b)''ab' 0	#4
+	check 'x=c; echo ${x-$(echo a)}$(echo b)'  'cb' 0	#5
+	check 'x=c; echo ${x:-$(echo a)}$(echo b)' 'cb' 0	#6
+
+	check 'unset x; echo ${x+$(echo a)}$(echo b)'  'b'  0	#7
+	check 'unset x; echo ${x:+$(echo a)}$(echo b)' 'b'  0	#8
+	check 'x=""; echo ${x+$(echo a)}$(echo b)' 'ab' 0	#9
+	check 'x=""; echo ${x:+$(echo a)}$(echo b)''b'  0	#10
+	check 'x=c; echo ${x+$(echo a)}$(echo b)'  'ab' 0	#11
+	check 'x=c; echo ${x:+$(echo a)}$(echo b)' 'ab' 0	#12
+
+	check 'unset x; echo ${x=$(echo a)}$(echo b)'  'ab' 0	#13
+	check 'unset x; echo ${x:=$(echo a)}$(echo b)' 'ab' 0	#14
+	check 'x=""; echo ${x=$(echo a)}$(echo b)' 'b'  0	#15
+	check 'x=""; echo ${x:=$(echo a)}$(echo b)''ab' 0	#16
+	check 'x=c; echo ${x=$(echo a)}$(echo b)'  'cb' 0	#17
+	check 'x=c; echo ${x:=$(echo a)}$(echo b)' 'cb' 0	#18
+
+	check 'unset x; echo ${x?$(echo a)}$(echo b)'  ''   2	#19
+	check 'unset x; echo ${x:?$(echo a)}$(echo b)' ''   2	#20
+	check 'x=""; echo ${x?$(echo a)}$(echo b)' 'b'  0	#21
+	check 'x=""; echo ${x:?$(echo a)}$(echo b)'''   2	#22
+	check 'x=c; echo ${x?$(echo a)}$(echo b)'  'cb' 0	#23
+	check 'x=c; echo ${x:?$(echo a)}$(echo b)' 'cb' 0	#24
+
+	check 'unset x; echo ${x%$(echo a)}$(echo b)'  'b'  0	#25
+	check 'unset x; echo ${x%%$(echo a)}$(echo b)' 'b'  0	#26
+	check 'x=""; echo ${x%$(echo a)}$(echo b)' 'b'  0	#27
+	check 'x=""; echo ${x%%$(echo a)}$(echo b)''b'  0	#28
+	check 'x=c; echo ${x%$(echo a)}$(echo b)'  'cb' 0	#29
+	check 'x=c; echo ${x%%$(echo a)}$(echo b)' 'cb' 0	#30
+	check 'x=aa; echo ${x%$(echo "*a")}$(echo b)'  'ab' 0	#31
+	check 'x=aa; echo ${x%%$(echo "*a")}$(echo b)' 'b'  0	#32
+
+	check 'unset x; echo ${x#$(echo a)}$(echo b)'  'b'  0	#33
+	check 'unset x; echo ${x##$(echo a)}$(echo b)' 'b'  0	#34
+	check 'x=""; echo ${x#$(echo a)}$(echo b)' 'b'  0	#35
+	check 'x=""; echo ${x##$(echo a)}$(echo b)''b'  0	#36
+	check 'x=c; echo ${x#$(echo a)}$(echo b)'  'cb' 0	#37
+	check 'x=c; echo ${x##$(echo a)}$(echo b)' 'cb' 0	#38
+	check 'x=aa; echo ${x#$(echo "*a")}$(echo b)'  'ab' 0	#39
+	check 'x=aa; echo ${x##$(echo "*a")}$(echo b)' 'b'  0	#40
+
+	results
+}
+
 atf_init_test_cases() {
 	atf_add_test_case dollar_at
 	atf_add_test_case dollar_at_with_text
@@ -377,4 +434,5 @@ atf_init_test_cases() {
 	atf_add_test_case iteration_on_null_or_null_parameter
 	atf_add_test_case iteration_on_null_or_missing_parameter
 	atf_add_test_case shell_params
+	atf_add_test_case var_with_embedded_cmdsub
 }



CVS commit: src/tests/bin/sh

2016-05-17 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue May 17 09:05:15 UTC 2016

Modified Files:
src/tests/bin/sh: t_shift.sh

Log Message:
Use valid (standard) shell syntax, in anticipation of /bin/sh enforcing
it sometime soon (perhaps.)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_shift.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_shift.sh
diff -u src/tests/bin/sh/t_shift.sh:1.1 src/tests/bin/sh/t_shift.sh:1.2
--- src/tests/bin/sh/t_shift.sh:1.1	Tue Mar  8 14:26:26 2016
+++ src/tests/bin/sh/t_shift.sh	Tue May 17 09:05:14 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_shift.sh,v 1.1 2016/03/08 14:26:26 christos Exp $
+# $NetBSD: t_shift.sh,v 1.2 2016/05/17 09:05:14 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -120,7 +120,7 @@ function_shift_head() {
 	atf_set "descr" "Test that shift in a function does not affect outside"
 }
 function_shift_body() {
-	# later...
+	: # later...
 }
 
 atf_test_case non_numeric_shift



CVS commit: src/tests/bin/sh

2016-05-15 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun May 15 15:44:43 UTC 2016

Modified Files:
src/tests/bin/sh: t_redircloexec.sh

Log Message:
Add a new test case to validate N> redirect disables close-on-exec.
OK christos@


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_redircloexec.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redircloexec.sh
diff -u src/tests/bin/sh/t_redircloexec.sh:1.2 src/tests/bin/sh/t_redircloexec.sh:1.3
--- src/tests/bin/sh/t_redircloexec.sh:1.2	Wed Mar 16 21:13:51 2016
+++ src/tests/bin/sh/t_redircloexec.sh	Sun May 15 15:44:43 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_redircloexec.sh,v 1.2 2016/03/16 21:13:51 christos Exp $
+# $NetBSD: t_redircloexec.sh,v 1.3 2016/05/15 15:44:43 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -82,6 +82,40 @@ exec_redir_closed_body() {
 	cleanhelper exec
 }
 
+atf_test_case exec_redir_open
+exec_redir_open_head() {
+	atf_set "descr" "Tests that redirections created by exec can remain open"
+}
+exec_redir_open_body() {
+
+	mkhelper exec 6 \
+		"exec 6> out 6>&6; echo exec1 >&6; ${TEST_SH} exec2; exec 6>&-"
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} ./exec1
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -e ./exec1
+
+	mkhelper exec 9 \
+		"exec 9> out ; echo exec1 >&9; ${TEST_SH} exec2 9>&9"
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} ./exec1
+
+	mkhelper exec 8 \
+		"exec 8> out; printf OK; exec 8>&8; echo exec1 >&8;" \
+		"printf OK; ${TEST_SH} exec2; printf OK"
+
+	atf_check -s exit:0 -o match:OKOKOK -e empty \
+		${TEST_SH} -e ./exec1
+
+	mkhelper exec 7 \
+		"exec 7> out; printf OK; echo exec1 >&7;" \
+		"printf OK; ${TEST_SH} 7>&7 exec2; printf OK"
+
+	atf_check -s exit:0 -o match:OKOKOK -e empty \
+		${TEST_SH} -e ./exec1
+
+	cleanhelper exec
+}
+
 atf_test_case loop_redir_open
 loop_redir_open_head() {
 	atf_set "descr" "Tests that redirections in loops don't close on exec"
@@ -136,6 +170,7 @@ subshell_redir_open_body() {
 
 atf_init_test_cases() {
 	atf_add_test_case exec_redir_closed
+	atf_add_test_case exec_redir_open
 	atf_add_test_case loop_redir_open
 	atf_add_test_case compound_redir_open
 	atf_add_test_case simple_redir_open



CVS commit: src/tests/bin/sh

2016-05-13 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat May 14 00:33:02 UTC 2016

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
Add another test for the 48875 fix fallout...


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.8 src/tests/bin/sh/t_redir.sh:1.9
--- src/tests/bin/sh/t_redir.sh:1.8	Wed May 11 17:43:17 2016
+++ src/tests/bin/sh/t_redir.sh	Sat May 14 00:33:02 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.8 2016/05/11 17:43:17 kre Exp $
+# $NetBSD: t_redir.sh,v 1.9 2016/05/14 00:33:02 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -800,6 +800,21 @@ validate_fn_redirects_body()
 f "$B" <&3 >&4
 			done >&2'
 
+	# And this tests a similar condition with that same fix
+	cat  <<- 'DONE' >Script
+		f() {
+			printf '%s' " hello $1"
+		}
+		exec 3>&1
+		echo $( for i in a b c
+			do printf '%s' @$i; f $i >&3; done >foo
+		)
+		printf '%s\n' foo=$(cat foo)
+	DONE
+	atf_check -s exit:0 -e empty \
+	-o inline:' hello a hello b hello c\nfoo=@a@b@c\n' \
+	${TEST_SH} Script
+
 	# Tests with sh reading stdin, which is not quite the same internal
 	# mechanism.
 	echo ". ./f-def || echo >&2 FAIL



CVS commit: src/tests/bin/sh

2016-05-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu May 12 14:25:11 UTC 2016

Modified Files:
src/tests/bin/sh: t_arith.sh

Log Message:
Grunge.  I know I fixed this typo before...  must have been in a different
couy of the test.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_arith.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_arith.sh
diff -u src/tests/bin/sh/t_arith.sh:1.4 src/tests/bin/sh/t_arith.sh:1.5
--- src/tests/bin/sh/t_arith.sh:1.4	Thu May 12 13:34:23 2016
+++ src/tests/bin/sh/t_arith.sh	Thu May 12 14:25:11 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_arith.sh,v 1.4 2016/05/12 13:34:23 kre Exp $
+# $NetBSD: t_arith.sh,v 1.5 2016/05/12 14:25:11 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -836,9 +836,9 @@ make_selection_body()
 		'echo $(( 0x1234 ? 111 : 222 ))'
 
 	atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
-		'echo $(( 1 < 2 ? -1 : i > 2 ? 1 : 0 ))'
+		'echo $(( 1 < 2 ? -1 : 1 > 2 ? 1 : 0 ))'
 	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
-		'echo $(( 1 < 1 ? -1 : i > 1 ? 1 : 0 ))'
+		'echo $(( 1 < 1 ? -1 : 1 > 1 ? 1 : 0 ))'
 	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
 		'echo $(( 2 < 1 ? -1 : 2 > 1 ? 1 : 0 ))'
 }



CVS commit: src/tests/bin/sh

2016-05-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu May 12 13:34:23 UTC 2016

Modified Files:
src/tests/bin/sh: t_arith.sh

Log Message:
Verify that questionable characters don't have bad associates.

ok christos@


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_arith.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_arith.sh
diff -u src/tests/bin/sh/t_arith.sh:1.3 src/tests/bin/sh/t_arith.sh:1.4
--- src/tests/bin/sh/t_arith.sh:1.3	Thu Mar 31 16:19:52 2016
+++ src/tests/bin/sh/t_arith.sh	Thu May 12 13:34:23 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_arith.sh,v 1.3 2016/03/31 16:19:52 christos Exp $
+# $NetBSD: t_arith.sh,v 1.4 2016/05/12 13:34:23 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -834,6 +834,13 @@ make_selection_body()
 
 	atf_check -s exit:0 -o inline:'111\n' -e empty ${TEST_SH} -c \
 		'echo $(( 0x1234 ? 111 : 222 ))'
+
+	atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
+		'echo $(( 1 < 2 ? -1 : i > 2 ? 1 : 0 ))'
+	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+		'echo $(( 1 < 1 ? -1 : i > 1 ? 1 : 0 ))'
+	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+		'echo $(( 2 < 1 ? -1 : 2 > 1 ? 1 : 0 ))'
 }
 
 atf_test_case operator_precedence



CVS commit: src/tests/bin/sh

2016-05-11 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed May 11 17:43:17 UTC 2016

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
Add a test for fd redirections on functions in loops (the etcupdate issue)
and also fix a quoting bug which was causing a test to fail, though
ATF was ignoring (an ATF bug to be investigated later.)

OK christos@


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.7 src/tests/bin/sh/t_redir.sh:1.8
--- src/tests/bin/sh/t_redir.sh:1.7	Mon May  9 22:34:37 2016
+++ src/tests/bin/sh/t_redir.sh	Wed May 11 17:43:17 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.7 2016/05/09 22:34:37 kre Exp $
+# $NetBSD: t_redir.sh,v 1.8 2016/05/11 17:43:17 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -786,6 +786,20 @@ validate_fn_redirects_body()
 		${TEST_SH} -c \
 		   ". ./f-def; { f;f>/dev/null;}& wait; printf '%s\n' success10"
 
+	# This one tests the issue etcupdate had with the original 48875 fix
+	atf_check -s exit:0 -o inline:'Func a\nFunc b\nFunc c\n' -e empty \
+		${TEST_SH} -c '
+			f() {
+echo Func "$1"
+			}
+			exec 3<&0 4>&1
+			( echo x-a; echo y-b; echo z-c ) |
+			while read A
+			do
+B=${A#?-}
+f "$B" <&3 >&4
+			done >&2'
+
 	# Tests with sh reading stdin, which is not quite the same internal
 	# mechanism.
 	echo ". ./f-def || echo >&2 FAIL
@@ -796,7 +810,7 @@ validate_fn_redirects_body()
 	echo '
 		. ./f-def || echo >&2 FAIL
 		f >&-
-		printf '%s\n' stdin2
+		printf "%s\n" stdin2
 	' | atf_check -s exit:0 -o inline:'stdin2\n' -e empty ${TEST_SH}
 
 	cat <<- 'DONE' > fgh.def



CVS commit: src/tests/bin/sh

2016-05-09 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon May  9 22:34:37 UTC 2016

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
PR bin/48875   PR bin/51123This adds tests more that verify fide descriptor
redirection works correctly (including that the bugs reported in those PRs
are fixed.)  Note that the tests for 48875 are slow, so one of the new
test cases ends up running > 25 seconds (just doing sleeps) - each individual
test is just a few seconds, but there are several of them.

OK christos@


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.6 src/tests/bin/sh/t_redir.sh:1.7
--- src/tests/bin/sh/t_redir.sh:1.6	Mon May  2 01:47:14 2016
+++ src/tests/bin/sh/t_redir.sh	Mon May  9 22:34:37 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.6 2016/05/02 01:47:14 christos Exp $
+# $NetBSD: t_redir.sh,v 1.7 2016/05/09 22:34:37 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -472,6 +472,50 @@ local_redirections_body()
 	fi
 }
 
+atf_test_case named_fd_redirections
+named_fd_redirections_head()
+{
+	atf_set "descr" "Tests redirections to /dev/stdout (etc)"
+
+}
+named_fd_redirections_body()
+{
+	if test -c /dev/stdout
+	then
+		atf_check -s exit:0 -o inline:'OK\n' -e empty \
+			${TEST_SH} -c 'echo OK >/dev/stdout'
+		atf_check -s exit:0 -o inline:'OK\n' -e empty \
+			${TEST_SH} -c '/bin/echo OK >/dev/stdout'
+	fi
+
+	if test -c /dev/stdin
+	then
+		atf_require_prog cat
+
+		echo GOOD | atf_check -s exit:0 -o inline:'GOOD\n' -e empty \
+			${TEST_SH} -c 'read var /dev/stderr >&2'
+		atf_check -s exit:0 -e inline:'OK\n' -o empty \
+			${TEST_SH} -c '/bin/echo OK 2>/dev/stderr >&2'
+	fi
+
+	if test -c /dev/fd/8 && test -c /dev/fd/9
+	then
+		atf_check -s exit:0 -o inline:'EIGHT\n' -e empty \
+			${TEST_SH} -c 'printf "%s\n" EIGHT 8>&1 >/dev/fd/8 |
+	cat 9<&0  f-def
+		f() {
+			printf '%s\n' In-Func
+		}
+	DONE
+
+	atf_check -s exit:0 -o inline:'In-Func\nsuccess1\n' -e empty \
+		${TEST_SH} -c ". ./f-def; f ; printf '%s\n' success1"
+	atf_check -s exit:0 -o inline:'success2\n' -e empty \
+		${TEST_SH} -c ". ./f-def; f >/dev/null; printf '%s\n' success2"
+	atf_check -s exit:0 -o inline:'success3\n' -e empty \
+		${TEST_SH} -c ". ./f-def; f >&- ; printf '%s\n' success3"
+	atf_check -s exit:0 -o inline:'In-Func\nsuccess4\n' -e empty \
+		${TEST_SH} -c ". ./f-def; f & wait; printf '%s\n' success4"
+	atf_check -s exit:0 -o inline:'success5\n' -e empty \
+		${TEST_SH} -c ". ./f-def; f >&- & wait; printf '%s\n' success5"
+	atf_check -s exit:0 -o inline:'In-Func\nIn-Func\nsuccess6\n' -e empty \
+		${TEST_SH} -c ". ./f-def; f;f; printf '%s\n' success6"
+	atf_check -s exit:0 -o inline:'In-Func\nIn-Func\nsuccess7\n' -e empty \
+		${TEST_SH} -c ". ./f-def; { f;f;}; printf '%s\n' success7"
+	atf_check -s exit:0 -o inline:'In-Func\nIn-Func\nsuccess8\n' -e empty \
+		${TEST_SH} -c ". ./f-def; { f;f;}& wait; printf '%s\n' success8"
+	atf_check -s exit:0 -o inline:'In-Func\nsuccess9\n' -e empty \
+		${TEST_SH} -c \
+		   ". ./f-def; { f>/dev/null;f;}& wait; printf '%s\n' success9"
+	atf_check -s exit:0 -o inline:'In-Func\nsuccess10\n' -e empty \
+		${TEST_SH} -c \
+		   ". ./f-def; { f;f>/dev/null;}& wait; printf '%s\n' success10"
+
+	# Tests with sh reading stdin, which is not quite the same internal
+	# mechanism.
+	echo ". ./f-def || echo >&2 FAIL
+		f
+		printf '%s\n' stdin1
+	"| atf_check -s exit:0 -o inline:'In-Func\nstdin1\n' -e empty ${TEST_SH}
+
+	echo '
+		. ./f-def || echo >&2 FAIL
+		f >&-
+		printf '%s\n' stdin2
+	' | atf_check -s exit:0 -o inline:'stdin2\n' -e empty ${TEST_SH}
+
+	cat <<- 'DONE' > fgh.def
+		f() {
+			echo -n f >&3
+			sleep 4
+			echo -n F >&3
+		}
+		g() {
+			echo -n g >&3
+			sleep 2
+			echo -n G >&3
+		}
+		h() {
+			echo -n h >&3
+		}
+	DONE
+
+	atf_check -s exit:0 -o inline:'fFgGh' -e empty \
+		${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
+			exec 3>&1
+			f; g; h'
+
+	atf_check -s exit:0 -o inline:'fghGF' -e empty \
+		${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
+			exec 3>&1
+			f & sleep 1; g & sleep 1; h; wait'
+
+	atf_check -s exit:0 -o inline:'fFgGhX Y\n' -e empty \
+		${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
+			exec 3>&1
+			echo X $( f ; g ; h ) Y'
+
+	# This one is the real test for PR bin/48875.  If the
+	# cmdsub does not complete before f g (and h) exit,
+	# then the 'F' & 'G' will precede 'X Y' in the output.
+	# If the cmdsub finishes while f & g are still running,
+	# then the X Y will appear before the F and G.
+	# The trailing "sleep 3" is just so we catch all the
+	# output (otherwise atf_check will be finished while
+	# f & g are still sleeping).
+
+	atf_check -s exit:0 -o inline:'fghX Y\nGF' -e empty \
+		${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
+			exec 

CVS commit: src/tests/bin/sh

2016-05-07 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat May  7 23:51:30 UTC 2016

Modified Files:
src/tests/bin/sh: t_exit.sh

Log Message:
Remove the trap_zero__explicit_return test case - it was testing undefined
behaviour (and failed with the NetBSD shell, and was marked as expected to
fail.)   Other shells do different things.   The test was worthless, and is
now gone.

OK christos@


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_exit.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_exit.sh
diff -u src/tests/bin/sh/t_exit.sh:1.5 src/tests/bin/sh/t_exit.sh:1.6
--- src/tests/bin/sh/t_exit.sh:1.5	Tue Mar  1 12:39:35 2016
+++ src/tests/bin/sh/t_exit.sh	Sat May  7 23:51:30 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_exit.sh,v 1.5 2016/03/01 12:39:35 christos Exp $
+# $NetBSD: t_exit.sh,v 1.6 2016/05/07 23:51:30 kre Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -105,21 +105,6 @@ trap_zero__explicit_exit_body() {
 	# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
 }
 
-# Is return really defined to operate other than in functions (& '.') ??
-atf_test_case trap_zero__explicit_return
-trap_zero__explicit_return_head() {
-	atf_set "descr" "Tests that the trap statement in a subshell in a " \
-			"script works when the subshell executes a return"
-}
-trap_zero__explicit_return_body() {
-	echo '( trap "echo exiting" 0; return; echo NO_NO_NO )' >helper.sh
-	atf_expect_fail "return from a sub-shell not defined and does not work"
-	atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \
-		${TEST_SH} helper.sh
-	# test ksh by setting TEST_SH to /bin/ksh and run the entire set...
-	# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
-}
-
 atf_test_case simple_exit
 simple_exit_head() {
 	atf_set "descr" "Tests that various values for exit status work"
@@ -166,7 +151,6 @@ atf_init_test_cases() {
 	atf_add_test_case trap_subshell
 	atf_add_test_case trap_zero__implicit_exit
 	atf_add_test_case trap_zero__explicit_exit
-	atf_add_test_case trap_zero__explicit_return
 	atf_add_test_case simple_exit
 	atf_add_test_case subshell_exit
 	atf_add_test_case subshell_background



CVS commit: src/tests/bin/sh

2016-05-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon May  2 01:47:14 UTC 2016

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
More redirect tests, in particular, tests for redirects to/from
file descriptors outside the 0..9 range, and complex fd
reassignments.  Also test that the shell can cope with the
value of ulimit -n changing (downwards, up is harmless)
(Freom kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.5 src/tests/bin/sh/t_redir.sh:1.6
--- src/tests/bin/sh/t_redir.sh:1.5	Sun Mar 27 10:49:07 2016
+++ src/tests/bin/sh/t_redir.sh	Sun May  1 21:47:14 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.5 2016/03/27 14:49:07 christos Exp $
+# $NetBSD: t_redir.sh,v 1.6 2016/05/02 01:47:14 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -333,7 +333,78 @@ fd_redirections_head()
 }
 fd_redirections_body()
 {
-	# Or it will one day...
+	atf_require_prog /bin/echo
+
+	cat <<- 'DONE' > helper.sh
+		f() {
+			/bin/echo nothing "$1" >& "$1"
+		}
+		for n
+		do
+			eval "f $n $n"'> file-$n'
+		done
+	DONE
+	cat <<- 'DONE' > reread.sh
+		f() {
+			(read -r var; echo "${var}") <&"$1"
+		}
+		for n
+		do
+			x=$( eval "f $n $n"'< file-$n' )
+			test "${x}" = "nothing $n" || echo "$n"
+		done
+	DONE
+
+	validate()
+	{
+	for n
+	do
+		test -e "file-$n" || atf_fail "file-$n not created"
+		C=$(cat file-"$n")
+		test "$C" = "nothing $n" ||
+			atf_fail "file-$n contains '$C' not 'nothing $n'"
+	done
+	}
+
+	atf_check -s exit:0 -e empty -o empty \
+		${TEST_SH} helper.sh 1 2 3 4 5 6 7 8 9
+	validate 1 2 3 4 5 6 7 8 9
+	atf_check -s exit:0 -e empty -o empty \
+		${TEST_SH} reread.sh 3 4 5 6 7 8 9
+
+	L=$(ulimit -n)
+	if [ "$L" -ge 30 ]
+	then
+		atf_check -s exit:0 -e empty -o empty \
+			${TEST_SH} helper.sh 10 15 19 20 25 29
+		validate 10 15 19 20 25 29
+		atf_check -s exit:0 -e empty -o empty \
+			${TEST_SH} reread.sh 10 15 19 20 25 29
+	fi
+	if [ "$L" -ge 100 ]
+	then
+		atf_check -s exit:0 -e empty -o empty \
+			${TEST_SH} helper.sh 32 33 49 50 51 63 64 65 77 88 99
+		validate 32 33 49 50 51 63 64 65 77 88 99
+		atf_check -s exit:0 -e empty -o empty \
+			${TEST_SH} reread.sh 32 33 49 50 51 63 64 65 77 88 99
+	fi
+	if [ "$L" -ge 500 ]
+	then
+		atf_check -s exit:0 -e empty -o empty \
+			${TEST_SH} helper.sh 100 101 199 200 222 333 444 499
+		validate 100 101 199 200 222 333 444 499
+		atf_check -s exit:0 -e empty -o empty \
+			${TEST_SH} reread.sh 100 101 199 200 222 333 444 499
+	fi
+	if [ "$L" -gt 1005 ]
+	then
+		atf_check -s exit:0 -e empty -o empty \
+			${TEST_SH} helper.sh 1000 1001 1002 1003 1004 1005
+		validate 1000 1001 1002 1003 1004 1005
+		atf_check -s exit:0 -e empty -o empty \
+			${TEST_SH} reread.sh 1000 1001 1002 1003 1004 1005
+	fi
 } 
 
 atf_test_case local_redirections
@@ -344,7 +415,61 @@ local_redirections_head()
 }
 local_redirections_body()
 {
-	# Or it will one day...
+	cat <<- 'DONE' > helper.sh
+		for f
+		do
+			eval "exec $f"'> file-$f'
+		done
+
+		for f
+		do
+			printf '%s\n' "Hello $f" >&"$f"
+		done
+
+		for f
+		do
+			eval "exec $f"'>&-'
+		done
+
+		for f
+		do
+			eval "exec $f"'< file-$f'
+		done
+
+		for f
+		do
+			exec <& "$f"
+			read -r var || echo >&2 "No data in file-$f"
+			read -r x && echo >&2 "Too much data in file-${f}: $x"
+			test "${var}" = "Hello $f" ||
+			echo >&2 "file-$f contains '${var}' not 'Hello $f'"
+		done
+	DONE
+
+	atf_check -s exit:0 -o empty -e empty \
+		${TEST_SH} helper.sh 3 4 5 6 7 8 9
+
+	L=$(ulimit -n)
+	if [ "$L" -ge 30 ]
+	then
+		atf_check -s exit:0 -o empty -e empty \
+			${TEST_SH} helper.sh 10 11 13 15 16 19 20 28 29
+	fi
+	if [ "$L" -ge 100 ]
+	then
+		atf_check -s exit:0 -o empty -e empty \
+			${TEST_SH} helper.sh 30 31 32 63 64 65 77 88 99
+	fi
+	if [ "$L" -ge 500 ]
+	then
+		atf_check -s exit:0 -o empty -e empty \
+			${TEST_SH} helper.sh 100 101 111 199 200 201 222 333 499
+	fi
+	if [ "$L" -ge 1005 ]
+	then
+		atf_check -s exit:0 -o empty -e empty \
+			${TEST_SH} helper.sh 1000 1001 1002 1003 1004 1005
+	fi
 }
 
 atf_test_case redir_in_case
@@ -443,7 +568,138 @@ subshell_redirections_head()
 }
 subshell_redirections_body()
 {
-	# Or will, one day
+	atf_require_prog cat
+
+	LIM=$(ulimit -n)
+
+	cat <<- 'DONE' |
+		exec 6>output-file
+
+		( printf "hello\n" >&6 )
+
+		exec 8&2 Hello )
+
+		( printf "bye-bye\n" >&6 )
+
+		( exec 8<&- )
+		read bye <&8 || echo >&2 "Closed?"
+		echo Bye="$bye"
+	DONE
+	atf_check -s exit:0 -o match:Bye=bye-bye -e empty \
+		${TEST_SH}
+
+	cat <<- 'DONE' |
+		for arg in one-4 two-24 three-14
+		do
+			fd=${arg#*-}
+			file=${arg%-*}
+			eval "exec ${fd}>${file}"
+		done
+
+		for arg in one-5 two-7 three-19
+		do
+			fd=${arg#*-}
+			file=${arg%-*}
+			eval 

CVS commit: src/tests/bin/sh

2016-04-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr 29 18:29:17 UTC 2016

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
use "" so ${TEST_SH} is expanded.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.7 src/tests/bin/sh/t_expand.sh:1.8
--- src/tests/bin/sh/t_expand.sh:1.7	Thu Mar 31 12:21:10 2016
+++ src/tests/bin/sh/t_expand.sh	Fri Apr 29 14:29:17 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.7 2016/03/31 16:21:10 christos Exp $
+# $NetBSD: t_expand.sh,v 1.8 2016/04/29 18:29:17 christos Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -340,7 +340,7 @@ shell_params_body() {
 	check "${TEST_SH} -c 'echo 0=\$0 1=\$1 2=\$2' a b c" '0=a 1=b 2=c' 0
 
 	echo 'echo 0="$0" 1="$1" 2="$2"' > helper.sh
-	check '${TEST_SH} helper.sh a b c' '0=helper.sh 1=a 2=b' 0
+	check "${TEST_SH} helper.sh a b c" '0=helper.sh 1=a 2=b' 0
 
 	check 'set -- a bb ccc  e ff ggg  \
 		i jj kkk



CVS commit: src/tests/bin/sh

2016-04-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Apr  4 12:40:13 UTC 2016

Modified Files:
src/tests/bin/sh: t_cmdsub.sh

Log Message:
Add a test case for here documents positioned outside `` with the
redirect operator inside the ``.   Move the one similar test using
$( ) into its own test case (and expand that test as well.
The `` case was omitted before, as no shells (including NetBSD) were
parsing it correctly,  Now the NetBSD shell does, so ... (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_cmdsub.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_cmdsub.sh
diff -u src/tests/bin/sh/t_cmdsub.sh:1.3 src/tests/bin/sh/t_cmdsub.sh:1.4
--- src/tests/bin/sh/t_cmdsub.sh:1.3	Thu Mar 31 12:20:39 2016
+++ src/tests/bin/sh/t_cmdsub.sh	Mon Apr  4 08:40:13 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_cmdsub.sh,v 1.3 2016/03/31 16:20:39 christos Exp $
+# $NetBSD: t_cmdsub.sh,v 1.4 2016/04/04 12:40:13 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -433,13 +433,6 @@ r_heredoc_in_cmdsub_body() {
 	2 * 7 = $(( 2 * 7 ))
 			EOF
 			)"'
-
-	atf_check -s exit:0 -o inline:'Line 1\nLine 2\n' -e empty \
-	${TEST_SH} -c 'echo "$( cat <<- "EOF" )"
-Line 1
-Line 2
-EOF
-			'
 }
 
 atf_test_case s_heredoc_in_backticks
@@ -629,6 +622,89 @@ v_cmdsub_paren_tests_body() {
 		${TEST_SH} -c 'echo H: empty command-substitution $( )'
 }
 
+atf_test_case w_heredoc_outside_cmdsub
+w_heredoc_outside_cmdsub_head() {
+	atf_set "descr" "Checks that here docs work inside cmd subs"
+}
+w_heredoc_outside_cmdsub_body() {
+	atf_require_prog cat
+
+	atf_check -s exit:0 -o inline:'Mary had a\nlittle\nlamb\n' -e empty \
+	${TEST_SH} -c 'echo "$( cat <<- \EOF )"
+Mary had a
+little
+lamb
+			EOF
+			'
+
+	atf_check -s exit:0 -e empty \
+	-o inline:'Mary had 1\nlittle\nlamb\nMary had 4\nlittle\nlambs\n' \
+	${TEST_SH} -c 'for N in 1 4; do echo "$( cat <<- EOF )"
+Mary had ${N}
+little
+lamb$( [ $N -gt 1 ] && echo s )
+			EOF
+			done'
+
+
+	atf_check -s exit:0 -o inline:'A Calculation:\n2 * 7 = 14\n' -e empty \
+	${TEST_SH} -c 'echo "$( cat <<- EOF)"
+A Calculation:
+	2 * 7 = $(( 2 * 7 ))
+			EOF
+			'
+}
+
+atf_test_case x_heredoc_outside_backticks
+x_heredoc_outside_backticks_head() {
+	atf_set "descr" "Checks that here docs work inside old style cmd subs"
+}
+x_heredoc_outside_backticks_body() {
+	atf_require_prog cat
+
+	atf_check -s exit:0 -o inline:'Mary had a little lamb\n' -e empty \
+	${TEST_SH} -c 'echo ` cat <<- \EOF `
+Mary had a
+little
+lamb
+			EOF
+			'
+
+	atf_check -s exit:0 -o inline:'A Calculation:\n17 / 3 = 5\n' -e empty \
+	${TEST_SH} -c 'echo "` cat <<- EOF `"
+A Calculation:
+	17 / 3 = $(( 17 / 3 ))
+			EOF
+			'
+}
+
+atf_test_case t_nested_cmdsubs_in_heredoc
+t_nested_cmdsubs_in_heredoc_head() {
+	atf_set "descr" "Checks nested command substitutions in here docs"
+}
+t_nested_cmdsubs_in_heredoc_body() {
+	atf_require_prog cat
+	atf_require_prog rm
+
+	rm -f * 2>/dev/null || :
+	echo "Hello" > File
+
+	atf_check -s exit:0 -o inline:'Hello U\nHelp me!\n' -e empty \
+	${TEST_SH} -c 'cat <<- EOF
+		$(cat File) U
+		$( V=$(cat File); echo "${V%lo}p" ) me!
+		EOF'
+
+	rm -f * 2>/dev/null || :
+	echo V>V ; echo A>A; echo R>R
+	echo Value>VAR
+
+	atf_check -s exit:0 -o inline:'$2.50\n' -e empty \
+	${TEST_SH} -c 'cat <<- EOF
+	$(Value='\''$2.50'\'';eval echo $(eval $(cat V)$(cat A)$(cat R)=\'\''\$$(cat $(cat V)$(cat A)$(cat R))\'\''; eval echo \$$(set -- *;echo ${3}${1}${2})))
+		EOF'
+}
+
 atf_test_case z_absurd_heredoc_cmdsub_combos
 z_absurd_heredoc_cmdsub_combos_head() {
 	atf_set "descr" "perverse and unusual cmd substitutions & more"
@@ -701,5 +777,7 @@ atf_init_test_cases() {
 	atf_add_test_case t_nested_cmdsubs_in_heredoc
 	atf_add_test_case u_nested_backticks_in_heredoc
 	atf_add_test_case v_cmdsub_paren_tests
+	atf_add_test_case w_heredoc_outside_cmdsub
+	atf_add_test_case x_heredoc_outside_backticks
 	atf_add_test_case z_absurd_heredoc_cmdsub_combos
 }



CVS commit: src/tests/bin/sh

2016-03-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 31 16:22:28 UTC 2016

Modified Files:
src/tests/bin/sh: t_set_e.sh

Log Message:
When embedding a command in a subshell "( ... )" avoid accidentally
producing (( (when the cmd starts with a '(' as that as a reserved
sequence (according to posix) and some shells do treat it specially.
So, force a space after the enclosing '(' to avoid the problem.
For symmetry, put a space before the concluding ')' as well, though
there is nothing special about )). (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_set_e.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_set_e.sh
diff -u src/tests/bin/sh/t_set_e.sh:1.3 src/tests/bin/sh/t_set_e.sh:1.4
--- src/tests/bin/sh/t_set_e.sh:1.3	Sun Mar 27 10:50:01 2016
+++ src/tests/bin/sh/t_set_e.sh	Thu Mar 31 12:22:27 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_set_e.sh,v 1.3 2016/03/27 14:50:01 christos Exp $
+# $NetBSD: t_set_e.sh,v 1.4 2016/03/31 16:22:27 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -63,7 +63,7 @@ dcheck()
 # is thus important to test. (PR bin/29861)
 echeck()
 {
-	check1 'eval '"'($1)'" "$2" "eval '($1)'"
+	check1 'eval '"'( $1 )'" "$2" "eval '($1)'"
 }
 
 atf_test_case all



CVS commit: src/tests/bin/sh

2016-03-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 31 16:22:54 UTC 2016

Modified Files:
src/tests/bin/sh: t_wait.sh

Log Message:
Avoid leaving turds in /tmp. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/bin/sh/t_wait.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_wait.sh
diff -u src/tests/bin/sh/t_wait.sh:1.7 src/tests/bin/sh/t_wait.sh:1.8
--- src/tests/bin/sh/t_wait.sh:1.7	Sun Mar 27 10:50:40 2016
+++ src/tests/bin/sh/t_wait.sh	Thu Mar 31 12:22:54 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_wait.sh,v 1.7 2016/03/27 14:50:40 christos Exp $
+# $NetBSD: t_wait.sh,v 1.8 2016/03/31 16:22:54 christos Exp $
 #
 # Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -147,7 +147,7 @@ kill_body() {
 	atf_require_prog kill
 
 	s=killhelper.sh
-	z=/tmp/killhelper.$$ 
+	z=killhelper.$$ 
 	pid=
 
 	# waiting for a specific process that is not a child



CVS commit: src/tests/bin/sh

2016-03-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 31 16:21:52 UTC 2016

Modified Files:
src/tests/bin/sh: t_here.sh

Log Message:
Added lots more end delimiter tests (some weird cases...). Also
use printf %s instead of echo, as there are embedded \ chars in
some of the strings, and some other (nameless) shells insist on
treating \ in the args to echo as something special... (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_here.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_here.sh
diff -u src/tests/bin/sh/t_here.sh:1.5 src/tests/bin/sh/t_here.sh:1.6
--- src/tests/bin/sh/t_here.sh:1.5	Sun Mar 27 10:52:40 2016
+++ src/tests/bin/sh/t_here.sh	Thu Mar 31 12:21:52 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_here.sh,v 1.5 2016/03/27 14:52:40 christos Exp $
+# $NetBSD: t_here.sh,v 1.6 2016/03/31 16:21:52 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -88,6 +88,11 @@ check()
 		fail=true
 	fi
 
+	if $fail
+	then
+		echo >&2 "[$TEST_NUM] Full command: <<${CMD}>>"
+	fi
+
 	$fail && test -n "$TEST_ID" && {
 		TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+
 }${TEST_ID}[$TEST_NUM]: test of '$1' failed";
@@ -171,55 +176,56 @@ end_markers_head() {
 end_markers_body() {
 
 	reset 'end_markers'
-	for end in EOF 1 \! '$$$' "string " a\\\  '&' '' ' ' '  ' --STRING-- . '~~~' \
+	for end in EOF 1 \! '$$$' "string " a\\\ a\\\ \   '&' '' ' ' '  ' \
+	--STRING-- . '~~~' ')' '(' '#' '()' '(\)' '(\/)' '--' '\' '{' '}' \
 VERYVERYVERYVERYLONGLONGLONGin_fact_absurdly_LONG_LONG_HERE_DOCUMENT_TERMINATING_MARKER_THAT_goes_On_forever_and_ever_and_ever...
 	do
 		# check unquoted end markers
 		case "${end}" in
-		('' | *[' $

CVS commit: src/tests/bin/sh

2016-03-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 31 16:20:40 UTC 2016

Modified Files:
src/tests/bin/sh: t_cmdsub.sh

Log Message:
Added tests collected by Sven Mascheck
http://www.in-ulm.de/~mascheck/various/cmd-subst/
which test cases of ')' being embedded in command substitutions.
(from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_cmdsub.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_cmdsub.sh
diff -u src/tests/bin/sh/t_cmdsub.sh:1.2 src/tests/bin/sh/t_cmdsub.sh:1.3
--- src/tests/bin/sh/t_cmdsub.sh:1.2	Sun Mar 27 10:53:17 2016
+++ src/tests/bin/sh/t_cmdsub.sh	Thu Mar 31 12:20:39 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_cmdsub.sh,v 1.2 2016/03/27 14:53:17 christos Exp $
+# $NetBSD: t_cmdsub.sh,v 1.3 2016/03/31 16:20:39 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -519,6 +519,116 @@ u_nested_backticks_in_heredoc_body() {
 		EOF'
 }
 
+atf_test_case v_cmdsub_paren_tests
+v_cmdsub__paren_tests_head() {
+	atf_set "descr" "tests with cmdsubs containing embedded ')'"
+}
+v_cmdsub_paren_tests_body() {
+
+	# Tests from:
+	#	http://www.in-ulm.de/~mascheck/various/cmd-subst/
+	# (slightly modified.)
+
+	atf_check -s exit:0 -o inline:'A.1\n' -e empty ${TEST_SH} -c \
+		'echo $(
+			case x in  x) echo A.1;; esac
+		)'
+
+	atf_check -s exit:0 -o inline:'A.2\n' -e empty ${TEST_SH} -c \
+		'echo $(
+			case x in  x) echo A.2;; esac # comment
+		)'
+
+	atf_check -s exit:0 -o inline:'A.3\n' -e empty ${TEST_SH} -c \
+		'echo $(
+			case x in (x) echo A.3;; esac
+		)'
+
+	atf_check -s exit:0 -o inline:'A.4\n' -e empty ${TEST_SH} -c \
+		'echo $(
+			case x in (x) echo A.4;; esac # comment
+		)'
+
+	atf_check -s exit:0 -o inline:'A.5\n' -e empty ${TEST_SH} -c \
+		'echo $(
+			case x in (x) echo A.5
+			esac
+		)'
+
+	atf_check -s exit:0 -o inline:'B: quoted )\n' -e empty ${TEST_SH} -c \
+		'echo $(
+			echo '\''B: quoted )'\''
+		)'
+
+	atf_check -s exit:0 -o inline:'C: comment then closing paren\n' \
+		-e empty ${TEST_SH} -c \
+			'echo $(
+echo C: comment then closing paren # )
+			)'
+
+	atf_check -s exit:0 -o inline:'D.1: here-doc with )\n' \
+		-e empty ${TEST_SH} -c \
+			'echo $(
+cat <<-\eof
+D.1: here-doc with )
+eof
+			)'
+
+	# D.2 is a bogus test.
+
+	atf_check -s exit:0 -o inline:'D.3: here-doc with \()\n' \
+		-e empty ${TEST_SH} -c \
+			'echo $(
+cat <<-\eof
+D.3: here-doc with \()
+eof
+			)'
+
+	atf_check -s exit:0 -e empty \
+	  -o inline:'E: here-doc terminated with a parenthesis ("academic")\n' \
+		${TEST_SH} -c \
+		'echo $(
+			cat <<-\)
+			E: here-doc terminated with a parenthesis ("academic")
+			)
+		)'
+
+	atf_check -s exit:0 -e empty \
+-o inline:'F.1: here-doc embed with unbal single, back- or doublequote '\''\n' \
+		${TEST_SH} -c \
+		'echo $(
+			cat <<-"eof"
+		F.1: here-doc embed with unbal single, back- or doublequote '\''
+			eof
+		)'
+	atf_check -s exit:0 -e empty \
+ -o inline:'F.2: here-doc embed with unbal single, back- or doublequote "\n' \
+		${TEST_SH} -c \
+		'echo $(
+			cat <<-"eof"
+		F.2: here-doc embed with unbal single, back- or doublequote "
+			eof
+		)'
+	atf_check -s exit:0 -e empty \
+ -o inline:'F.3: here-doc embed with unbal single, back- or doublequote `\n' \
+		${TEST_SH} -c \
+		'echo $(
+			cat <<-"eof"
+		F.3: here-doc embed with unbal single, back- or doublequote `
+			eof
+		)'
+
+	atf_check -s exit:0 -e empty -o inline:'G: backslash at end of line\n' \
+		${TEST_SH} -c \
+			'echo $(
+echo G: backslash at end of line # \
+			)'
+
+	atf_check -s exit:0 -e empty \
+		-o inline:'H: empty command-substitution\n' \
+		${TEST_SH} -c 'echo H: empty command-substitution $( )'
+}
+
 atf_test_case z_absurd_heredoc_cmdsub_combos
 z_absurd_heredoc_cmdsub_combos_head() {
 	atf_set "descr" "perverse and unusual cmd substitutions & more"
@@ -590,5 +700,6 @@ atf_init_test_cases() {
 	atf_add_test_case s_heredoc_in_backticks
 	atf_add_test_case t_nested_cmdsubs_in_heredoc
 	atf_add_test_case u_nested_backticks_in_heredoc
+	atf_add_test_case v_cmdsub_paren_tests
 	atf_add_test_case z_absurd_heredoc_cmdsub_combos
 }



CVS commit: src/tests/bin/sh

2016-03-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 31 16:21:10 UTC 2016

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
PR bin/51027 - tests for shell positional parameters, including
testing that $10 is correctly parsed as ${1}0 and not as ${10}.
More than that though. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.6 src/tests/bin/sh/t_expand.sh:1.7
--- src/tests/bin/sh/t_expand.sh:1.6	Tue Mar  8 09:26:54 2016
+++ src/tests/bin/sh/t_expand.sh	Thu Mar 31 12:21:10 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.6 2016/03/08 14:26:54 christos Exp $
+# $NetBSD: t_expand.sh,v 1.7 2016/03/31 16:21:10 christos Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -227,6 +227,145 @@ iteration_on_null_or_missing_parameter_b
 		'N=; set -- ${N:-}; for X; do echo "[$X]"; done'
 }
 
+nl='
+'
+reset()
+{
+	TEST_NUM=0
+	TEST_FAILURES=''
+	TEST_FAIL_COUNT=0
+	TEST_ID="$1"
+}
+
+check()
+{
+	fail=false
+	TEMP_FILE=$( mktemp OUT.XX )
+	TEST_NUM=$(( $TEST_NUM + 1 ))
+	MSG=
+
+	# our local shell (ATF_SHELL) better do quoting correctly...
+	# some of the tests expect us to expand $nl internally...
+	CMD="$1"
+
+	result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
+	STATUS=$?
+
+	if [ "${STATUS}" -ne "$3" ]; then
+		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
+		MSG="${MSG} expected exit code $3, got ${STATUS}"
+
+		# don't actually fail just because of wrong exit code
+		# unless we either expected, or received "good"
+		case "$3/${STATUS}" in
+		(*/0|0/*) fail=true;;
+		esac
+	fi
+
+	if [ "$3" -eq 0 ]; then
+		if [ -s "${TEMP_FILE}" ]; then
+			MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
+			MSG="${MSG} Messages produced on stderr unexpected..."
+			MSG="${MSG}${nl}$( cat "${TEMP_FILE}" )"
+			fail=true
+		fi
+	else
+		if ! [ -s "${TEMP_FILE}" ]; then
+			MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
+			MSG="${MSG} Expected messages on stderr,"
+			MSG="${MSG} nothing produced"
+			fail=true
+		fi
+	fi
+	rm -f "${TEMP_FILE}"
+
+	# Remove newlines (use local shell for this)
+	oifs="$IFS"
+	IFS="$nl"
+	result="$(echo $result)"
+	IFS="$oifs"
+	if [ "$2" != "$result" ]
+	then
+		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
+		MSG="${MSG} Expected output '$2', received '$result'"
+		fail=true
+	fi
+
+	if $fail
+	then
+		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
+		MSG="${MSG} Full command: <<${CMD}>>"
+	fi
+
+	$fail && test -n "$TEST_ID" && {
+		TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+${nl}}"
+		TEST_FAILURES="${TEST_FAILURES}${TEST_ID}[$TEST_NUM]:"
+		TEST_FAILURES="${TEST_FAILURES} Test of '$1' failed.";
+		TEST_FAILURES="${TEST_FAILURES}${nl}${MSG}"
+		TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
+		return 0
+	}
+	$fail && atf_fail "Test[$TEST_NUM] of '$1' failed${nl}${MSG}"
+	return 0
+}
+
+results()
+{
+	test -z "${TEST_ID}" && return 0
+	test -z "${TEST_FAILURES}" && return 0
+
+	echo >&2 "=="
+	echo >&2 "While testing '${TEST_ID}'"
+	echo >&2 " - - - - - - - - - - - - - - - - -"
+	echo >&2 "${TEST_FAILURES}"
+	atf_fail \
+ "Test ${TEST_ID}: $TEST_FAIL_COUNT subtests (of $TEST_NUM) failed - see stderr"
+}
+
+atf_test_case shell_params
+shell_params_head() {
+	atf_set "descr" "Test correct operation of the numeric parameters"
+}
+shell_params_body() {
+	atf_require_prog mktemp
+
+	reset shell_params
+
+	check 'set -- a b c; echo "$#: $1 $2 $3"' '3: a b c' 0
+	check 'set -- a b c d e f g h i j k l m; echo "$#: ${1}0 ${10} $10"' \
+		'13: a0 j a0' 0
+	check 'x="$0"; set -- a b; y="$0";
+	  [ "x${x}y" = "x${y}y" ] && echo OK || echo x="$x" y="$y"' \
+		'OK' 0
+	check "${TEST_SH} -c 'echo 0=\$0 1=\$1 2=\$2' a b c" '0=a 1=b 2=c' 0
+
+	echo 'echo 0="$0" 1="$1" 2="$2"' > helper.sh
+	check '${TEST_SH} helper.sh a b c' '0=helper.sh 1=a 2=b' 0
+
+	check 'set -- a bb ccc  e ff ggg  \
+		i jj kkk
+	   echo "${#}: ${#1} ${#2} ${#3} ${#4} ... ${#9} ${#10} ${#11}"' \
+		 '11: 1 2 3 4 ... 9 10 11' 0
+
+	check 'set -- a b c; echo "$#: ${1-A} ${2-B} ${3-C} ${4-D} ${5-E}"' \
+		'3: a b c D E' 0
+	check 'set -- a "" c "" e
+	   echo "$#: ${1:-A} ${2:-B} ${3:-C} ${4:-D} ${5:-E}"' \
+		'5: a B c D e' 0
+	check 'set -- a "" c "" e
+	   echo "$#: ${1:+A} ${2:+B} ${3:+C} ${4:+D} ${5:+E}"' \
+		'5: A  C  E' 0
+	check 'set -- "abab*cbb"
+	   echo "${1} ${1#a} ${1%b} ${1##ab} ${1%%b} ${1#*\*} ${1%\**}"' \
+	   'abab*cbb bab*cbb abab*cb ab*cbb abab*cb cbb abab' 0
+	check 'set -- "abab?cbb"
+echo "${1}:${1#*a}+${1%b*}-${1##*a}_${1%%b*}%${1#[ab]}=${1%?*}/${1%\?*}"' \
+	   'abab?cbb:bab?cbb+abab?cb-b?cbb_a%bab?cbb=abab?cb/abab' 0
+	check 'set -- a "" c "" e; echo "${2:=b}"' '' 1
+
+	results
+}
+
 atf_init_test_cases() {
 	

CVS commit: src/tests/bin/sh

2016-03-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 31 16:19:52 UTC 2016

Modified Files:
src/tests/bin/sh: t_arith.sh

Log Message:
Don't confuse more capable shells by writing operator combinations
that could be interpreted as something different. That is, for our
shell +4++3 is just (+4)+(+3) and works fine. But others treat ++
as the increment operator.  Same for --. Sprinkle spaces to taste.
(from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_arith.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_arith.sh
diff -u src/tests/bin/sh/t_arith.sh:1.2 src/tests/bin/sh/t_arith.sh:1.3
--- src/tests/bin/sh/t_arith.sh:1.2	Wed Mar 16 13:39:12 2016
+++ src/tests/bin/sh/t_arith.sh	Thu Mar 31 12:19:52 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_arith.sh,v 1.2 2016/03/16 17:39:12 christos Exp $
+# $NetBSD: t_arith.sh,v 1.3 2016/03/31 16:19:52 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -280,9 +280,9 @@ elementary_add_body()
 	atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
 		'echo $((++))'
 	atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
-		'echo $((+++))'
+		'echo $((+ + +))'
 	atf_check -s exit:0 -o inline:'-\n' -e empty ${TEST_SH} -c \
-		'echo -$((+4125++3652))'
+		'echo -$((+4125+ +3652))'
 }
 
 atf_test_case elementary_sub
@@ -311,7 +311,7 @@ elementary_sub_body()
 	atf_check -s exit:0 -o inline:'-7694\n' -e empty ${TEST_SH} -c \
 		'echo $(( -2016-5678 ))'
 	atf_check -s exit:0 -o inline:'--1\n' -e empty ${TEST_SH} -c \
-		'echo -$(( -1018--1017 ))'
+		'echo -$(( -1018 - -1017 ))'
 }
 
 atf_test_case elementary_mul



CVS commit: src/tests/bin/sh/dotcmd

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:57:50 UTC 2016

Modified Files:
src/tests/bin/sh/dotcmd: Makefile scoped_command t_dotcmd.sh

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


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/dotcmd/Makefile
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/dotcmd/scoped_command \
src/tests/bin/sh/dotcmd/t_dotcmd.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/dotcmd/Makefile
diff -u src/tests/bin/sh/dotcmd/Makefile:1.2 src/tests/bin/sh/dotcmd/Makefile:1.3
--- src/tests/bin/sh/dotcmd/Makefile:1.2	Sun Jul 27 10:24:17 2014
+++ src/tests/bin/sh/dotcmd/Makefile	Sun Mar 27 10:57:50 2016
@@ -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 
@@ -7,6 +7,10 @@ TESTSDIR = ${TESTSBASE}/bin/sh/dotcmd
 
 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 @@ FILESDIR_${cmd}_${cmd_scope} = ${TESTSDI
 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 @@ FILESBUILD_${dot_scope}_${cmd}_${cmd_sco
 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

Index: src/tests/bin/sh/dotcmd/scoped_command
diff -u src/tests/bin/sh/dotcmd/scoped_command:1.1 src/tests/bin/sh/dotcmd/scoped_command:1.2
--- src/tests/bin/sh/dotcmd/scoped_command:1.1	Sat May 31 10:29:06 2014
+++ src/tests/bin/sh/dotcmd/scoped_command	Sun Mar 27 10:57:50 2016
@@ -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 @@ cmd="echo 'before ${3}'
 ${2}
 echo 'after ${3}, return value:' ${?}"
 
-echo "#!/bin/sh"
+echo "#!${TEST_SH}"
 
 [ 'func' = "${1}" ] && cat <

CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:53:17 UTC 2016

Modified Files:
src/tests/bin/sh: t_cmdsub.sh

Log Message:
Finish these tests (or at least, fill in the place holder tests
with actual code ... tests are never really finished.)  One of these
new tests was how the bug in PR bin/50993 was discovered. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_cmdsub.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_cmdsub.sh
diff -u src/tests/bin/sh/t_cmdsub.sh:1.1 src/tests/bin/sh/t_cmdsub.sh:1.2
--- src/tests/bin/sh/t_cmdsub.sh:1.1	Sun Mar 20 18:57:04 2016
+++ src/tests/bin/sh/t_cmdsub.sh	Sun Mar 27 10:53:17 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_cmdsub.sh,v 1.1 2016/03/20 22:57:04 christos Exp $
+# $NetBSD: t_cmdsub.sh,v 1.2 2016/03/27 14:53:17 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -181,6 +181,9 @@ f_redirect_in_cmdsub_head() {
 	atf_set "descr" "Checks that redirects work in command substitutions"
 }
 f_redirect_in_cmdsub_body() {
+	atf_require_prog cat
+	atf_require_prog rm
+
 	rm -f file 2>/dev/null || :
 	atf_check -s exit:0 -o match:'_aa_' -e empty \
 	${TEST_SH} -c 'echo _$( echo a$( echo b > file )a)_'
@@ -199,6 +202,9 @@ g_redirect_in_backticks_head() {
 	atf_set "descr" "Checks that redirects work in old style cmd sub"
 }
 g_redirect_in_backticks_body() {
+	atf_require_prog cat
+	atf_require_prog rm
+
 	rm -f file 2>/dev/null || :
 	atf_check -s exit:0 -o match:'_aa_' -e empty \
 	${TEST_SH} -c 'echo _` echo a\` echo b > file \`a`_'
@@ -371,6 +377,8 @@ p_cmdsub_in_heredoc_head() {
 	atf_set "descr" "Checks that cmdsubs work inside a here document"
 }
 p_cmdsub_in_heredoc_body() {
+	atf_require_prog cat
+
 	atf_check -s exit:0 -o inline:'line 1+1\nline 2\nline 3\n' -e empty \
 	${TEST_SH} -c \
 		'cat <<- EOF
@@ -384,6 +392,8 @@ q_backticks_in_heredoc_head() {
 	atf_set "descr" "Checks that old style cmdsubs work in here docs"
 }
 q_backticks_in_heredoc_body() {
+	atf_require_prog cat
+
 	atf_check -s exit:0 -o inline:'Mary had a\nlittle\nlamb\n' -e empty \
 	${TEST_SH} -c \
 		'cat <<- EOF
@@ -397,6 +407,8 @@ r_heredoc_in_cmdsub_head() {
 	atf_set "descr" "Checks that here docs work inside cmd subs"
 }
 r_heredoc_in_cmdsub_body() {
+	atf_require_prog cat
+
 	atf_check -s exit:0 -o inline:'Mary had a\nlittle\nlamb\n' -e empty \
 	${TEST_SH} -c 'echo "$( cat <<- \EOF
 Mary had a
@@ -422,8 +434,6 @@ r_heredoc_in_cmdsub_body() {
 			EOF
 			)"'
 
-	# not all shells permit this syntax ...
-	# But I see nothing in the standard to prohibit it.
 	atf_check -s exit:0 -o inline:'Line 1\nLine 2\n' -e empty \
 	${TEST_SH} -c 'echo "$( cat <<- "EOF" )"
 Line 1
@@ -437,6 +447,8 @@ s_heredoc_in_backticks_head() {
 	atf_set "descr" "Checks that here docs work inside old style cmd subs"
 }
 s_heredoc_in_backticks_body() {
+	atf_require_prog cat
+
 	atf_check -s exit:0 -o inline:'Mary had a little lamb\n' -e empty \
 	${TEST_SH} -c 'echo ` cat <<- \EOF
 Mary had a
@@ -458,6 +470,26 @@ t_nested_cmdsubs_in_heredoc_head() {
 	atf_set "descr" "Checks nested command substitutions in here docs"
 }
 t_nested_cmdsubs_in_heredoc_body() {
+	atf_require_prog cat
+	atf_require_prog rm
+
+	rm -f * 2>/dev/null || :
+	echo "Hello" > File
+
+	atf_check -s exit:0 -o inline:'Hello U\nHelp me!\n' -e empty \
+	${TEST_SH} -c 'cat <<- EOF
+		$(cat File) U
+		$( V=$(cat File); echo "${V%lo}p" ) me!
+		EOF'
+
+	rm -f * 2>/dev/null || :
+	echo V>V ; echo A>A; echo R>R
+	echo Value>VAR
+
+	atf_check -s exit:0 -o inline:'$2.50\n' -e empty \
+	${TEST_SH} -c 'cat <<- EOF
+	$(Value='\''$2.50'\'';eval echo $(eval $(cat V)$(cat A)$(cat R)=\'\''\$$(cat $(cat V)$(cat A)$(cat R))\'\''; eval echo \$$(set -- *;echo ${3}${1}${2})))
+		EOF'
 }
 
 atf_test_case u_nested_backticks_in_heredoc
@@ -465,6 +497,26 @@ u_nested_backticks_in_heredoc_head() {
 	atf_set "descr" "Checks nested old style cmd subs in here docs"
 }
 u_nested_backticks_in_heredoc_body() {
+	atf_require_prog cat
+	atf_require_prog rm
+
+	rm -f * 2>/dev/null || :
+	echo "Hello" > File
+
+	atf_check -s exit:0 -o inline:'Hello U\nHelp me!\n' -e empty \
+	${TEST_SH} -c 'cat <<- EOF
+		`cat File` U
+		`V=\`cat File\`; echo "${V%lo}p" ` me!
+		EOF'
+
+	rm -f * 2>/dev/null || :
+	echo V>V ; echo A>A; echo R>R
+	echo Value>VAR
+
+	atf_check -s exit:0 -o inline:'$5.20\n' -e empty \
+	${TEST_SH} -c 'cat <<- EOF
+	`Value='\''$5.20'\'';eval echo \`eval \\\`cat V\\\`\\\`cat A\\\`\\\`cat R\\\`=\\\'\''\\\$\\\`cat \\\`cat V\\\`\\\`cat A\\\`\\\`cat R\\\`\\\`\\\'\''; eval echo \\\$\\\`set -- *;echo \${3}\${1}\${2}\\\`\``
+		EOF'
 }
 
 atf_test_case z_absurd_heredoc_cmdsub_combos
@@ -472,6 +524,48 @@ z_absurd_heredoc_cmdsub_combos_head() {
 	atf_set "descr" "perverse and 

CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:52:40 UTC 2016

Modified Files:
src/tests/bin/sh: t_here.sh

Log Message:
PR bin/50993 - lots of new here document tests to validate all of
the changes made to fix that PR.   LOTS more tests...  A few general
improvements to the way the tests work and results are reported
as well. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_here.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_here.sh
diff -u src/tests/bin/sh/t_here.sh:1.4 src/tests/bin/sh/t_here.sh:1.5
--- src/tests/bin/sh/t_here.sh:1.4	Tue Mar  8 09:21:02 2016
+++ src/tests/bin/sh/t_here.sh	Sun Mar 27 10:52:40 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_here.sh,v 1.4 2016/03/08 14:21:02 christos Exp $
+# $NetBSD: t_here.sh,v 1.5 2016/03/27 14:52:40 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -30,21 +30,29 @@
 nl='
 '
 
+reset()
+{
+	TEST_NUM=0
+	TEST_FAILURES=''
+	TEST_FAIL_COUNT=0
+	TEST_ID="$1"
+}
+
 check()
 {
 	fail=false
 	TEMP_FILE=$( mktemp OUT.XX )
+	TEST_NUM=$(( $TEST_NUM + 1 ))
 
 	# our local shell (ATF_SHELL) better do quoting correctly...
 	# some of the tests expect us to expand $nl internally...
 	CMD="nl='${nl}'; $1"
 
-	rm -f trace.*
 	result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
 	STATUS=$?
 
 	if [ "${STATUS}" -ne "$3" ]; then
-		echo >&2 "expected exit code $3, got ${STATUS}"
+		echo >&2 "[$TEST_NUM] expected exit code $3, got ${STATUS}"
 
 		# don't actually fail just because of wrong exit code
 		# unless we either expected, or received "good"
@@ -55,13 +63,15 @@ check()
 
 	if [ "$3" -eq 0 ]; then
 		if [ -s "${TEMP_FILE}" ]; then
-			echo >&2 "Messages produced on stderr unexpected..."
+			echo >&2 \
+			 "[$TEST_NUM] Messages produced on stderr unexpected..."
 			cat "${TEMP_FILE}" >&2
 			fail=true
 		fi
 	else
 		if ! [ -s "${TEMP_FILE}" ]; then
-			echo >&2 "Expected messages on stderr, nothing produced"
+			echo >&2 \
+		"[$TEST_NUM] Expected messages on stderr, nothing produced"
 			fail=true
 		fi
 	fi
@@ -74,14 +84,33 @@ check()
 	IFS="$oifs"
 	if [ "$2" != "$result" ]
 	then
-		echo >&2 "Expected output '$2', received '$result'"
+		echo >&2 "[$TEST_NUM] Expected output '$2', received '$result'"
 		fail=true
 	fi
 
-	$fail && atf_fail "test of '$1' failed"
+	$fail && test -n "$TEST_ID" && {
+		TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+
+}${TEST_ID}[$TEST_NUM]: test of '$1' failed";
+		TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
+		return 0
+	}
+	$fail && atf_fail "Test[$TEST_NUM] of '$1' failed"
 	return 0
 }
 
+results()
+{
+	test -z "${TEST_ID}" && return 0
+	test -z "${TEST_FAILURES}" && return 0
+
+	echo >&2 "=="
+	echo >&2 "While testing '${TEST_ID}'"
+	echo >&2 " - - - - - - - - - - - - - - - - -"
+	echo >&2 "${TEST_FAILURES}"
+	atf_fail \
+ "Test ${TEST_ID}: $TEST_FAIL_COUNT subtests (of $TEST_NUM) failed - see stderr"
+}
+
 atf_test_case do_simple
 do_simple_head() {
 	atf_set "descr" "Basic tests for here documents"
@@ -89,7 +118,8 @@ do_simple_head() {
 do_simple_body() {
 	y=x
 
-	IFS=
+	reset 'simple'
+	IFS=' 	'
 	check 'x=`cat <

CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:50:40 UTC 2016

Modified Files:
src/tests/bin/sh: t_wait.sh

Log Message:
More tests, add protection against shells that allow wait N
to wait for the same process over and over again (forever) (???)
This test now takes slightly over 20 seconds to complete (elapsed
time) caused by all the waiting on sleep commands being run in
the background. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/bin/sh/t_wait.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_wait.sh
diff -u src/tests/bin/sh/t_wait.sh:1.6 src/tests/bin/sh/t_wait.sh:1.7
--- src/tests/bin/sh/t_wait.sh:1.6	Tue Mar  8 09:24:06 2016
+++ src/tests/bin/sh/t_wait.sh	Sun Mar 27 10:50:40 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_wait.sh,v 1.6 2016/03/08 14:24:06 christos Exp $
+# $NetBSD: t_wait.sh,v 1.7 2016/03/27 14:50:40 christos Exp $
 #
 # Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -27,34 +27,115 @@
 # the implementation of "sh" to test
 : ${TEST_SH:="/bin/sh"}
 
+atf_test_case basic_wait
+basic_wait_head() {
+	atf_set "descr" "Tests simple uses of wait"
+}
+basic_wait_body() {
+	atf_require_prog sleep
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'(echo nothing >/dev/null) & wait'
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'(exit 3) & wait $!; S=$?; test $S -eq 3 || {
+			echo "status: $S"; exit 1; }'
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'sleep 3 & sleep 2 & sleep 1 & wait'
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'sleep 3 & (exit 2) & sleep 1 & wait'
+}
+
 atf_test_case individual
 individual_head() {
-	atf_set "descr" "Tests that waiting for individual jobs works"
+	atf_set "descr" "Tests that waiting for individual processes works"
 }
 individual_body() {
+	atf_require_prog sleep
+
+	cat >individualhelper.sh <<\EOF
+sleep 3 & P1=$!
+sleep 1 & P2=$!
+
+wait ${P1}
+S=$?
+if [ $S -ne 0 ]; then
+echo "Waiting for first process failed: $S"
+exit 1
+fi
+
+wait ${P2}
+S=$?
+if [ $? -ne 0 ]; then
+echo "Waiting for second process failed"
+exit 1
+fi
+
+exit 0
+EOF
+	output=$(${TEST_SH} individualhelper.sh 2>&1)
+	[ $? -eq 0 ] || atf_fail "${output}"
+}
+
+atf_test_case jobs
+jobs_head() {
+	atf_set "descr" "Tests that waiting for individual jobs works"
+}
+jobs_body() {
 	# atf-sh confuses wait for some reason; work it around by creating
 	# a helper script that executes /bin/sh directly.
+
+	if ! ${TEST_SH} -c 'sleep 1 & wait %1' 2>/dev/null
+	then
+		atf_skip "No job control support in this shell"
+	fi
+
 	cat >individualhelper.sh <<\EOF
 sleep 3 &
 sleep 1 &
 
 wait %1
 if [ $? -ne 0 ]; then
-echo "Waiting of first job failed"
+echo "Waiting for first job failed"
 exit 1
 fi
 
 wait %2
 if [ $? -ne 0 ]; then
-echo "Waiting of second job failed"
+echo "Waiting for second job failed"
 exit 1
 fi
 
 exit 0
 EOF
-	output=$("${TEST_SH}" individualhelper.sh)
+	output=$(${TEST_SH} individualhelper.sh 2>&1)
+	[ $? -eq 0 ] || atf_fail "${output}"
+
+	cat >individualhelper.sh <<\EOF
+{ sleep 3; exit 3; } &
+{ sleep 1; exit 7; } &
+
+wait %1
+S=$?
+if [ $S -ne 3 ]; then
+echo "Waiting for first job failed - status: $S != 3 (expected)"
+exit 1
+fi
+
+wait %2
+S=$?
+if [ $S -ne 7 ]; then
+echo "Waiting for second job failed - status: $S != 7 (expected)"
+exit 1
+fi
+
+exit 0
+EOF
+
+	output=$(${TEST_SH} individualhelper.sh 2>&1)
 	[ $? -eq 0 ] || atf_fail "${output}"
-	rm -f individualhelper.sh
 }
 
 atf_test_case kill
@@ -62,39 +143,53 @@ kill_head() {
 	atf_set "descr" "Tests that killing the shell while in wait calls trap"
 }
 kill_body() {
-	# atf-sh confuses wait for some reason; work it around by creating
-	# a helper script that executes /bin/sh directly.
-	local s=$PWD/killhelper.sh
-	local z=/tmp/killhelper.$$ 
-	local pid=
+	atf_require_prog sleep
+	atf_require_prog kill
+
+	s=killhelper.sh
+	z=/tmp/killhelper.$$ 
+	pid=
+
+	# waiting for a specific process that is not a child
+	# should return exit status of 127 according to the spec
+	# This test is here before the next, to avoid that one
+	# entering an infinite loop should the shell have a bug here.
+
+	atf_check -s exit:127 -o empty -e ignore ${TEST_SH} -c 'wait 1'
+
+	cat > "${s}" <<'EOF'
 
-	sed 's!${SH}!'"${TEST_SH}!"  >$s <<\EOF
-#! ${SH}
 trap "echo SIGHUP" 1
 (sleep 5; exit 3) &
 sl=$!
 wait
 S=$?
 echo $S
-while [ $S -ne 0 ] && [ $S != 127 ]; do wait $sl; S=$?; echo $S; done
+LS=
+while [ $S -ne 0 ] && [ $S != 127 ]; do
+	wait $sl; S=$?; echo $S
+	test $S = $LS && { echo "wait repeats..."; exit 2; }
+	LS=$S
+	done
 EOF
-	chmod +x $s
 
-	$s > $z &
+	${TEST_SH} $s > $z &
 	pid=$!
 	sleep 1
 
-	kill -HUP $pid
+	kill -HUP "${pid}"
 	wait
 
 	output="$(cat $z | tr '\n' ' ')"
-	rm -f $s $z
+
 	if [ 

CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:50:01 UTC 2016

Modified Files:
src/tests/bin/sh: t_evaltested.sh t_fsplit.sh t_set_e.sh t_ulimit.sh
t_varquote.sh

Log Message:
Finish TEST_SH - all tests should support it now.
Misc other KNF changes, minor bug fixes, and a few minor
extra tests added. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_evaltested.sh
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_fsplit.sh
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_set_e.sh \
src/tests/bin/sh/t_ulimit.sh
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_varquote.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_evaltested.sh
diff -u src/tests/bin/sh/t_evaltested.sh:1.1 src/tests/bin/sh/t_evaltested.sh:1.2
--- src/tests/bin/sh/t_evaltested.sh:1.1	Sat Mar 17 12:33:11 2012
+++ src/tests/bin/sh/t_evaltested.sh	Sun Mar 27 10:50:01 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_evaltested.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
+# $NetBSD: t_evaltested.sh,v 1.2 2016/03/27 14:50:01 christos Exp $
 #
 # Copyright (c) 2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -24,6 +24,8 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
 
 atf_test_case evaltested
 
@@ -43,7 +45,7 @@ fi
 echo "passed"
 exit 0
 EOF
-	output="$(/bin/sh helper.sh)"
+	output="$($TEST_SH helper.sh)"
 	[ $? = 0 ] && return
 
 	if [ -n "$output" ]

Index: src/tests/bin/sh/t_fsplit.sh
diff -u src/tests/bin/sh/t_fsplit.sh:1.3 src/tests/bin/sh/t_fsplit.sh:1.4
--- src/tests/bin/sh/t_fsplit.sh:1.3	Thu Mar 10 17:30:57 2016
+++ src/tests/bin/sh/t_fsplit.sh	Sun Mar 27 10:50:01 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_fsplit.sh,v 1.3 2016/03/10 22:30:57 christos Exp $
+# $NetBSD: t_fsplit.sh,v 1.4 2016/03/27 14:50:01 christos Exp $
 #
 # Copyright (c) 2007-2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -294,6 +294,11 @@ dollar_at_body() {
 		'zaz zbz zcz'
 	check 'set " a b " c; for i in "$@";do echo "z${i}z"; done' \
 		'z a b z zcz'
+
+	check 'set a b c; for i in "$@$@";  do echo "z${i}z"; done' \
+		'zaz zbz zcaz zbz zcz'
+	check 'set a b c; for i in "$@""$@";do echo "z${i}z"; done' \
+		'zaz zbz zcaz zbz zcz'
 }
 
 atf_test_case ifs

Index: src/tests/bin/sh/t_set_e.sh
diff -u src/tests/bin/sh/t_set_e.sh:1.2 src/tests/bin/sh/t_set_e.sh:1.3
--- src/tests/bin/sh/t_set_e.sh:1.2	Tue Mar  8 09:20:22 2016
+++ src/tests/bin/sh/t_set_e.sh	Sun Mar 27 10:50:01 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_set_e.sh,v 1.2 2016/03/08 14:20:22 christos Exp $
+# $NetBSD: t_set_e.sh,v 1.3 2016/03/27 14:50:01 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -81,8 +81,8 @@ all_body() {
 	# first, check basic functioning.
 	# The ERR shouldn't print; the result of the () should be 1.
 	# Henceforth we'll assume that we don't need to check $?.
-	dcheck '(set -e; false; echo ERR$?); echo -n OK$?' 'OK1'
-	echeck '(set -e; false; echo ERR$?); echo -n OK$?' 'OK1'
+	dcheck '(set -e; false; echo ERR$?); echo OK$?' 'OK1'
+	echeck '(set -e; false; echo ERR$?); echo OK$?' 'OK1'
 
 	# these cases should be equivalent to the preceding.
 	dcheck '(set -e; /nonexistent; echo ERR); echo OK' 'OK'
Index: src/tests/bin/sh/t_ulimit.sh
diff -u src/tests/bin/sh/t_ulimit.sh:1.2 src/tests/bin/sh/t_ulimit.sh:1.3
--- src/tests/bin/sh/t_ulimit.sh:1.2	Wed Dec 30 17:24:44 2015
+++ src/tests/bin/sh/t_ulimit.sh	Sun Mar 27 10:50:01 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_ulimit.sh,v 1.2 2015/12/30 22:24:44 christos Exp $
+# $NetBSD: t_ulimit.sh,v 1.3 2016/03/27 14:50:01 christos Exp $
 #
 # Copyright (c) 2012 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -24,6 +24,8 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
 
 # ulimit builtin test.
 
@@ -33,7 +35,7 @@ limits_head() {
 }
 
 get_ulimits() {
-	local limits=$(ulimit -a |
+	local limits=$(${TEST_SH} -c 'ulimit -a' |
 	sed -e 's/.*\(-[A-Za-z0-9]\)[^A-Za-z0-9].*/\1/' | sort -u)
 	if [ -z "$limits" ]; then
 		# grr ksh
@@ -43,12 +45,10 @@ get_ulimits() {
 }
 
 limits_body() {
-	atf_check -s eq:0 -o ignore -e empty \
-	/bin/sh -c "ulimit -a"
+	atf_check -s eq:0 -o ignore -e empty ${TEST_SH} -c "ulimit -a"
 	for l in $(get_ulimits)
 	do
-	atf_check -s eq:0 -o ignore -e empty \
-	/bin/sh -c "ulimit $l"
+	atf_check -s eq:0 -o ignore -e empty ${TEST_SH} -c "ulimit $l"
 	done
 }
 

Index: src/tests/bin/sh/t_varquote.sh
diff -u src/tests/bin/sh/t_varquote.sh:1.4 src/tests/bin/sh/t_varquote.sh:1.5
--- src/tests/bin/sh/t_varquote.sh:1.4	Sat Mar 12 09:58:03 2016
+++ src/tests/bin/sh/t_varquote.sh	Sun Mar 27 10:50:01 2016
@@ -1,4 +1,4 @@
-# 

CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:49:07 UTC 2016

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
Avoid relying on the test shell correctly implementing $(( ))
in order for some of the redirect tests to terminate. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.4 src/tests/bin/sh/t_redir.sh:1.5
--- src/tests/bin/sh/t_redir.sh:1.4	Tue Mar  8 09:26:54 2016
+++ src/tests/bin/sh/t_redir.sh	Sun Mar 27 10:49:07 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.4 2016/03/08 14:26:54 christos Exp $
+# $NetBSD: t_redir.sh,v 1.5 2016/03/27 14:49:07 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -122,9 +122,7 @@ do_input_redirections_body()
 
 
 	cat <<- 'EOF' |
-		i=0
-		while [ "$i" -lt 3 ]; do
-			i=$((i + 1))
+		for l in 1 2 3; do
 			read line < File
 			echo "$line"
 		done
@@ -134,9 +132,7 @@ do_input_redirections_body()
 		${TEST_SH}
 
 	cat <<- 'EOF' |
-		i=0
-		while [ "$i" -lt 3 ]; do
-			i=$((i + 1))
+		for l in 1 2 3; do
 			read line
 			echo "$line"
 		done /dev/null || :
 	test -f Output && atf_fail "Unable to remove Output file"



CVS commit: src/tests/bin/sh

2016-03-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 20 22:57:04 UTC 2016

Modified Files:
src/tests/bin/sh: Makefile
Added Files:
src/tests/bin/sh: t_cmdsub.sh

Log Message:
new command substitution test from kre


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/bin/sh/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/bin/sh/t_cmdsub.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/Makefile
diff -u src/tests/bin/sh/Makefile:1.10 src/tests/bin/sh/Makefile:1.11
--- src/tests/bin/sh/Makefile:1.10	Wed Mar 16 17:13:51 2016
+++ src/tests/bin/sh/Makefile	Sun Mar 20 18:57:04 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.10 2016/03/16 21:13:51 christos Exp $
+# $NetBSD: Makefile,v 1.11 2016/03/20 22:57:04 christos Exp $
 #
 
 .include 
@@ -8,6 +8,7 @@ TESTSDIR = ${TESTSBASE}/bin/sh
 TESTS_SUBDIRS += dotcmd
 
 TESTS_SH+=	t_arith
+TESTS_SH+=	t_cmdsub
 TESTS_SH+=	t_evaltested
 TESTS_SH+=	t_exit
 TESTS_SH+=	t_expand

Added files:

Index: src/tests/bin/sh/t_cmdsub.sh
diff -u /dev/null src/tests/bin/sh/t_cmdsub.sh:1.1
--- /dev/null	Sun Mar 20 18:57:04 2016
+++ src/tests/bin/sh/t_cmdsub.sh	Sun Mar 20 18:57:04 2016
@@ -0,0 +1,500 @@
+# $NetBSD: t_cmdsub.sh,v 1.1 2016/03/20 22:57:04 christos Exp $
+#
+# Copyright (c) 2016 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
+
+#
+# This file tests command substitutions ( `...` and $( ... ) )
+#
+# CAUTION:
+#	Be careful attempting running these tests outside the ATF environment
+#	Some of the tests run "rm *" in the current directory to clean up
+#	An ATF test directory should be empty already, outside ATF, anything
+
+atf_test_case a_basic_cmdsub
+a_basic_cmdsub_head() {
+	atf_set "descr" 'Test operation of simple $( ) substitutions'
+}
+a_basic_cmdsub_body() {
+	atf_check -s exit:0 -o match:'Result is true today' -e empty \
+	${TEST_SH} -c \
+		'echo Result is $( true && echo true || echo false ) today'
+
+	atf_check -s exit:0 -o match:'Result is false today' -e empty \
+	${TEST_SH} -c \
+		'echo Result is $( false && echo true || echo false ) today'
+
+	atf_check -s exit:0 -o match:'aaabbbccc' -e empty \
+	${TEST_SH} -c 'echo aaa$( echo bbb )ccc'
+	atf_check -s exit:0 -o match:'aaabbb cccddd' -e empty \
+	${TEST_SH} -c 'echo aaa$( echo bbb ccc )ddd'
+	atf_check -s exit:0 -o inline:'aaabbb cccddd\n' -e empty \
+	${TEST_SH} -c 'echo aaa$( echo bbb; echo ccc )ddd'
+	atf_check -s exit:0 -o inline:'aaabbb\ncccddd\n' -e empty \
+	${TEST_SH} -c 'echo "aaa$( echo bbb; echo ccc )ddd"'
+
+	atf_check -s exit:0 -o inline:'some string\n' -e empty \
+	${TEST_SH} -c 'X=$( echo some string ); echo "$X"'
+	atf_check -s exit:0 -o inline:'weird; string *\n' -e empty \
+	${TEST_SH} -c 'X=$( echo "weird; string *" ); echo "$X"'
+
+	rm -f * 2>/dev/null || :
+	for f in file-1 file-2
+	do
+		cp /dev/null "$f"
+	done
+
+	atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
+	${TEST_SH} -c 'echo Found $( echo * )'
+	atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
+	${TEST_SH} -c 'echo Found "$( echo * )"'
+	atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
+	${TEST_SH} -c 'echo Found $('" echo '*' )"
+	atf_check -s exit:0 -o match:'Found \*' -e empty \
+	${TEST_SH} -c 'echo Found "$('" echo '*' "')"'
+	atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
+	${TEST_SH} -c 'echo Found $('" echo \\* )"
+	atf_check -s exit:0 -o match:'Found \*' -e empty \
+	${TEST_SH} -c 'echo Found "$('" echo \\* )"\"

CVS commit: src/tests/bin/sh

2016-03-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 16 17:39:12 UTC 2016

Modified Files:
src/tests/bin/sh: t_arith.sh

Log Message:
remove binary test and other cleanups (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_arith.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_arith.sh
diff -u src/tests/bin/sh/t_arith.sh:1.1 src/tests/bin/sh/t_arith.sh:1.2
--- src/tests/bin/sh/t_arith.sh:1.1	Wed Mar 16 11:49:19 2016
+++ src/tests/bin/sh/t_arith.sh	Wed Mar 16 13:39:12 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_arith.sh,v 1.1 2016/03/16 15:49:19 christos Exp $
+# $NetBSD: t_arith.sh,v 1.2 2016/03/16 17:39:12 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -28,10 +28,10 @@
 : ${TEST_SH:="/bin/sh"}
 
 # Requirement is to support at least "signed long" whatever that means
-# (number of bits in "long" is not specified - but should be at lease 32).
+# (number of bits in "long" is not specified - but should be at least 32).
 
 # These tests use -o inline:"..." rather than -o match:'...' as we have
-# only digits to examine, and it is good to be sure that 1 + 2 really gives 2
+# only digits to examine, and it is good to be sure that 1 + 1 really gives 2
 # and that 42 or 123 don't look like success because there is a 2 in them.
 
 ARITH_BITS='?'
@@ -64,7 +64,6 @@ discover_range()
 	if ! ${TEST_SH} -c ': $(( 0xC000 ))' 2>/dev/null
 	then
 		# proobably shell detected overflow and complained
-		# (if it does not support hex, we will discover that later)
 		ARITH_BITS=32
 		return
 	fi
@@ -170,31 +169,6 @@ constants_body()
 	# 	${TEST_SH} -c 'echo $(( UNDEFINED_VAR ))'
 }
 
-atf_test_case constants_binary
-constants_binary_head()
-{
-atf_set "descr" "Optional tests that binary constants work as expected"
-}
-constants_binary_body()
-{
-	if ! ${TEST_SH} -c '[ $(( 0b0101 )) = 5 ]' 2>/dev/null
-	then
-		atf_skip "Binary constants (0b0101) not implemented"
-	fi
-
-	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
-		'echo $((0b0))'
-	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
-		'echo $((0b01))'
-	atf_check -s exit:0 -o inline:'3\n' -e empty ${TEST_SH} -c \
-		'echo $((0b11))'
-	atf_check -s exit:0 -o inline:'7\n' -e empty ${TEST_SH} -c \
-		'echo $((0b111))'
-	atf_check -s exit:0 -o inline:'1398101\n' -e empty ${TEST_SH} -c \
-		'echo $(( 0b101010101010101010101 ))'
-	atf_check -s exit:0 -o inline:'119097103\n' -e empty ${TEST_SH} -c \
-		'echo $(( 0b1110001100101000111 ))'
-}
 
 atf_test_case do_unary_plus
 do_unary_plus_head()
@@ -453,7 +427,7 @@ elementary_rem_body()
 atf_test_case elementary_shl
 elementary_shl_head()
 {
-atf_set "descr" "Tests that simple modulus works as expected"
+atf_set "descr" "Tests that simple shift left works as expected"
 }
 elementary_shl_body()
 {
@@ -487,7 +461,7 @@ elementary_shl_body()
 atf_test_case elementary_shr
 elementary_shr_head()
 {
-atf_set "descr" "Tests that simple modulus works as expected"
+atf_set "descr" "Tests that simple shift right works as expected"
 }
 elementary_shr_body()
 {
@@ -798,7 +772,7 @@ fiddle_bits_xor_body()
 atf_test_case logical_and
 logical_and_head()
 {
-	atf_set "descr" "Test bitwise and operations in arithmetic expressions"
+	atf_set "descr" "Test logical and operations in arithmetic expressions"
 }
 logical_and_body()
 {
@@ -822,7 +796,7 @@ logical_and_body()
 atf_test_case logical_or
 logical_or_head()
 {
-	atf_set "descr" "Test bitwise or operations in arithmetic expressions"
+	atf_set "descr" "Test logical or operations in arithmetic expressions"
 }
 logical_or_body()
 {
@@ -1021,7 +995,6 @@ atf_init_test_cases() {
 	# odd names are to get atf's sort order semi-rational
 
 	atf_add_test_case constants
-	atf_add_test_case constants_binary
 	atf_add_test_case do_unary_plus
 	atf_add_test_case do_unary_minus
 	atf_add_test_case do_unary_not



CVS commit: src/tests/bin/sh

2016-03-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 16 15:49:20 UTC 2016

Modified Files:
src/tests/bin/sh: Makefile
Added Files:
src/tests/bin/sh: t_arith.sh t_varval.sh

Log Message:
New tests from kre


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/bin/sh/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/bin/sh/t_arith.sh \
src/tests/bin/sh/t_varval.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/Makefile
diff -u src/tests/bin/sh/Makefile:1.8 src/tests/bin/sh/Makefile:1.9
--- src/tests/bin/sh/Makefile:1.8	Sun Mar 13 14:55:12 2016
+++ src/tests/bin/sh/Makefile	Wed Mar 16 11:49:19 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.8 2016/03/13 18:55:12 christos Exp $
+# $NetBSD: Makefile,v 1.9 2016/03/16 15:49:19 christos Exp $
 #
 
 .include 
@@ -7,9 +7,10 @@ TESTSDIR = ${TESTSBASE}/bin/sh
 
 TESTS_SUBDIRS += dotcmd
 
+TESTS_SH+=	t_arith
+TESTS_SH+=	t_evaltested
 TESTS_SH+=	t_exit
 TESTS_SH+=	t_expand
-TESTS_SH+=	t_evaltested
 TESTS_SH+=	t_fsplit
 TESTS_SH+=	t_here
 TESTS_SH+=	t_option
@@ -18,6 +19,7 @@ TESTS_SH+=	t_redircloexec
 TESTS_SH+=	t_set_e
 TESTS_SH+=	t_ulimit
 TESTS_SH+=	t_varquote
+TESTS_SH+=	t_varval
 TESTS_SH+=	t_wait
 
 .include 

Added files:

Index: src/tests/bin/sh/t_arith.sh
diff -u /dev/null src/tests/bin/sh/t_arith.sh:1.1
--- /dev/null	Wed Mar 16 11:49:20 2016
+++ src/tests/bin/sh/t_arith.sh	Wed Mar 16 11:49:19 2016
@@ -0,0 +1,1055 @@
+# $NetBSD: t_arith.sh,v 1.1 2016/03/16 15:49:19 christos Exp $
+#
+# Copyright (c) 2016 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
+
+# Requirement is to support at least "signed long" whatever that means
+# (number of bits in "long" is not specified - but should be at lease 32).
+
+# These tests use -o inline:"..." rather than -o match:'...' as we have
+# only digits to examine, and it is good to be sure that 1 + 2 really gives 2
+# and that 42 or 123 don't look like success because there is a 2 in them.
+
+ARITH_BITS='?'
+discover_range()
+{
+	# cannot use arithmetic "test" operators, range of test in
+	# ATF_SHELL (or even TEST_SH) might not be as big as that
+	# supported by $(( )) in TEST_SH
+
+	if ! ${TEST_SH} -c ': $(( 0x1 ))' 2>/dev/null
+	then
+		# 16 bits or less, or hex unsupported, just give up...
+		return
+	fi
+	test $( ${TEST_SH} -c 'echo $(( 0x1 ))' ) = 131071 || return
+
+	# when attempting to exceed the number of available bits
+	# the shell may react in any of 3 (rational) ways
+	# 1. syntax error (maybe even core dump...) and fail
+	# 2. represent a positive number input as negative value
+	# 3. keep the number positive, but not the value expected
+	#(perhaps pegged at the max possible value)
+	# any of those may be accompanied by a message to stderr
+
+	# Must check all 3 possibilities for each plausible size
+	# Tests do not use 0x8000... because that value can have weird
+	# other side effects that are not relevant to discover here.
+	# But we do want to try and force the sign bit set.
+
+	if ! ${TEST_SH} -c ': $(( 0xC000 ))' 2>/dev/null
+	then
+		# proobably shell detected overflow and complained
+		# (if it does not support hex, we will discover that later)
+		ARITH_BITS=32
+		return
+	fi
+	if ${TEST_SH} 2>/dev/null \
+	-c 'case $(( 0xC000 )); in (-*) exit 0;; esac; exit 1'
+	then
+		ARITH_BITS=32
+		return
+	fi
+	if ${TEST_SH} -c '[ $(( 0xC000 )) != 3221225472 ]' 2>/dev/null
+	then
+		ARITH_BITS=32
+		return
+	fi
+
+	if ! ${TEST_SH} -c ': $(( 0xC000 ))' 2>/dev/null
+	then
+		

CVS commit: src/tests/bin/sh

2016-03-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 16 21:13:51 UTC 2016

Modified Files:
src/tests/bin/sh: Makefile t_redircloexec.sh

Log Message:
Better tests for redircloexec and add t_shift (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/bin/sh/Makefile
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_redircloexec.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/Makefile
diff -u src/tests/bin/sh/Makefile:1.9 src/tests/bin/sh/Makefile:1.10
--- src/tests/bin/sh/Makefile:1.9	Wed Mar 16 11:49:19 2016
+++ src/tests/bin/sh/Makefile	Wed Mar 16 17:13:51 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.9 2016/03/16 15:49:19 christos Exp $
+# $NetBSD: Makefile,v 1.10 2016/03/16 21:13:51 christos Exp $
 #
 
 .include 
@@ -17,6 +17,7 @@ TESTS_SH+=	t_option
 TESTS_SH+=	t_redir
 TESTS_SH+=	t_redircloexec
 TESTS_SH+=	t_set_e
+TESTS_SH+=	t_shift
 TESTS_SH+=	t_ulimit
 TESTS_SH+=	t_varquote
 TESTS_SH+=	t_varval

Index: src/tests/bin/sh/t_redircloexec.sh
diff -u src/tests/bin/sh/t_redircloexec.sh:1.1 src/tests/bin/sh/t_redircloexec.sh:1.2
--- src/tests/bin/sh/t_redircloexec.sh:1.1	Sun Mar 13 14:55:12 2016
+++ src/tests/bin/sh/t_redircloexec.sh	Wed Mar 16 17:13:51 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_redircloexec.sh,v 1.1 2016/03/13 18:55:12 christos Exp $
+# $NetBSD: t_redircloexec.sh,v 1.2 2016/03/16 21:13:51 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -31,25 +31,21 @@
 : ${TEST_SH:="/bin/sh"}
 
 mkhelper() {
-	local name="$1"
-	local fd="$2"
+	name=$1
+	fd=$2
 	shift 2
-	(echo "#!${TEST_SH}"; echo "$@") > ./"$name"1
-	(echo "#!${TEST_SH}"; echo "echo $name"2 ">&$fd") > ./"$name"2
-	chmod +x ./"$name"1 ./"$name"2
+
+	echo "$@" > ./"${name}1"
+	echo "echo ${name}2" ">&${fd}" > ./"${name}2"
 }
 
 runhelper() {
-	local name="$1"
-	shift
-
-	"./$name"1
+	${TEST_SH} "./${1}1"
 }
 
 cleanhelper() {
-	local name="$1"
-	shift
-	rm -f ./"$name"1 ./"$name"2
+	# not really needed, atf cleans up...
+	rm -f ./"${1}1" ./"${1}2" out
 }
 
 atf_test_case exec_redir_closed
@@ -57,11 +53,32 @@ exec_redir_closed_head() {
 	atf_set "descr" "Tests that redirections created by exec are closed on exec"
 }
 exec_redir_closed_body() {
-	mkhelper exec 6 "exec 6> out; echo exec1 >&6; ./exec2; exec 6>&-"
-	atf_check -s exit:0 \
-		-o empty \
-		-e match:"./exec2: 6: Bad file descriptor" \
-		./exec1
+
+	mkhelper exec 6 \
+		"exec 6> out; echo exec1 >&6; ${TEST_SH} exec2; exec 6>&-"
+
+	atf_check -s exit:0 -o empty -e not-empty ${TEST_SH} ./exec1
+	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -e ./exec1
+
+	mkhelper exec 9 \
+		"exec 9> out; echo exec1 >&9; ${TEST_SH} exec2"
+
+	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} ./exec1
+
+	mkhelper exec 8 \
+		"exec 8> out; printf OK; echo exec1 >&8;" \
+		"printf OK; ${TEST_SH} exec2; printf ERR"
+
+	atf_check -s not-exit:0 -o match:OKOK -o not-match:ERR -e not-empty \
+		${TEST_SH} -e ./exec1
+
+	mkhelper exec 7 \
+		"exec 7> out; printf OK; echo exec1 >&7;" \
+		"printf OK; ${TEST_SH} exec2 || printf ERR"
+
+	atf_check -s exit:0 -o match:OKOKERR -e not-empty \
+		${TEST_SH} ./exec1
+
 	cleanhelper exec
 }
 
@@ -70,11 +87,11 @@ loop_redir_open_head() {
 	atf_set "descr" "Tests that redirections in loops don't close on exec"
 }
 loop_redir_open_body() {
-	mkhelper for 3 "for x in x; do ./for2; done 3>out"
+	mkhelper for 3 "for x in x; do ${TEST_SH} ./for2; done 3>out"
 	atf_check -s exit:0 \
 		-o empty \
 		-e empty \
-		./for1
+		${TEST_SH} ./for1
 	cleanhelper for
 }
 
@@ -83,11 +100,11 @@ compound_redir_open_head() {
 	atf_set "descr" "Tests that redirections in compound statements don't close on exec"
 }
 compound_redir_open_body() {
-	mkhelper comp 3 "{ ./comp2; } 3>out"
+	mkhelper comp 3 "{ ${TEST_SH} ./comp2; } 3>out"
 	atf_check -s exit:0 \
 		-o empty \
 		-e empty \
-		./comp1
+		${TEST_SH} ./comp1
 	cleanhelper comp
 }
 
@@ -96,17 +113,31 @@ simple_redir_open_head() {
 	atf_set "descr" "Tests that redirections in simple commands don't close on exec"
 }
 simple_redir_open_body() {
-	mkhelper simp 6 "./simp2 6>out"
+	mkhelper simp 4 "${TEST_SH} ./simp2 4>out"
 	atf_check -s exit:0 \
 		-o empty \
 		-e empty \
-		./simp1
+		${TEST_SH} ./simp1
 	cleanhelper simp
 }
 
+atf_test_case subshell_redir_open
+subshell_redir_open_head() {
+	atf_set "descr" "Tests that redirections on subshells don't close on exec"
+}
+subshell_redir_open_body() {
+	mkhelper comp 5 "( ${TEST_SH} ./comp2; ${TEST_SH} ./comp2 ) 5>out"
+	atf_check -s exit:0 \
+		-o empty \
+		-e empty \
+		${TEST_SH} ./comp1
+	cleanhelper comp
+}
+
 atf_init_test_cases() {
 	atf_add_test_case exec_redir_closed
 	atf_add_test_case loop_redir_open
 	atf_add_test_case compound_redir_open
 	atf_add_test_case simple_redir_open
+	atf_add_test_case subshell_redir_open
 }



CVS commit: src/tests/bin/sh

2016-03-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 13 18:55:12 UTC 2016

Modified Files:
src/tests/bin/sh: Makefile
Added Files:
src/tests/bin/sh: t_redircloexec.sh

Log Message:
Add some redir-close-on-exec tests


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/bin/sh/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/bin/sh/t_redircloexec.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/Makefile
diff -u src/tests/bin/sh/Makefile:1.7 src/tests/bin/sh/Makefile:1.8
--- src/tests/bin/sh/Makefile:1.7	Tue Mar  8 09:26:34 2016
+++ src/tests/bin/sh/Makefile	Sun Mar 13 14:55:12 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.7 2016/03/08 14:26:34 christos Exp $
+# $NetBSD: Makefile,v 1.8 2016/03/13 18:55:12 christos Exp $
 #
 
 .include 
@@ -14,6 +14,7 @@ TESTS_SH+=	t_fsplit
 TESTS_SH+=	t_here
 TESTS_SH+=	t_option
 TESTS_SH+=	t_redir
+TESTS_SH+=	t_redircloexec
 TESTS_SH+=	t_set_e
 TESTS_SH+=	t_ulimit
 TESTS_SH+=	t_varquote

Added files:

Index: src/tests/bin/sh/t_redircloexec.sh
diff -u /dev/null src/tests/bin/sh/t_redircloexec.sh:1.1
--- /dev/null	Sun Mar 13 14:55:12 2016
+++ src/tests/bin/sh/t_redircloexec.sh	Sun Mar 13 14:55:12 2016
@@ -0,0 +1,112 @@
+# $NetBSD: t_redircloexec.sh,v 1.1 2016/03/13 18:55:12 christos Exp $
+#
+# Copyright (c) 2016 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Christos Zoulas.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
+
+mkhelper() {
+	local name="$1"
+	local fd="$2"
+	shift 2
+	(echo "#!${TEST_SH}"; echo "$@") > ./"$name"1
+	(echo "#!${TEST_SH}"; echo "echo $name"2 ">&$fd") > ./"$name"2
+	chmod +x ./"$name"1 ./"$name"2
+}
+
+runhelper() {
+	local name="$1"
+	shift
+
+	"./$name"1
+}
+
+cleanhelper() {
+	local name="$1"
+	shift
+	rm -f ./"$name"1 ./"$name"2
+}
+
+atf_test_case exec_redir_closed
+exec_redir_closed_head() {
+	atf_set "descr" "Tests that redirections created by exec are closed on exec"
+}
+exec_redir_closed_body() {
+	mkhelper exec 6 "exec 6> out; echo exec1 >&6; ./exec2; exec 6>&-"
+	atf_check -s exit:0 \
+		-o empty \
+		-e match:"./exec2: 6: Bad file descriptor" \
+		./exec1
+	cleanhelper exec
+}
+
+atf_test_case loop_redir_open
+loop_redir_open_head() {
+	atf_set "descr" "Tests that redirections in loops don't close on exec"
+}
+loop_redir_open_body() {
+	mkhelper for 3 "for x in x; do ./for2; done 3>out"
+	atf_check -s exit:0 \
+		-o empty \
+		-e empty \
+		./for1
+	cleanhelper for
+}
+
+atf_test_case compound_redir_open
+compound_redir_open_head() {
+	atf_set "descr" "Tests that redirections in compound statements don't close on exec"
+}
+compound_redir_open_body() {
+	mkhelper comp 3 "{ ./comp2; } 3>out"
+	atf_check -s exit:0 \
+		-o empty \
+		-e empty \
+		./comp1
+	cleanhelper comp
+}
+
+atf_test_case simple_redir_open
+simple_redir_open_head() {
+	atf_set "descr" "Tests that redirections in simple commands don't close on exec"
+}
+simple_redir_open_body() {
+	mkhelper simp 6 "./simp2 6>out"
+	atf_check -s exit:0 \
+		-o empty \
+		-e empty \
+		./simp1
+	cleanhelper simp
+}
+
+atf_init_test_cases() {
+	atf_add_test_case exec_redir_closed
+	atf_add_test_case loop_redir_open
+	atf_add_test_case compound_redir_open
+	atf_add_test_case simple_redir_open
+}



CVS commit: src/tests/bin/sh

2016-03-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar 12 14:58:03 UTC 2016

Modified Files:
src/tests/bin/sh: t_varquote.sh

Log Message:
Implement TEST_SH for this test, add a test or two, and also some
commentary to explain some of the weirdness of shell quoting. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_varquote.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_varquote.sh
diff -u src/tests/bin/sh/t_varquote.sh:1.3 src/tests/bin/sh/t_varquote.sh:1.4
--- src/tests/bin/sh/t_varquote.sh:1.3	Fri Feb 19 08:48:28 2016
+++ src/tests/bin/sh/t_varquote.sh	Sat Mar 12 09:58:03 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_varquote.sh,v 1.3 2016/02/19 13:48:28 christos Exp $
+# $NetBSD: t_varquote.sh,v 1.4 2016/03/12 14:58:03 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -24,6 +24,8 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
 
 # Variable quoting test.
 
@@ -39,30 +41,70 @@ all_head() {
 	atf_set "descr" "Basic checks for variable quoting"
 }
 all_body() {
-	foo='${a:-foo}'
-	check "$foo" '${a:-foo}'
 
-	foo="${a:-foo}"
-	check "$foo" "foo"
+	cat <<-'EOF' > script.sh
+		T=0
+		check() {
+			T=$((${T} + 1))
+
+			if [ "$1" != "$2" ]
+			then
+printf '%s\n' "T${T}: expected [$2], found [$1]"
+exit 1
+			fi
+		}
+
+#1
+		foo='${a:-foo}'
+		check "$foo" '${a:-foo}'
+#2
+		foo="${a:-foo}"
+		check "$foo" "foo"
+#3
+		foo=${a:-"'{}'"}	
+		check "$foo" "'{}'"
+#4
+		foo=${a:-${b:-"'{}'"}}
+		check "$foo" "'{}'"
+#5
+		#${   }   The ' are inside ".." so are literal (not quotes).
+		foo="${a-'}'}"
+		check "$foo" "''}"
+#6
+		# The rules for quoting in ${var-word} expressions are somewhat
+		# weird, in the following there is not one quoted string being
+		# assigned to foo (with internally quoted sub-strings), rather
+		# it is a mixed quoted/unquoted string, with parts that are
+		# quoted, separated by 2 unquoted sections...
+		#qq uu qq  
+		foo="${a:-${b:-"${c:-${d:-"x}"}}y}"}}z}"
+		#   "z*"
+		#${a:-  }
+		# ${b:-}
+		#  "y*"
+		#   ${c:-  }
+		#${d:-}
+		# "x*"
+		check "$foo" "x}y}z}"
+#7
+		# And believe it or not, this is the one that gives
+		# most problems, with 3 different observed outputs...
+		#q  qq  q		is one interpretation
+		#q  q		is another (most common)
+		#			(the third is syntax error...)
+		foo="${a:-"'{}'"}"
+		check "$foo" "'{}'"
 
-	foo=${a:-"'{}'"}
-	check "$foo" "'{}'"
+	EOF
 
-	foo=${a:-${b:-"'{}'"}}
-	check "$foo" "'{}'"
-
-	foo="${a:-"'{}'"}"
-	check "$foo" "'{}'"
-
-	foo="${a:-${b:-"${c:-${d:-"x}"}}y}"}}z}"
-	#   "z*"
-	#${a:-  }
-	# ${b:-}
-	#  "y*"
-	#   ${c:-  }
-	#${d:-}
-	# "x*"
-	check "$foo" "x}y}z}"
+	OUT=$( ${TEST_SH} script.sh 2>&1 )
+	if  [ $? -ne 0 ]
+	then
+		atf_fail "${OUT}"
+	elif [ -n "${OUT}" ]
+	then
+		atf_fail "script.sh unexpectedly said: ${OUT}"
+	fi
 }
 
 atf_test_case nested_quotes_multiword
@@ -72,7 +114,7 @@ nested_quotes_multiword_head() {
 }
 nested_quotes_multiword_body() {
 	atf_check -s eq:0 -o match:"first-word second-word" -e empty \
-	/bin/sh -c 'echo "${foo:="first-word"} second-word"'
+	${TEST_SH} -c 'echo "${foo:="first-word"} second-word"'
 }
 
 atf_test_case default_assignment_with_arith
@@ -81,7 +123,8 @@ default_assignment_with_arith_head() {
 	"string works (PR bin/50827)"
 }
 default_assignment_with_arith_body() {
-	atf_check -s eq:0 -o empty -e empty /bin/sh -c ': "${x=$((1))}"'
+	atf_check -s eq:0 -o empty -e empty ${TEST_SH} -c ': "${x=$((1))}"'
+	atf_check -s eq:0 -o match:1 -e empty ${TEST_SH} -c 'echo "${x=$((1))}"'
 
 }
 



CVS commit: src/tests/bin/sh

2016-03-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 10 22:30:57 UTC 2016

Modified Files:
src/tests/bin/sh: t_fsplit.sh

Log Message:
Set TEST_SH


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_fsplit.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_fsplit.sh
diff -u src/tests/bin/sh/t_fsplit.sh:1.2 src/tests/bin/sh/t_fsplit.sh:1.3
--- src/tests/bin/sh/t_fsplit.sh:1.2	Tue Mar  8 09:26:54 2016
+++ src/tests/bin/sh/t_fsplit.sh	Thu Mar 10 17:30:57 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_fsplit.sh,v 1.2 2016/03/08 14:26:54 christos Exp $
+# $NetBSD: t_fsplit.sh,v 1.3 2016/03/10 22:30:57 christos Exp $
 #
 # Copyright (c) 2007-2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -36,6 +36,9 @@
 # and: sh -c 'set -- ${x-}' echo $#' shold give 0
 #
 
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
+
 nl='
 '
 



CVS commit: src/tests/bin/sh

2016-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  8 14:26:54 UTC 2016

Modified Files:
src/tests/bin/sh: t_expand.sh t_fsplit.sh t_redir.sh

Log Message:
Added more test cases, more exhaustive testing. (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_expand.sh
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_fsplit.sh
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.5 src/tests/bin/sh/t_expand.sh:1.6
--- src/tests/bin/sh/t_expand.sh:1.5	Mon Feb 22 15:02:29 2016
+++ src/tests/bin/sh/t_expand.sh	Tue Mar  8 09:26:54 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.5 2016/02/22 20:02:29 christos Exp $
+# $NetBSD: t_expand.sh,v 1.6 2016/03/08 14:26:54 christos Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -24,6 +24,8 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
 
 #
 # This file tests the functions in expand.c.
@@ -50,19 +52,15 @@ dollar_at_head() {
 }
 dollar_at_body() {
 	# This one should work everywhere.
-	got=`echo "" "" | sed 's,$,EOL,'`
-	atf_check_equal ' EOL' '$got'
+	atf_check -s exit:0 -o inline:' EOL\n' -e empty \
+		${TEST_SH} -c 'echo "" "" | '" sed 's,\$,EOL,'"
 
 	# This code triggered the bug.
-	set -- "" ""
-	got=`echo "$@" | sed 's,$,EOL,'`
-	atf_check_equal ' EOL' '$got'
-
-	set -- -
-	shift
-	n_arg() { echo $#; }
-	n_args=`n_arg "$@"`
-	atf_check_equal '0' '$n_args'
+	atf_check -s exit:0 -o inline:' EOL\n' -e empty \
+		${TEST_SH} -c 'set -- "" ""; echo "$@" | '" sed 's,\$,EOL,'"
+
+	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+		'set -- -; shift; n_arg() { echo $#; }; n_arg "$@"'
 }
 
 atf_test_case dollar_at_with_text
@@ -71,27 +69,91 @@ dollar_at_with_text_head() {
 	"within the quotes.  PR bin/33956."
 }
 dollar_at_with_text_body() {
-	set --
-	atf_check_equal '' "$(delim_argv "$@")"
-	atf_check_equal '>foobar<' "$(delim_argv "foo$@bar")"
-	atf_check_equal '>foo  bar<' "$(delim_argv "foo $@ bar")"
-
-	set -- a b c
-	atf_check_equal '>a< >b< >c<' "$(delim_argv "$@")"
-	atf_check_equal '>fooa< >b< >cbar<' "$(delim_argv "foo$@bar")"
-	atf_check_equal '>foo a< >b< >c bar<' "$(delim_argv "foo $@ bar")"
+
+	cat <<'EOF' > h-f1
+
+delim_argv() {
+	str=
+	while [ $# -gt 0 ]; do
+		if [ -z "${str}" ]; then
+			str=">$1<"
+		else
+			str="${str} >$1<"
+		fi
+		shift
+	done
+	echo "${str}"
+}
+
+EOF
+	cat <<'EOF' > h-f2
+
+delim_argv() {
+	str=
+	while [ $# -gt 0 ]; do
+
+		str="${str}${str:+ }>$1<"
+		shift
+
+	done
+	echo "${str}"
+}
+
+EOF
+
+	chmod +x h-f1 h-f2
+
+	for f in 1 2
+	do
+		atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
+			". ./h-f${f}; "'set -- ; delim_argv "$@"'
+		atf_check -s exit:0 -o inline:'>foobar<\n' -e empty \
+			${TEST_SH} -c \
+			". ./h-f${f}; "'set -- ; delim_argv "foo$@bar"'
+		atf_check -s exit:0 -o inline:'>foo  bar<\n' -e empty \
+			${TEST_SH} -c \
+			". ./h-f${f}; "'set -- ; delim_argv "foo $@ bar"'
+
+		atf_check -s exit:0 -o inline:'>a< >b< >c<\n' -e empty \
+			${TEST_SH} -c \
+			". ./h-f${f}; "'set -- a b c; delim_argv "$@"'
+		atf_check -s exit:0 -o inline:'>fooa< >b< >cbar<\n' -e empty \
+			${TEST_SH} -c \
+			". ./h-f${f}; "'set -- a b c; delim_argv "foo$@bar"'
+		atf_check -s exit:0 -o inline:'>foo a< >b< >c bar<\n' -e empty \
+			${TEST_SH} -c \
+			". ./h-f${f}; "'set -- a b c; delim_argv "foo $@ bar"'
+	done
 }
 
 atf_test_case strip
 strip_head() {
 	atf_set "descr" "Checks that the %% operator works and strips" \
 	"the contents of a variable from the given point" \
-			"to the end (PR bin/43469)"
+			"to the end"
 }
 strip_body() {
 	line='#define bindir "/usr/bin" /* comment */'
 	stripped='#define bindir "/usr/bin" '
-	atf_check_equal '$stripped' '${line%%/\**}'
+
+	# atf_expect_fail "PR bin/43469" -- now fixed
+	for exp in \
+		'${line%%/\**}'			\
+		'${line%%"/*"*}'		\
+		'${line%%'"'"'/*'"'"'*}'	\
+		'"${line%%/\**}"'		\
+		'"${line%%"/*"*}"'		\
+		'"${line%%'"'"'/*'"'"'*}"'	\
+		'${line%/\**}'			\
+		'${line%"/*"*}'			\
+		'${line%'"'"'/*'"'"'*}'		\
+		'"${line%/\**}"'		\
+		'"${line%"/*"*}"'		\
+		'"${line%'"'"'/*'"'"'*}"'
+	do
+		atf_check -o inline:":$stripped:\n" -e empty ${TEST_SH} -c \
+			"line='${line}'; echo :${exp}:"
+	done
 }
 
 atf_test_case varpattern_backslashes
@@ -102,7 +164,8 @@ varpattern_backslashes_head() {
 varpattern_backslashes_body() {
 	line='/foo/bar/*/baz'
 	stripped='/foo/bar/'
-	atf_check_equal $stripped ${line%%\**}
+	atf_check -o inline:'/foo/bar/\n' -e empty ${TEST_SH} -c \
+		'line="/foo/bar/*/baz"; echo ${line%%\**}'
 }
 
 atf_test_case arithmetic
@@ -113,9 +176,13 @@ arithmetic_head() {
 			

CVS commit: src/tests/bin/sh

2016-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  8 14:26:26 UTC 2016

Added Files:
src/tests/bin/sh: t_shift.sh

Log Message:
Tests for the shift builtin (from kre)


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/bin/sh/t_shift.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/bin/sh/t_shift.sh
diff -u /dev/null src/tests/bin/sh/t_shift.sh:1.1
--- /dev/null	Tue Mar  8 09:26:26 2016
+++ src/tests/bin/sh/t_shift.sh	Tue Mar  8 09:26:26 2016
@@ -0,0 +1,181 @@
+# $NetBSD: t_shift.sh,v 1.1 2016/03/08 14:26:26 christos Exp $
+#
+# Copyright (c) 2016 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
+
+atf_test_case basic_shift_test
+basic_shift_test_head() {
+	atf_set "descr" "Test correct operation of valid shifts"
+}
+basic_shift_test_body() {
+
+	for a in			\
+	  "one-arg::0:one-arg"		\
+	  "one-arg:1:0:one-arg"		\
+	  "one-arg:0:1 one-arg"		\
+	  "a b c::2 b c:a"		\
+	  "a b c:1:2 b c:a"		\
+	  "a b c:2:1 c:a:b"		\
+	  "a b c:3:0:a:b:c"		\
+	  "a b c:0:3 a b c"		\
+	  "a b c d e f g h i j k l m n o p:1:15 b c d e f g h i j k l m n o p"\
+	  "a b c d e f g h i j k l m n o p:9:7 j k l m n o p:a:b:c:g:h:i" \
+	  "a b c d e f g h i j k l m n o p:13:3 n o p:a:b:c:d:k:l:m"	  \
+	  "a b c d e f g h i j k l m n o p:16:0:a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p"
+	do
+		oIFS="${IFS}"
+		IFS=:; set -- $a
+		IFS="${oIFS}"
+
+		init="$1"; n="$2"; res="$3"; shift 3
+
+		not=
+		for b
+		do
+			not="${not} -o not-match:$b"
+		done
+
+		atf_check -s exit:0 -o "match:${res}" ${not} -e empty \
+			${TEST_SH} -c "set -- ${init}; shift $n;"' echo "$# $*"'
+	done
+
+	atf_check -s exit:0 -o match:complete -o not-match:ERR -e empty \
+		${TEST_SH} -c \
+'set -- a b c d e;while [ $# -gt 0 ];do shift||echo ERR;done;echo complete'
+}
+
+atf_test_case excessive_shift
+excessive_shift_head() {
+	atf_set "descr" "Test acceptable operation of shift too many"
+}
+# In:
+#
+#	http://pubs.opengroup.org/onlinepubs/9699919799
+#		/utilities/V3_chap02.html#tag_18_26_01
+#
+# (that URL should be one line, with the /util... immediately after ...9799)
+#
+# POSIX says of shift (in the "EXIT STATUS" paragraph):
+#
+#  If the n operand is invalid or is greater than "$#", this may be considered
+#  a syntax error and a non-interactive shell may exit; if the shell does not
+#  exit in this case, a non-zero exit status shall be returned.
+#  Otherwise, zero shall be returned.
+#
+# NetBSD's sh treats it as an error and exits (if non-interactive, as here),
+# other shells do not.
+#
+# Either behaviour is acceptable - so the test allows for both
+# (and checks that if the shell does not exit, "shift" returns status != 0)
+
+excessive_shift_body() {
+	for a in\
+		"one-arg:2"			\
+		"one-arg:4"			\
+		"one-arg:13"			\
+		"one two:3"			\
+		"one two:7"			\
+		"one two three four five:6"	\
+		"I II III IV V VI VII VIII IX X XI XII XIII XIV XV:16"	\
+		"I II III IV V VI VII VIII IX X XI XII XIII XIV XV:17"	\
+		"I II III IV V VI VII VIII IX X XI XII XIII XIV XV:30"	\
+		"I II III IV V VI VII VIII IX X XI XII XIII XIV XV:"
+	do
+		oIFS="${IFS}"
+		IFS=:; set -- $a
+		IFS="${oIFS}"
+
+		atf_check -s not-exit:0 -o match:OK -o not-match:ERR \
+			-e ignore ${TEST_SH} -c \
+			"set -- $1 ;"'echo OK:$#-'"$2;shift $2 && echo ERR"
+	done
+}
+
+atf_test_case function_shift
+function_shift_head() {
+	atf_set "descr" "Test that shift in a function does not affect outside"
+}
+function_shift_body() {
+	# later...
+}
+
+atf_test_case non_numeric_shift

CVS commit: src/tests/bin/sh

2016-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  8 14:26:34 UTC 2016

Modified Files:
src/tests/bin/sh: Makefile

Log Message:
remove old test


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/bin/sh/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/Makefile
diff -u src/tests/bin/sh/Makefile:1.6 src/tests/bin/sh/Makefile:1.7
--- src/tests/bin/sh/Makefile:1.6	Tue Feb 23 11:20:42 2016
+++ src/tests/bin/sh/Makefile	Tue Mar  8 09:26:34 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.6 2016/02/23 16:20:42 christos Exp $
+# $NetBSD: Makefile,v 1.7 2016/03/08 14:26:34 christos Exp $
 #
 
 .include 
@@ -7,7 +7,6 @@ TESTSDIR = ${TESTSBASE}/bin/sh
 
 TESTS_SUBDIRS += dotcmd
 
-TESTS_SH=	t_compexit
 TESTS_SH+=	t_exit
 TESTS_SH+=	t_expand
 TESTS_SH+=	t_evaltested



CVS commit: src/tests/bin/sh

2016-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  8 14:24:50 UTC 2016

Removed Files:
src/tests/bin/sh: t_compexit.sh

Log Message:
This test tests nothing not tested elsewhere, and doesn't
do a very good job of that. Bang! (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r0 src/tests/bin/sh/t_compexit.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/bin/sh

2016-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  8 14:24:06 UTC 2016

Modified Files:
src/tests/bin/sh: t_wait.sh

Log Message:
Complete implementation of TEST_SH, use builting kill (which does
work, now anyway) rather than working around a defect by using
/bin/kill (if the shell is broken, the test should fail, not succeed)
and test more aspects of the wait builtin in the kill test. (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_wait.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_wait.sh
diff -u src/tests/bin/sh/t_wait.sh:1.5 src/tests/bin/sh/t_wait.sh:1.6
--- src/tests/bin/sh/t_wait.sh:1.5	Wed Feb 24 09:42:50 2016
+++ src/tests/bin/sh/t_wait.sh	Tue Mar  8 09:24:06 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_wait.sh,v 1.5 2016/02/24 14:42:50 christos Exp $
+# $NetBSD: t_wait.sh,v 1.6 2016/03/08 14:24:06 christos Exp $
 #
 # Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -84,14 +84,13 @@ EOF
 	pid=$!
 	sleep 1
 
-	# XXX: built-in kill does not work?
-	/bin/kill -HUP $pid
+	kill -HUP $pid
 	wait
 
 	output="$(cat $z | tr '\n' ' ')"
 	rm -f $s $z
 	if [ "$output" != "SIGHUP 129 3 127 " ]; then
-		atf_fail "${output} != 'SIGHUP 129 '"
+		atf_fail "${output} != 'SIGHUP 129 3 127 '"
 	fi
 }
 



CVS commit: src/tests/bin/sh

2016-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  8 14:21:02 UTC 2016

Modified Files:
src/tests/bin/sh: t_here.sh

Log Message:
Cleanup left over (dead) debugging code (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_here.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_here.sh
diff -u src/tests/bin/sh/t_here.sh:1.3 src/tests/bin/sh/t_here.sh:1.4
--- src/tests/bin/sh/t_here.sh:1.3	Tue Mar  1 07:39:35 2016
+++ src/tests/bin/sh/t_here.sh	Tue Mar  8 09:21:02 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_here.sh,v 1.3 2016/03/01 12:39:35 christos Exp $
+# $NetBSD: t_here.sh,v 1.4 2016/03/08 14:21:02 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -43,12 +43,6 @@ check()
 	result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
 	STATUS=$?
 
-	if [ -s "${O_FILE}" ]; then
-		echo >&2 "unexpected shell output noise on stdout"
-		cat "${O_FILE}" >&2
-		fail=true
-	fi
-
 	if [ "${STATUS}" -ne "$3" ]; then
 		echo >&2 "expected exit code $3, got ${STATUS}"
 



CVS commit: src/tests/bin/sh

2016-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  8 14:20:22 UTC 2016

Modified Files:
src/tests/bin/sh: t_set_e.sh

Log Message:
Correct one test that (while OK for NetBSD) insisted on behaviour
that is not required by the standard. The test now allows either
of the two allowed responses. Also add commentary correcting
erroneous comments about what is correct, and incorrect. (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_set_e.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_set_e.sh
diff -u src/tests/bin/sh/t_set_e.sh:1.1 src/tests/bin/sh/t_set_e.sh:1.2
--- src/tests/bin/sh/t_set_e.sh:1.1	Sat Mar 17 12:33:11 2012
+++ src/tests/bin/sh/t_set_e.sh	Tue Mar  8 09:20:22 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_set_e.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
+# $NetBSD: t_set_e.sh,v 1.2 2016/03/08 14:20:22 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -30,7 +30,7 @@
 #   http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
 
 # the implementation of "sh" to test
-: ${TEST_SH:="sh"}
+: ${TEST_SH:="/bin/sh"}
 
 failwith()
 {
@@ -205,6 +205,9 @@ all_body() {
 
 	# According to dsl@ in PR bin/32282, () is not defined as a
 	# subshell, only as a grouping operator [and a scope, I guess]
+
+	#		(This is incorrect.   () is definitely a sub-shell)
+
 	# so the nested false ought to cause the whole shell to exit,
 	# not just the subshell. dholland@ would like to see C,
 	# because that seems like a bad idea. (Among other things, it
@@ -215,8 +218,10 @@ all_body() {
 	#
 	# XXX: the second set has been disabled in the name of making
 	# all tests "pass".
+	#
+	# As they should be, they are utter nonsense.
 
-	# 1. error if the whole shell exits (current behavior)
+	# 1. error if the whole shell exits (current correct behavior)
 	dcheck 'echo OK; (set -e; false); echo OK' 'OK OK'
 	echeck 'echo OK; (set -e; false); echo OK' 'OK OK'
 	# 2. error if the whole shell does not exit (dsl's suggested behavior)
@@ -232,29 +237,32 @@ all_body() {
 
 	# backquote expansion (PR bin/17514)
 
-	# correct
+	# (in-)correct
 	#dcheck '(set -e; echo ERR `false`; echo ERR); echo OK' 'OK'
 	#dcheck '(set -e; echo ERR $(false); echo ERR); echo OK' 'OK'
 	#dcheck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'OK'
 	#dcheck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'OK'
-	# wrong current behavior
+	# Not-wrong current behavior
+	# the exit status of ommand substitution is ignored in most cases
+	# None of these should be causing the shell to exit.
 	dcheck '(set -e; echo ERR `false`; echo ERR); echo OK' 'ERR ERR OK'
 	dcheck '(set -e; echo ERR $(false); echo ERR); echo OK' 'ERR ERR OK'
 	dcheck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'ERR ERR OK'
 	dcheck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'ERR ERR OK'
 
+	# This is testing one case (the case?) where the exit status is used
 	dcheck '(set -e; x=`false`; echo ERR); echo OK' 'OK'
 	dcheck '(set -e; x=$(false); echo ERR); echo OK' 'OK'
 	dcheck '(set -e; x=`exit 3`; echo ERR); echo OK' 'OK'
 	dcheck '(set -e; x=$(exit 3); echo ERR); echo OK' 'OK'
 
-	# correct
+	# correct (really just commented out incorrect nonsense)
 	#echeck '(set -e; echo ERR `false`; echo ERR); echo OK' 'OK'
 	#echeck '(set -e; echo ERR $(false); echo ERR); echo OK' 'OK'
 	#echeck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'OK'
 	#echeck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'OK'
 
-	# wrong current behavior
+	# not-wrong current behavior (as above)
 	echeck '(set -e; echo ERR `false`; echo ERR); echo OK' 'ERR ERR OK'
 	echeck '(set -e; echo ERR $(false); echo ERR); echo OK' 'ERR ERR OK'
 	echeck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'ERR ERR OK'
@@ -267,11 +275,19 @@ all_body() {
 
 	# shift (PR bin/37493)
 	# correct
+	# Actually, both ways are correct, both are permitted
 	#dcheck '(set -e; shift || true; echo OK); echo OK' 'OK OK'
 	#echeck '(set -e; shift || true; echo OK); echo OK' 'OK OK'
-	# wrong current behavior
-	dcheck '(set -e; shift || true; echo OK); echo OK' 'OK'
-	echeck '(set -e; shift || true; echo OK); echo OK' 'OK'
+	# (not-) wrong current behavior
+	#dcheck '(set -e; shift || true; echo OK); echo OK' 'OK'
+	#echeck '(set -e; shift || true; echo OK); echo OK' 'OK'
+
+	# what is wrong is this test assuming one behaviour or the other
+	# (and incidentally this has nothing whatever to do with "-e",
+	# the test should really be moved elsewhere...)
+	# But for now, leave it here, and correct it:
+	dcheck '(set -e; shift && echo OK); echo OK' 'OK'
+	echeck '(set -e; shift && echo OK); echo OK' 'OK'
 
 	# Done.
 



CVS commit: src/tests/bin/sh

2016-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  8 14:19:28 UTC 2016

Modified Files:
src/tests/bin/sh: t_option.sh

Log Message:
Correct the way that TEST_SH is used so that the tests work as
intended when TEST_SH is specifies a shell that needs options (like
sh -F, or bash -o posix). (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_option.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_option.sh
diff -u src/tests/bin/sh/t_option.sh:1.2 src/tests/bin/sh/t_option.sh:1.3
--- src/tests/bin/sh/t_option.sh:1.2	Tue Mar  1 07:39:35 2016
+++ src/tests/bin/sh/t_option.sh	Tue Mar  8 09:19:28 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_option.sh,v 1.2 2016/03/01 12:39:35 christos Exp $
+# $NetBSD: t_option.sh,v 1.3 2016/03/08 14:19:28 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -414,42 +414,45 @@ set_v_body() {
 		${TEST_SH} -ec 'printf "%s" OK; set -v; echo OK; exit 0'
 
 	# but that it does when there are multiple lines
+	cat <<- 'EOF' |
+		set -v
+		printf %s OK
+		echo OK
+		exit 0
+	EOF
 	atf_check -s exit:0 \
 			-o match:OKOK -o not-match:echo -o not-match:printf \
 			-e match:printf -e match:OK -e match:echo \
-		${TEST_SH} -ec '{
-	echo "set -v"
-	echo "printf %s OK"
-	echo "echo OK"
-	echo "exit 0"
-} | '"'${TEST_SH}'"' -e'
+			-e not-match:set ${TEST_SH}
 
 	# and that it can be disabled again
+	cat <<- 'EOF' |
+		set -v
+		printf %s OK
+		set +v
+		echo OK
+		exit 0
+	EOF
 	atf_check -s exit:0 \
 			-o match:OKOK -o not-match:echo -o not-match:printf \
 			-e match:printf -e match:OK -e not-match:echo \
-		${TEST_SH} -ec '{
-	echo "set -v"
-	echo "printf %s OK"
-	echo "set +v"
-	echo "echo OK"
-	echo "exit 0"
-} | '"'${TEST_SH}'"' -e'
+${TEST_SH}
 
 	# and lastly, that shell keywords do get output when "read"
+	cat <<- 'EOF' |
+		set -v
+		for i in 111 222 333
+		do
+			printf %s $i
+		done
+		exit 0
+	EOF
 	atf_check -s exit:0 \
 			-o match:111222333 -o not-match:printf \
 			-o not-match:for -o not-match:do -o not-match:done \
 			-e match:printf -e match:111 -e not-match:111222 \
 			-e match:for -e match:do -e match:done \
-		${TEST_SH} -ec '{
-	echo "set -v"
-	echo "for i in 111 222 333"
-	echo "do"
-	echo "printf %s \$i"
-	echo "done"
-	echo "exit 0"
-} | '"'${TEST_SH}'"' -e'
+${TEST_SH}
 }
 
 atf_test_case set_x
@@ -600,6 +603,9 @@ xx_bogus_head() {
 xx_bogus_body() {
 	# Biggest problem here is picking a "nonsense option" that is
 	# not implemented by any shell, anywhere.  Hopefully this will do.
+
+	# 'set' is a special builtin, so a conforming shell should exit
+	# on an arg error, and the ERR should not be printed.
 	atf_check -s not-exit:0 -o empty -e not-empty \
 		${TEST_SH} -c 'set -% ; echo ERR'
 }



CVS commit: src/tests/bin/sh

2016-03-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  1 12:39:36 UTC 2016

Modified Files:
src/tests/bin/sh: t_exit.sh t_here.sh t_option.sh t_redir.sh

Log Message:
Improved handling of TEST_SH so that it is possible to define it
to the name of a shell, plus options that shell needs to run it
in the correct mode to be tested: eg: TEST_SH='bash -o posix'
Also finished the implementation of tests of "set -n" now that
the NetBSD shell supports that as it should. (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_exit.sh
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_here.sh \
src/tests/bin/sh/t_redir.sh
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_option.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_exit.sh
diff -u src/tests/bin/sh/t_exit.sh:1.4 src/tests/bin/sh/t_exit.sh:1.5
--- src/tests/bin/sh/t_exit.sh:1.4	Wed Feb 24 09:42:06 2016
+++ src/tests/bin/sh/t_exit.sh	Tue Mar  1 07:39:35 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_exit.sh,v 1.4 2016/02/24 14:42:06 christos Exp $
+# $NetBSD: t_exit.sh,v 1.5 2016/03/01 12:39:35 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -34,9 +34,9 @@ background_head() {
 			"a command in the background (PR bin/46327)"
 }
 background_body() {
-	atf_check -o match:0 -e empty "${TEST_SH}" -c 'true; true & echo $?'
+	atf_check -o match:0 -e empty ${TEST_SH} -c 'true; true & echo $?'
 	# atf_expect_fail "PR bin/46327" (now fixed?)
-	atf_check -o match:0 -e empty "${TEST_SH}" -c 'false; true & echo $?'
+	atf_check -o match:0 -e empty ${TEST_SH} -c 'false; true & echo $?'
 }
 
 atf_test_case function
@@ -46,7 +46,7 @@ function_head() {
 }
 function_body() {
 	atf_check -s exit:0 -o match:STATUS=1-0 -e empty \
-		"${TEST_SH}" -c '
+		${TEST_SH} -c '
 			crud() {
 test yes = no
 
@@ -66,7 +66,7 @@ readout_head() {
 }
 readout_body() {
 	atf_check -s exit:0 -o match:0 -e empty \
-		"${TEST_SH}" -c 'true && ! true | false; echo $?'
+		${TEST_SH} -c 'true && ! true | false; echo $?'
 }
 
 atf_test_case trap_subshell
@@ -87,7 +87,7 @@ trap_zero__implicit_exit_head() {
 trap_zero__implicit_exit_body() {
 	# PR bin/6764: sh works but ksh does not
 	echo '( trap "echo exiting" 0 )' >helper.sh
-	atf_check -s exit:0 -o match:exiting -e empty "${TEST_SH}" helper.sh
+	atf_check -s exit:0 -o match:exiting -e empty ${TEST_SH} helper.sh
 	# test ksh by setting TEST_SH to /bin/ksh and run the entire set...
 	# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
 }
@@ -100,7 +100,7 @@ trap_zero__explicit_exit_head() {
 trap_zero__explicit_exit_body() {
 	echo '( trap "echo exiting" 0; exit; echo NO_NO_NO )' >helper.sh
 	atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \
-		"${TEST_SH}" helper.sh
+		${TEST_SH} helper.sh
 	# test ksh by setting TEST_SH to /bin/ksh and run the entire set...
 	# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
 }
@@ -115,7 +115,7 @@ trap_zero__explicit_return_body() {
 	echo '( trap "echo exiting" 0; return; echo NO_NO_NO )' >helper.sh
 	atf_expect_fail "return from a sub-shell not defined and does not work"
 	atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \
-		"${TEST_SH}" helper.sh
+		${TEST_SH} helper.sh
 	# test ksh by setting TEST_SH to /bin/ksh and run the entire set...
 	# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
 }
@@ -129,7 +129,7 @@ simple_exit_body() {
 	for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255
 	do
 		atf_check -s exit:$N -o empty -e empty \
-			"${TEST_SH}" -c "exit $N; echo FOO; echo BAR >&2"
+			${TEST_SH} -c "exit $N; echo FOO; echo BAR >&2"
 	done
 }
 
@@ -142,7 +142,7 @@ subshell_exit_body() {
 	for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255
 	do
 		atf_check -s exit:0 -o empty -e empty \
-			"${TEST_SH}" -c "(exit $N); test \$? -eq $N"
+			${TEST_SH} -c "(exit $N); test \$? -eq $N"
 	done
 }
 
@@ -153,10 +153,10 @@ subshell_background_head() {
 }
 subshell_background_body() {
 	atf_check -o match:0 -e empty \
-		"${TEST_SH}" -c 'true; (false || true) & echo $?'
+		${TEST_SH} -c 'true; (false || true) & echo $?'
 	# atf_expect_fail "PR bin/46327" (now fixed?)
 	atf_check -o match:0 -e empty \
-		"${TEST_SH}" -c 'false; (false || true) & echo $?'
+		${TEST_SH} -c 'false; (false || true) & echo $?'
 }
 
 atf_init_test_cases() {

Index: src/tests/bin/sh/t_here.sh
diff -u src/tests/bin/sh/t_here.sh:1.2 src/tests/bin/sh/t_here.sh:1.3
--- src/tests/bin/sh/t_here.sh:1.2	Mon Feb 29 18:52:53 2016
+++ src/tests/bin/sh/t_here.sh	Tue Mar  1 07:39:35 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_here.sh,v 1.2 2016/02/29 23:52:53 christos Exp $
+# $NetBSD: t_here.sh,v 1.3 2016/03/01 12:39:35 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -39,7 +39,6 @@ check()
 	# some of the tests 

CVS commit: src/tests/bin/sh

2016-02-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 29 23:52:53 UTC 2016

Modified Files:
src/tests/bin/sh: t_here.sh

Log Message:
more tests from kre


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_here.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_here.sh
diff -u src/tests/bin/sh/t_here.sh:1.1 src/tests/bin/sh/t_here.sh:1.2
--- src/tests/bin/sh/t_here.sh:1.1	Sat Mar 17 12:33:11 2012
+++ src/tests/bin/sh/t_here.sh	Mon Feb 29 18:52:53 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_here.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
+# $NetBSD: t_here.sh,v 1.2 2016/02/29 23:52:53 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -24,50 +24,238 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
 
 nl='
 '
 
 check()
 {
-	SVIFS="$IFS"
-	result="$(eval $1)"
-	# Remove newlines
+	fail=false
+	TEMP_FILE=$( mktemp OUT.XX )
+
+	# our local shell (ATF_SHELL) better do quoting correctly...
+	# some of the tests expect us to expand $nl internally...
+	CMD="nl='${nl}'; $1"
+
+echo "${CMD}" >/tmp/CMD
+	rm -f trace.*
+	result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
+	STATUS=$?
+
+	if [ -s "${O_FILE}" ]; then
+		echo >&2 "unexpected shell output noise on stdout"
+		cat "${O_FILE}" >&2
+		fail=true
+	fi
+
+	if [ "${STATUS}" -ne "$3" ]; then
+		echo >&2 "expected exit code $3, got ${STATUS}"
+
+		# don't actually fail just because of wrong exit code
+		# unless we either expected, or received "good"
+		case "$3/${STATUS}" in
+		(*/0|0/*) fail=true;;
+		esac
+	fi
+
+	if [ "$3" -eq 0 ]; then
+		if [ -s "${TEMP_FILE}" ]; then
+			echo >&2 "Messages produced on stderr unexpected..."
+			cat "${TEMP_FILE}" >&2
+			fail=true
+		fi
+	else
+		if ! [ -s "${TEMP_FILE}" ]; then
+			echo >&2 "Expected messages on stderr, nothing produced"
+			fail=true
+		fi
+	fi
+	rm -f "${TEMP_FILE}"
+
+	# Remove newlines (use local shell for this)
 	oifs="$IFS"
 	IFS="$nl"
 	result="$(echo $result)"
 	IFS="$oifs"
 	if [ "$2" != "$result" ]
 	then
-		atf_fail "expected [$2], found [$result]"
+		echo >&2 "Expected output '$2', received '$result'"
+		fail=true
 	fi
-	IFS="$SVIFS"
+
+	$fail && atf_fail "test of '$1' failed"
+	return 0
 }
 
-atf_test_case all
-all_head() {
+atf_test_case do_simple
+do_simple_head() {
 	atf_set "descr" "Basic tests for here documents"
 }
-all_body() {
+do_simple_body() {
 	y=x
 
 	IFS=
-	check 'x=`cat <

CVS commit: src/tests/bin/sh

2016-02-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Feb 24 14:42:50 UTC 2016

Modified Files:
src/tests/bin/sh: t_wait.sh

Log Message:
uncomment clean up


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_wait.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_wait.sh
diff -u src/tests/bin/sh/t_wait.sh:1.4 src/tests/bin/sh/t_wait.sh:1.5
--- src/tests/bin/sh/t_wait.sh:1.4	Wed Feb 24 09:42:06 2016
+++ src/tests/bin/sh/t_wait.sh	Wed Feb 24 09:42:50 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_wait.sh,v 1.4 2016/02/24 14:42:06 christos Exp $
+# $NetBSD: t_wait.sh,v 1.5 2016/02/24 14:42:50 christos Exp $
 #
 # Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -89,7 +89,7 @@ EOF
 	wait
 
 	output="$(cat $z | tr '\n' ' ')"
-	# rm -f $s $z
+	rm -f $s $z
 	if [ "$output" != "SIGHUP 129 3 127 " ]; then
 		atf_fail "${output} != 'SIGHUP 129 '"
 	fi



CVS commit: src/tests/bin/sh

2016-02-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Feb 24 14:42:06 UTC 2016

Modified Files:
src/tests/bin/sh: t_exit.sh t_wait.sh

Log Message:
Test improvements from kre


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_exit.sh \
src/tests/bin/sh/t_wait.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_exit.sh
diff -u src/tests/bin/sh/t_exit.sh:1.3 src/tests/bin/sh/t_exit.sh:1.4
--- src/tests/bin/sh/t_exit.sh:1.3	Fri Apr 13 02:12:32 2012
+++ src/tests/bin/sh/t_exit.sh	Wed Feb 24 09:42:06 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_exit.sh,v 1.3 2012/04/13 06:12:32 jruoho Exp $
+# $NetBSD: t_exit.sh,v 1.4 2016/02/24 14:42:06 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -24,74 +24,139 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
 
-crud() {
-	test yes = no
-
-	cat helper.sh
-	atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
-	atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
+	echo '( trap "echo exiting" 0; exit; echo NO_NO_NO )' >helper.sh
+	atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \
+		"${TEST_SH}" helper.sh
+	# test ksh by setting TEST_SH to /bin/ksh and run the entire set...
+	# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
 }
 
+# Is return really defined to operate other than in functions (& '.') ??
 atf_test_case trap_zero__explicit_return
+trap_zero__explicit_return_head() {
+	atf_set "descr" "Tests that the trap statement in a subshell in a " \
+			"script works when the subshell executes a return"
+}
 trap_zero__explicit_return_body() {
-	echo '( trap "echo exiting" 0; return )' >helper.sh
-	atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
-	atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
+	echo '( trap "echo exiting" 0; return; echo NO_NO_NO )' >helper.sh
+	atf_expect_fail "return from a sub-shell not defined and does not work"
+	atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \
+		"${TEST_SH}" helper.sh
+	# test ksh by setting TEST_SH to /bin/ksh and run the entire set...
+	# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
+}
+
+atf_test_case simple_exit
+simple_exit_head() {
+	atf_set "descr" "Tests that various values for exit status work"
+}
+# Note: ATF will not allow tests of exit values > 255, even if they would work
+simple_exit_body() {
+	for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255
+	do
+		atf_check -s exit:$N -o empty -e empty \
+			"${TEST_SH}" -c "exit $N; echo FOO; echo BAR >&2"
+	done
+}
+
+atf_test_case subshell_exit
+subshell_exit_head() {
+	atf_set "descr" "Tests that subshell exit status works and \$? gets it"
+}
+# Note: ATF will not allow tests of exit values > 255, even if they would work
+subshell_exit_body() {
+	for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255
+	do
+		atf_check -s exit:0 -o empty -e empty \
+			"${TEST_SH}" -c "(exit $N); test \$? -eq $N"
+	done
+}
+
+atf_test_case subshell_background
+subshell_background_head() {
+	atf_set "descr" "Tests that sh(1) sets '$?' properly when running " \
+			"a subshell in the background"
+}
+subshell_background_body() {
+	atf_check -o match:0 -e empty \
+		"${TEST_SH}" -c 'true; (false || true) & echo $?'
+	# atf_expect_fail "PR bin/46327" (now fixed?)
+	atf_check -o match:0 -e empty \
+		"${TEST_SH}" -c 'false; (false || true) & echo $?'
 }
 
 atf_init_test_cases() {
@@ -102,4 +167,7 @@ atf_init_test_cases() {
 	atf_add_test_case trap_zero__implicit_exit
 	atf_add_test_case trap_zero__explicit_exit
 	atf_add_test_case trap_zero__explicit_return
+	atf_add_test_case simple_exit
+	atf_add_test_case subshell_exit
+	atf_add_test_case subshell_background
 }
Index: src/tests/bin/sh/t_wait.sh
diff -u src/tests/bin/sh/t_wait.sh:1.3 src/tests/bin/sh/t_wait.sh:1.4
--- src/tests/bin/sh/t_wait.sh:1.3	Wed Sep 30 02:08:36 2015
+++ src/tests/bin/sh/t_wait.sh	Wed Feb 24 09:42:06 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_wait.sh,v 1.3 2015/09/30 06:08:36 ozaki-r Exp $
+# $NetBSD: t_wait.sh,v 1.4 2016/02/24 14:42:06 

CVS commit: src/tests/bin/sh

2016-02-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb 23 14:21:37 UTC 2016

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
Add new redirection test, from kre


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.1 src/tests/bin/sh/t_redir.sh:1.2
--- src/tests/bin/sh/t_redir.sh:1.1	Mon Feb 22 14:52:03 2016
+++ src/tests/bin/sh/t_redir.sh	Tue Feb 23 09:21:37 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.1 2016/02/22 19:52:03 christos Exp $
+# $NetBSD: t_redir.sh,v 1.2 2016/02/23 14:21:37 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -24,6 +24,8 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
 
 atf_test_case redir_in_case
 redir_in_case_head() {
@@ -31,10 +33,25 @@ redir_in_case_head() {
 	"in case statements. (PR bin/48631)"
 }
 redir_in_case_body() {
-	atf_check -s exit:0 -o ignore -e ignore \
-	-x '/bin/sh -c "case x in (whatever) >foo;; esac"'
+	atf_check -s exit:0 -o empty -e empty \
+	${TEST_SH} -c 'case x in (whatever) >foo;; esac'
+}
+
+atf_test_case redir_here_doc
+redir_here_doc_head() {
+	atf_set "descr" "Tests that sh(1) correctly processes 'here' doc " \
+	"input redirections"
+}
+redir_here_doc_body() {
+	atf_check -s exit:0 -o match:'hello\\n' -e empty \
+		"${TEST_SH}" -ec '{
+	echo "cat <

CVS commit: src/tests/bin/sh

2016-02-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 22 20:02:30 UTC 2016

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
PR/43469 has been fixed


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.4 src/tests/bin/sh/t_expand.sh:1.5
--- src/tests/bin/sh/t_expand.sh:1.4	Fri Feb 19 08:49:01 2016
+++ src/tests/bin/sh/t_expand.sh	Mon Feb 22 15:02:29 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.4 2016/02/19 13:49:01 christos Exp $
+# $NetBSD: t_expand.sh,v 1.5 2016/02/22 20:02:29 christos Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -86,12 +86,11 @@ atf_test_case strip
 strip_head() {
 	atf_set "descr" "Checks that the %% operator works and strips" \
 	"the contents of a variable from the given point" \
-			"to the end"
+			"to the end (PR bin/43469)"
 }
 strip_body() {
 	line='#define bindir "/usr/bin" /* comment */'
 	stripped='#define bindir "/usr/bin" '
-	atf_expect_fail "PR bin/43469"
 	atf_check_equal '$stripped' '${line%%/\**}'
 }
 



CVS commit: src/tests/bin/sh

2016-02-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 22 19:52:03 UTC 2016

Modified Files:
src/tests/bin/sh: Makefile
Added Files:
src/tests/bin/sh: t_redir.sh

Log Message:
Add new test


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/Makefile
diff -u src/tests/bin/sh/Makefile:1.4 src/tests/bin/sh/Makefile:1.5
--- src/tests/bin/sh/Makefile:1.4	Thu Sep 11 14:25:30 2014
+++ src/tests/bin/sh/Makefile	Mon Feb 22 14:52:03 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2014/09/11 18:25:30 dholland Exp $
+# $NetBSD: Makefile,v 1.5 2016/02/22 19:52:03 christos Exp $
 #
 
 .include 
@@ -13,6 +13,7 @@ TESTS_SH+=	t_expand
 TESTS_SH+=	t_evaltested
 TESTS_SH+=	t_fsplit
 TESTS_SH+=	t_here
+TESTS_SH+=	t_redir
 TESTS_SH+=	t_set_e
 TESTS_SH+=	t_ulimit
 TESTS_SH+=	t_varquote

Added files:

Index: src/tests/bin/sh/t_redir.sh
diff -u /dev/null src/tests/bin/sh/t_redir.sh:1.1
--- /dev/null	Mon Feb 22 14:52:03 2016
+++ src/tests/bin/sh/t_redir.sh	Mon Feb 22 14:52:03 2016
@@ -0,0 +1,40 @@
+# $NetBSD: t_redir.sh,v 1.1 2016/02/22 19:52:03 christos Exp $
+#
+# Copyright (c) 2016 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+atf_test_case redir_in_case
+redir_in_case_head() {
+	atf_set "descr" "Tests that sh(1) allows plain redirections " \
+	"in case statements. (PR bin/48631)"
+}
+redir_in_case_body() {
+	atf_check -s exit:0 -o ignore -e ignore \
+	-x '/bin/sh -c "case x in (whatever) >foo;; esac"'
+}
+
+atf_init_test_cases() {
+	atf_add_test_case redir_in_case
+}



CVS commit: src/tests/bin/sh

2016-02-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 19 13:49:01 UTC 2016

Modified Files:
src/tests/bin/sh: t_expand.sh

Log Message:
undo accidental commit


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_expand.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.3 src/tests/bin/sh/t_expand.sh:1.4
--- src/tests/bin/sh/t_expand.sh:1.3	Fri Feb 19 08:48:28 2016
+++ src/tests/bin/sh/t_expand.sh	Fri Feb 19 08:49:01 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.3 2016/02/19 13:48:28 christos Exp $
+# $NetBSD: t_expand.sh,v 1.4 2016/02/19 13:49:01 christos Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -91,7 +91,7 @@ strip_head() {
 strip_body() {
 	line='#define bindir "/usr/bin" /* comment */'
 	stripped='#define bindir "/usr/bin" '
-#	atf_expect_fail "PR bin/43469"
+	atf_expect_fail "PR bin/43469"
 	atf_check_equal '$stripped' '${line%%/\**}'
 }
 



CVS commit: src/tests/bin/sh

2016-02-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 19 13:48:28 UTC 2016

Modified Files:
src/tests/bin/sh: t_expand.sh t_varquote.sh

Log Message:
Add a test for PR/50827


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_expand.sh \
src/tests/bin/sh/t_varquote.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_expand.sh
diff -u src/tests/bin/sh/t_expand.sh:1.2 src/tests/bin/sh/t_expand.sh:1.3
--- src/tests/bin/sh/t_expand.sh:1.2	Sun Oct  6 17:05:50 2013
+++ src/tests/bin/sh/t_expand.sh	Fri Feb 19 08:48:28 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.2 2013/10/06 21:05:50 ast Exp $
+# $NetBSD: t_expand.sh,v 1.3 2016/02/19 13:48:28 christos Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -91,7 +91,7 @@ strip_head() {
 strip_body() {
 	line='#define bindir "/usr/bin" /* comment */'
 	stripped='#define bindir "/usr/bin" '
-	atf_expect_fail "PR bin/43469"
+#	atf_expect_fail "PR bin/43469"
 	atf_check_equal '$stripped' '${line%%/\**}'
 }
 
Index: src/tests/bin/sh/t_varquote.sh
diff -u src/tests/bin/sh/t_varquote.sh:1.2 src/tests/bin/sh/t_varquote.sh:1.3
--- src/tests/bin/sh/t_varquote.sh:1.2	Sun Mar 25 14:50:19 2012
+++ src/tests/bin/sh/t_varquote.sh	Fri Feb 19 08:48:28 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_varquote.sh,v 1.2 2012/03/25 18:50:19 christos Exp $
+# $NetBSD: t_varquote.sh,v 1.3 2016/02/19 13:48:28 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -75,7 +75,18 @@ nested_quotes_multiword_body() {
 	/bin/sh -c 'echo "${foo:="first-word"} second-word"'
 }
 
+atf_test_case default_assignment_with_arith
+default_assignment_with_arith_head() {
+	atf_set "descr" "Tests default variable assignment with arithmetic" \
+	"string works (PR bin/50827)"
+}
+default_assignment_with_arith_body() {
+	atf_check -s eq:0 -o empty -e empty /bin/sh -c ': "${x=$((1))}"'
+
+}
+
 atf_init_test_cases() {
 	atf_add_test_case all
 	atf_add_test_case nested_quotes_multiword
+	atf_add_test_case default_assignment_with_arith
 }



CVS commit: src/tests/bin/sh

2015-12-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Dec 30 22:24:44 UTC 2015

Modified Files:
src/tests/bin/sh: t_ulimit.sh

Log Message:
more robust ulimit test that works with most variants of bourne shells.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_ulimit.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_ulimit.sh
diff -u src/tests/bin/sh/t_ulimit.sh:1.1 src/tests/bin/sh/t_ulimit.sh:1.2
--- src/tests/bin/sh/t_ulimit.sh:1.1	Mon Jun 11 14:32:59 2012
+++ src/tests/bin/sh/t_ulimit.sh	Wed Dec 30 17:24:44 2015
@@ -1,4 +1,4 @@
-# $NetBSD: t_ulimit.sh,v 1.1 2012/06/11 18:32:59 njoly Exp $
+# $NetBSD: t_ulimit.sh,v 1.2 2015/12/30 22:24:44 christos Exp $
 #
 # Copyright (c) 2012 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -31,10 +31,21 @@ atf_test_case limits
 limits_head() {
 	atf_set "descr" "Checks for limits flags"
 }
+
+get_ulimits() {
+	local limits=$(ulimit -a |
+	sed -e 's/.*\(-[A-Za-z0-9]\)[^A-Za-z0-9].*/\1/' | sort -u)
+	if [ -z "$limits" ]; then
+		# grr ksh
+		limits="-a -b -c -d -f -l -m -n -p -r -s -t -v"
+	fi
+	echo "$limits"
+}
+
 limits_body() {
 	atf_check -s eq:0 -o ignore -e empty \
 	/bin/sh -c "ulimit -a"
-	for l in $(ulimit -a | sed 's,^.*(,,;s, .*$,,');
+	for l in $(get_ulimits)
 	do
 	atf_check -s eq:0 -o ignore -e empty \
 	/bin/sh -c "ulimit $l"



CVS commit: src/tests/bin/sh

2015-09-30 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Sep 30 06:08:36 UTC 2015

Modified Files:
src/tests/bin/sh: t_wait.sh

Log Message:
Add delay to improve stability of test


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_wait.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_wait.sh
diff -u src/tests/bin/sh/t_wait.sh:1.2 src/tests/bin/sh/t_wait.sh:1.3
--- src/tests/bin/sh/t_wait.sh:1.2	Sun Aug 23 07:15:16 2015
+++ src/tests/bin/sh/t_wait.sh	Wed Sep 30 06:08:36 2015
@@ -1,4 +1,4 @@
-# $NetBSD: t_wait.sh,v 1.2 2015/08/23 07:15:16 christos Exp $
+# $NetBSD: t_wait.sh,v 1.3 2015/09/30 06:08:36 ozaki-r Exp $
 #
 # Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -64,6 +64,8 @@ kill_body() {
 	# a helper script that executes /bin/sh directly.
 	local s=$PWD/killhelper.sh
 	local z=/tmp/killhelper.$$ 
+	local pid=
+
 	cat >$s <<\EOF
 #!/bin/sh
 trap "echo SIGHUP" 1
@@ -73,9 +75,15 @@ wait
 echo $?
 EOF
 	chmod +x $s
+
 	$s > $z &
+	pid=$!
+	sleep 1
+
 	# XXX: built-in kill does not work?
-	/bin/kill -HUP $!
+	/bin/kill -HUP $pid
+	sleep 1
+
 	output="$(cat $z | tr '\n' ' ')"
 	rm -f $s $z
 	if [ "$output" != "SIGHUP 129 " ]; then



CVS commit: src/tests/bin/sh

2015-08-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Aug 23 07:15:16 UTC 2015

Modified Files:
src/tests/bin/sh: t_wait.sh

Log Message:
another wait test.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_wait.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_wait.sh
diff -u src/tests/bin/sh/t_wait.sh:1.1 src/tests/bin/sh/t_wait.sh:1.2
--- src/tests/bin/sh/t_wait.sh:1.1	Sat Mar 17 12:33:11 2012
+++ src/tests/bin/sh/t_wait.sh	Sun Aug 23 03:15:16 2015
@@ -1,4 +1,4 @@
-# $NetBSD: t_wait.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
+# $NetBSD: t_wait.sh,v 1.2 2015/08/23 07:15:16 christos Exp $
 #
 # Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -32,28 +32,58 @@ individual_head() {
 individual_body() {
 	# atf-sh confuses wait for some reason; work it around by creating
 	# a helper script that executes /bin/sh directly.
-	cat helper.sh EOF
+	cat individualhelper.sh \EOF
 sleep 3 
 sleep 1 
 
 wait %1
-if [ \$? -ne 0 ]; then
+if [ $? -ne 0 ]; then
 echo Waiting of first job failed
 exit 1
 fi
 
 wait %2
-if [ \$? -ne 0 ]; then
+if [ $? -ne 0 ]; then
 echo Waiting of second job failed
 exit 1
 fi
 
 exit 0
 EOF
-	output=$(/bin/sh helper.sh)
+	output=$(/bin/sh individualhelper.sh)
 	[ $? -eq 0 ] || atf_fail ${output}
+	rm -f individualhelper.sh
+}
+
+atf_test_case kill
+kill_head() {
+	atf_set descr Tests that killing the shell while in wait calls trap
+}
+kill_body() {
+	# atf-sh confuses wait for some reason; work it around by creating
+	# a helper script that executes /bin/sh directly.
+	local s=$PWD/killhelper.sh
+	local z=/tmp/killhelper.$$ 
+	cat $s \EOF
+#!/bin/sh
+trap echo SIGHUP 1
+sleep 10 
+sl=$!
+wait
+echo $?
+EOF
+	chmod +x $s
+	$s  $z 
+	# XXX: built-in kill does not work?
+	/bin/kill -HUP $!
+	output=$(cat $z | tr '\n' ' ')
+	rm -f $s $z
+	if [ $output != SIGHUP 129  ]; then
+		atf_fail ${output} != 'SIGHUP 129 '
+	fi
 }
 
 atf_init_test_cases() {
 	atf_add_test_case individual
+	atf_add_test_case kill
 }



CVS commit: src/tests/bin/sh

2014-09-11 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Sep 11 18:25:30 UTC 2014

Modified Files:
src/tests/bin/sh: Makefile

Log Message:
Visit the Bureau of Redundancy Department.
From Henning Petersen in PR 49191.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/Makefile
diff -u src/tests/bin/sh/Makefile:1.3 src/tests/bin/sh/Makefile:1.4
--- src/tests/bin/sh/Makefile:1.3	Sat May 31 14:29:06 2014
+++ src/tests/bin/sh/Makefile	Thu Sep 11 18:25:30 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2014/05/31 14:29:06 christos Exp $
+# $NetBSD: Makefile,v 1.4 2014/09/11 18:25:30 dholland Exp $
 #
 
 .include bsd.own.mk
@@ -7,13 +7,6 @@ TESTSDIR = ${TESTSBASE}/bin/sh
 
 TESTS_SUBDIRS += dotcmd
 
-.include bsd.test.mk
-# $NetBSD: Makefile,v 1.3 2014/05/31 14:29:06 christos Exp $
-
-.include bsd.own.mk
-
-TESTSDIR=	${TESTSBASE}/bin/sh
-
 TESTS_SH=	t_compexit
 TESTS_SH+=	t_exit
 TESTS_SH+=	t_expand



CVS commit: src/tests/bin/sh/dotcmd

2014-07-27 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Sun Jul 27 14:24:17 UTC 2014

Modified Files:
src/tests/bin/sh/dotcmd: Makefile

Log Message:
Run scripts at build time via ${HOST_SH}


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/dotcmd/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/dotcmd/Makefile
diff -u src/tests/bin/sh/dotcmd/Makefile:1.1 src/tests/bin/sh/dotcmd/Makefile:1.2
--- src/tests/bin/sh/dotcmd/Makefile:1.1	Sat May 31 14:29:06 2014
+++ src/tests/bin/sh/dotcmd/Makefile	Sun Jul 27 14:24:17 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2014/05/31 14:29:06 christos Exp $
+# $NetBSD: Makefile,v 1.2 2014/07/27 14:24:17 apb Exp $
 #
 
 .include bsd.own.mk
@@ -19,7 +19,7 @@ FILESDIR_${cmd}_${cmd_scope} = ${TESTSDI
 FILESBUILD_${cmd}_${cmd_scope} = yes
 
 ${cmd}_${cmd_scope}: scoped_command
-	${.CURDIR}/scoped_command '${cmd_scope}' '${cmd}' '${cmd}' \
+	${HOST_SH} ${.CURDIR}/scoped_command '${cmd_scope}' '${cmd}' '${cmd}' \
 		'${.TARGET}'
 
 .  for dot_scope in case compound file for func subshell until while
@@ -31,7 +31,7 @@ FILESBUILD_${dot_scope}_${cmd}_${cmd_sco
 FILESMODE_${dot_scope}_${cmd}_${cmd_scope} = ${BINMODE}
 
 ${dot_scope}_${cmd}_${cmd_scope}: scoped_command
-	${.CURDIR}/scoped_command '${dot_scope}' \
+	${HOST_SH} ${.CURDIR}/scoped_command '${dot_scope}' \
 		'. ${cmd}_${cmd_scope}' 'dotcmd' 'dotcmd' '${.TARGET}'
 .  endfor
 . endfor



CVS commit: src/tests/bin/sh

2012-03-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 25 17:30:59 UTC 2012

Modified Files:
src/tests/bin/sh: t_exit.sh

Log Message:
ksh trap has been fixed.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_exit.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_exit.sh
diff -u src/tests/bin/sh/t_exit.sh:1.1 src/tests/bin/sh/t_exit.sh:1.2
--- src/tests/bin/sh/t_exit.sh:1.1	Sat Mar 17 12:33:11 2012
+++ src/tests/bin/sh/t_exit.sh	Sun Mar 25 13:30:59 2012
@@ -1,4 +1,4 @@
-# $NetBSD: t_exit.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
+# $NetBSD: t_exit.sh,v 1.2 2012/03/25 17:30:59 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -64,9 +64,9 @@ trap_subshell_body() {
 
 atf_test_case trap_zero__implicit_exit
 trap_zero__implicit_exit_body() {
+	# PR bin/6764: sh works but ksh does not
 	echo '( trap echo exiting 0 )' helper.sh
 	atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
-	atf_expect_fail PR bin/6764: sh works but ksh does not
 	atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
 }
 



CVS commit: src/tests/bin/sh

2012-03-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 25 18:50:19 UTC 2012

Modified Files:
src/tests/bin/sh: t_varquote.sh

Log Message:
PR/43597 was fixed


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_varquote.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_varquote.sh
diff -u src/tests/bin/sh/t_varquote.sh:1.1 src/tests/bin/sh/t_varquote.sh:1.2
--- src/tests/bin/sh/t_varquote.sh:1.1	Sat Mar 17 12:33:11 2012
+++ src/tests/bin/sh/t_varquote.sh	Sun Mar 25 14:50:19 2012
@@ -1,4 +1,4 @@
-# $NetBSD: t_varquote.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
+# $NetBSD: t_varquote.sh,v 1.2 2012/03/25 18:50:19 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -68,10 +68,9 @@ all_body() {
 atf_test_case nested_quotes_multiword
 nested_quotes_multiword_head() {
 	atf_set descr Tests that having nested quoting in a multi-word \
-	string works
+	string works (PR bin/43597)
 }
 nested_quotes_multiword_body() {
-	atf_expect_fail PR bin/43597
 	atf_check -s eq:0 -o match:first-word second-word -e empty \
 	/bin/sh -c 'echo ${foo:=first-word} second-word'
 }