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

2023-12-29 Thread Andrius V
On Thu, Dec 28, 2023 at 11:08 PM Robert Elz  wrote:
>
> [I could claim that the typo was deliberate, as part of
> the test  but that would be kind of absurd, sh does
> no spell checking to test.]
>
> kre
>

Thanks for clarification. I definitely had few instances when I needed
to revert spelling fixes, which were left on purpose for one reason or
another, fortunately it is not the case here :).


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

2023-12-28 Thread Robert Elz
Date:Thu, 28 Dec 2023 20:04:11 +
From:"Andrius Varanavicius" 
Message-ID:  <20231228200411.283ccf...@cvs.netbsd.org>

  | Modified Files:
  | src/tests/bin/sh: t_syntax.sh
  | Log Message:
  | s/synax/syntax/ in test description.

Thanks for the correction, but, not that it matters, that
was in the test code, not just a description.

[I could claim that the typo was deliberate, as part of
the test  but that would be kind of absurd, sh does
no spell checking to test.]

kre



CVS commit: src/tests/bin/sh

2023-12-28 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Thu Dec 28 20:04:11 UTC 2023

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

Log Message:
s/synax/syntax/ in test description.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 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.



CVS commit: src/tests/bin/sh

2023-12-28 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Thu Dec 28 20:04:11 UTC 2023

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

Log Message:
s/synax/syntax/ in test description.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 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.12 src/tests/bin/sh/t_syntax.sh:1.13
--- src/tests/bin/sh/t_syntax.sh:1.12	Mon Nov 22 05:07:15 2021
+++ src/tests/bin/sh/t_syntax.sh	Thu Dec 28 20:04:10 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.12 2021/11/22 05:07:15 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.13 2023/12/28 20:04:10 andvar Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -114,7 +114,7 @@ b_comments_body() {
 		'echo \## #\#'
 
 	cat <<-'DONE' |
-		# test comments do not provoke synax errors !\
+		# test comments do not provoke syntax errors !\
 		echo foo # ( { " hello
 		while : # that's forever
 		do	# the following command list



CVS commit: src/tests/bin/sh

2023-05-11 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu May 11 10:08:35 UTC 2023

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

Log Message:
Fix building the debugging tarball of the directory tree created for
the pathname matching tests ... this is not used in any way in a normal
test run, but if there are problems, one needs a mechanism to discover
whether the issue is with the code that creates the directory tree in the
test, or with the matching (either what the test expects to happen, or
what the shell actually does).   The couple of lines being fixed here make
that mechanism work --- I have had this in my private sources for years
now, but never got around to committing it.   It is time.  NFC for any
normal test run.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 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.6 src/tests/bin/sh/t_patterns.sh:1.7
--- src/tests/bin/sh/t_patterns.sh:1.6	Thu May 11 01:50:40 2023
+++ src/tests/bin/sh/t_patterns.sh	Thu May 11 10:08:34 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_patterns.sh,v 1.6 2023/05/11 01:50:40 gutteridge Exp $
+# $NetBSD: t_patterns.sh,v 1.7 2023/05/11 10:08:34 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -301,8 +301,8 @@ filename_expansion_body() {
 	esac
 	case "${ATF_TEST_SAVE_FILES}" in
 	'')	;;
-	/*)	(cd ../..; tar cf "${ATF_TEST_SAVE_FILES}" D) ;;
-	*)	(cd ../..; tar cf "${TMPDIR:-/tmp}/${ATF_TEST_SAVE_FILES}" D) ;;
+	/*)	(cd ..; tar cf "${ATF_TEST_SAVE_FILES}" .D) ;;
+	*)	(cd ..; tar cf "${TMPDIR:-/tmp}/${ATF_TEST_SAVE_FILES}" .D) ;;
 	esac
 
 	# Now we have lots of files, try some matching



CVS commit: src/tests/bin/sh

2023-05-11 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu May 11 10:08:35 UTC 2023

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

Log Message:
Fix building the debugging tarball of the directory tree created for
the pathname matching tests ... this is not used in any way in a normal
test run, but if there are problems, one needs a mechanism to discover
whether the issue is with the code that creates the directory tree in the
test, or with the matching (either what the test expects to happen, or
what the shell actually does).   The couple of lines being fixed here make
that mechanism work --- I have had this in my private sources for years
now, but never got around to committing it.   It is time.  NFC for any
normal test run.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 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.



CVS commit: src/tests/bin/sh

2023-05-10 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Thu May 11 01:50:40 UTC 2023

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

Log Message:
t_patterns.sh: fix naming of head() of filename_expansion


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 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.5 src/tests/bin/sh/t_patterns.sh:1.6
--- src/tests/bin/sh/t_patterns.sh:1.5	Wed Jul 10 05:57:43 2019
+++ src/tests/bin/sh/t_patterns.sh	Thu May 11 01:50:40 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_patterns.sh,v 1.5 2019/07/10 05:57:43 martin Exp $
+# $NetBSD: t_patterns.sh,v 1.6 2023/05/11 01:50:40 gutteridge Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -173,7 +173,7 @@ results()
 ### End helpers
 
 atf_test_case filename_expansion
-filename_expansion() {
+filename_expansion_head() {
 	atf_set descr "Test correct operation of filename expansion"
 }
 filename_expansion_body() {



CVS commit: src/tests/bin/sh

2023-05-10 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Thu May 11 01:50:40 UTC 2023

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

Log Message:
t_patterns.sh: fix naming of head() of filename_expansion


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 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.



CVS commit: src/tests/bin/sh

2023-05-10 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Thu May 11 00:32:48 UTC 2023

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

Log Message:
t_cmdsub.sh: fix naming of head() of cmdsub_paren_tests


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 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.5 src/tests/bin/sh/t_cmdsub.sh:1.6
--- src/tests/bin/sh/t_cmdsub.sh:1.5	Fri Jun 16 07:37:41 2017
+++ src/tests/bin/sh/t_cmdsub.sh	Thu May 11 00:32:48 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_cmdsub.sh,v 1.5 2017/06/16 07:37:41 kre Exp $
+# $NetBSD: t_cmdsub.sh,v 1.6 2023/05/11 00:32:48 gutteridge Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -513,7 +513,7 @@ u_nested_backticks_in_heredoc_body() {
 }
 
 atf_test_case v_cmdsub_paren_tests
-v_cmdsub__paren_tests_head() {
+v_cmdsub_paren_tests_head() {
 	atf_set "descr" "tests with cmdsubs containing embedded ')'"
 }
 v_cmdsub_paren_tests_body() {



CVS commit: src/tests/bin/sh

2023-05-10 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Thu May 11 00:32:48 UTC 2023

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

Log Message:
t_cmdsub.sh: fix naming of head() of cmdsub_paren_tests


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 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.



CVS commit: src/tests/bin/sh

2023-03-05 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Mar  6 05:54:54 UTC 2023

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

Log Message:
Adjust the tilde expansion test to deal with (very) recent changes
to what the shell produces for tilde expansions, when the expansion
of the tilde prefix ends with '/' and the character immediately following
is another '/' - previously /bin/sh (and most other shells, but not all)
retained both slashes, and this test expected that behaviour.

No longer, now only one of the two will appear.  Adjust the expected
test results accordingly, and add an extra loop iteration to make sure
this is thoroughly tested (one more tilde expansion value).

Also, add two new test cases that test for the new (explicit - though
it was always stated this way, but not as explicitly) that if HOME is
an empty string (not unset - that remains an unspecified case, as it
was) then the expansion of ~ must generate "", and not nothing.
The current test was unable to distinguish those two, since it
simply looked for characters in the output, so add a new test cases
explicitly to test for this particular case.   This also means (also
previously in the standard, but not as explicitly) that shells are
not permitted to decide "The ~ expansion produces an empty string, that
is weird, let's generate something else instead" which some shells were
doing.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 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.22 src/tests/bin/sh/t_expand.sh:1.23
--- src/tests/bin/sh/t_expand.sh:1.22	Sat May  4 02:52:22 2019
+++ src/tests/bin/sh/t_expand.sh	Mon Mar  6 05:54:54 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_expand.sh,v 1.22 2019/05/04 02:52:22 kre Exp $
+# $NetBSD: t_expand.sh,v 1.23 2023/03/06 05:54:54 kre Exp $
 #
 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -432,7 +432,7 @@ tilde_head() {
 	atf_set descr "Checks that the ~ expansions work"
 }
 tilde_body() {
-	for HOME in '' / /home/foo \
+	for HOME in '' / /home/foo /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
@@ -440,22 +440,22 @@ tilde_body() {
 		atf_check -s exit:0 -e empty \
 			-o inline:'HOME\t'"${HOME}"'
 ~\t'"${HOME}"'
-~/foobar\t'"${HOME}"'/foobar
+~/foobar\t'"${HOME%/}"'/foobar
 "$V"\t'"${HOME}"'
 "$X"\t~
 "$Y"\t'"${HOME}"':'"${HOME}"'
-"$YY"\t'"${HOME}"'/foo:'"${HOME}"'/bar
-"$Z"\t'"${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}"'/~
+$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' \
+${UUU:=~/:~}\t'"${HOME%/}"'/:'"${HOME}"'
+${U4:=~/:~/}\t'"${HOME%/}"'/:'"${HOME%/}"'/\n' \
 			${TEST_SH} -s <<- \EOF
 unset -v U UU UUU U4
 V=~
@@ -484,6 +484,15 @@ ${U4:=~/:~/}\t'"${HOME}"'/:'"${HOME}"'/\
 			EOF
 	done
 
+	# Verify that when HOME is "" expanding a bare ~
+	# makes an empty word, not nothing (or anything else)
+	HOME=""
+	export HOME
+	atf_check -s exit:0 -e empty -o inline:'1:<>\n' ${TEST_SH} -c \
+		'set -- ~ ; IFS=, ; printf '"'%d:<%s>\\n'"' "$#" "$*"'
+	atf_check -s exit:0 -e empty -o inline:'4:<,X,,/>\n' ${TEST_SH} -c \
+		'set -- ~ X ~ ~/ ; IFS=, ; printf '"'%d:<%s>\\n'"' "$#" "$*"'
+
 	# Testing ~user is harder, so, perhaps later...
 }
 



CVS commit: src/tests/bin/sh

2023-03-05 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Mar  6 05:54:54 UTC 2023

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

Log Message:
Adjust the tilde expansion test to deal with (very) recent changes
to what the shell produces for tilde expansions, when the expansion
of the tilde prefix ends with '/' and the character immediately following
is another '/' - previously /bin/sh (and most other shells, but not all)
retained both slashes, and this test expected that behaviour.

No longer, now only one of the two will appear.  Adjust the expected
test results accordingly, and add an extra loop iteration to make sure
this is thoroughly tested (one more tilde expansion value).

Also, add two new test cases that test for the new (explicit - though
it was always stated this way, but not as explicitly) that if HOME is
an empty string (not unset - that remains an unspecified case, as it
was) then the expansion of ~ must generate "", and not nothing.
The current test was unable to distinguish those two, since it
simply looked for characters in the output, so add a new test cases
explicitly to test for this particular case.   This also means (also
previously in the standard, but not as explicitly) that shells are
not permitted to decide "The ~ expansion produces an empty string, that
is weird, let's generate something else instead" which some shells were
doing.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 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.



CVS commit: src/tests/bin/sh

2021-11-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Nov 22 05:21:54 UTC 2021

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

Log Message:
PR bin/53550

/bin/sh's processing of here doc expansions has changed.   Now it happens
in the context of the parent shell, so side effects are visible there,
just like all other redirection expansions.

We need to stop testing that that doesn't happen, and instead test
that it does.   This is that change.

Add another test case which is testing exactly the example from the PR
(well, with a different exit status, 1 is too generic and could happen
by accident) to make sure we don't reintroduce that bug sometime.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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.8 src/tests/bin/sh/t_here.sh:1.9
--- src/tests/bin/sh/t_here.sh:1.8	Thu Sep  9 00:04:51 2021
+++ src/tests/bin/sh/t_here.sh	Mon Nov 22 05:21:54 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_here.sh,v 1.8 2021/09/09 00:04:51 kre Exp $
+# $NetBSD: t_here.sh,v 1.9 2021/11/22 05:21:54 kre Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -515,13 +515,36 @@ quoting_body() {
 	results
 }
 
+#
+# This next test is really just testing what our shell happens to do.
+# There doesn't seem to be any spec on in which context expansions
+# in redirects are processed.   Most shells do them in the parent
+# shell context, meaning that side effects of the expansion become
+# visible to the shell - a couple process redirect expansions in
+# a subshell, meaning that side effects are lost.
+#
+# Before PR bin/53550 was fixed, the NetBSD sh evaluated all redirect
+# expansions, except here documents, in the context of the shell, and
+# here document redirects in a subshell context.   That distinction
+# makes no real sense (and only an old, and maybe still current, FreeBSD
+# shell shares that pecadillo.)   Afer that fix, the NetBSD shell joins
+# almost all others in expanding redirects (all of them) in the shell
+# context, meaning that side effects of here documenty expansions become
+# visible in the shell.
+#
+# Before the fix, we used to get "2\n1\n" as the output from this
+# test, now the variable assignment in the here document persists
+# and we get "2\n2\n" as do most other shells.  (bash is a notable
+# exception, but it does all redirect expansions in a subshell context)
+#
+
 atf_test_case side_effects
 side_effects_head() {
 	atf_set "descr" "Tests how side effects in here documents are handled"
 }
 side_effects_body() {
 
-	atf_check -s exit:0 -o inline:'2\n1\n' -e empty ${TEST_SH} -c '
+	atf_check -s exit:0 -o inline:'2\n2\n' -e empty ${TEST_SH} -c '
 		unset X
 		cat <<-EOF
 		${X=2}
@@ -530,6 +553,23 @@ side_effects_body() {
 		'
 }
 
+# This is a test for the specific bug reported in PR bin/53550
+# This should work in any shell.
+
+atf_test_case exit_status
+exit_status_head() {
+	atf_set descr "Tests exit status of a command substitution in a heredoc"
+}
+exit_status_body() {
+
+	# PR bin/53550 test
+	atf_check -s exit:7 -o empty -e empty ${TEST_SH} -c '
+		<<-EOF
+		$(exit 7)
+		EOF
+		'
+}
+
 # The following tests a problem reported on the austin-list 2021-09-08
 # by oguzismailuy...@gmail.com ... it affected all ash derived shells
 atf_test_case hard_cases
@@ -623,6 +663,7 @@ vicious_body() {
 atf_init_test_cases() {
 	atf_add_test_case do_simple	# not worthy of a comment
 	atf_add_test_case end_markers	# the mundane, the weird, the bizarre
+	atf_add_test_case exit_status	# PR bin/53550, cmdsub in heredoc
 	atf_add_test_case incomplete	# where the end marker isn't...
 	atf_add_test_case lineends	# test weird line endings in heredocs
 	atf_add_test_case multiple	# multiple << operators on one cmd



CVS commit: src/tests/bin/sh

2021-11-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Nov 22 05:21:54 UTC 2021

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

Log Message:
PR bin/53550

/bin/sh's processing of here doc expansions has changed.   Now it happens
in the context of the parent shell, so side effects are visible there,
just like all other redirection expansions.

We need to stop testing that that doesn't happen, and instead test
that it does.   This is that change.

Add another test case which is testing exactly the example from the PR
(well, with a different exit status, 1 is too generic and could happen
by accident) to make sure we don't reintroduce that bug sometime.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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.



CVS commit: src/tests/bin/sh

2021-11-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Nov 22 05:07:15 UTC 2021

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

Log Message:
More tests that were doing  ... | atf_check ...

which allows the atf_check to fail without causing the test to fail
(unless this is the (very) last command in the test case, in which case it
will fail with what can be interpreted as an internal error)/

Check for this failing and explicitly atf_fail whwn it does.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/bin/sh/t_option.sh
cvs rdiff -u -r1.11 -r1.12 src/tests/bin/sh/t_syntax.sh
cvs rdiff -u -r1.1 -r1.2 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.



CVS commit: src/tests/bin/sh

2021-11-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Nov 22 05:07:15 UTC 2021

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

Log Message:
More tests that were doing  ... | atf_check ...

which allows the atf_check to fail without causing the test to fail
(unless this is the (very) last command in the test case, in which case it
will fail with what can be interpreted as an internal error)/

Check for this failing and explicitly atf_fail whwn it does.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/bin/sh/t_option.sh
cvs rdiff -u -r1.11 -r1.12 src/tests/bin/sh/t_syntax.sh
cvs rdiff -u -r1.1 -r1.2 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/t_option.sh
diff -u src/tests/bin/sh/t_option.sh:1.7 src/tests/bin/sh/t_option.sh:1.8
--- src/tests/bin/sh/t_option.sh:1.7	Thu Jul 11 03:49:51 2019
+++ src/tests/bin/sh/t_option.sh	Mon Nov 22 05:07:15 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_option.sh,v 1.7 2019/07/11 03:49:51 msaitoh Exp $
+# $NetBSD: t_option.sh,v 1.8 2021/11/22 05:07:15 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -454,7 +454,8 @@ set_v_body() {
 			-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}
+${TEST_SH} ||
+		atf_fail '111 222 333 test failure'
 }
 
 atf_test_case set_x

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.11 src/tests/bin/sh/t_syntax.sh:1.12
--- src/tests/bin/sh/t_syntax.sh:1.11	Tue Nov 16 11:12:14 2021
+++ src/tests/bin/sh/t_syntax.sh	Mon Nov 22 05:07:15 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.11 2021/11/16 11:12:14 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.12 2021/11/22 05:07:15 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -113,7 +113,7 @@ b_comments_body() {
 	atf_check -s exit:0 -o 'inline:##\n' -e empty ${TEST_SH} -c \
 		'echo \## #\#'
 
-	cat <<-'DONE'|atf_check -s exit:0 -o inline:'foo\n' -e empty ${TEST_SH}
+	cat <<-'DONE' |
 		# test comments do not provoke synax errors !\
 		echo foo # ( { " hello
 		while : # that's forever
@@ -124,6 +124,8 @@ b_comments_body() {
 		# "hello
 		exit 0
 	DONE
+		atf_check -s exit:0 -o inline:'foo\n' -e empty ${TEST_SH} ||
+			atf_fail "ignoring comments"
 }
 
 atf_test_case c_line_wrapping

Index: src/tests/bin/sh/t_varval.sh
diff -u src/tests/bin/sh/t_varval.sh:1.1 src/tests/bin/sh/t_varval.sh:1.2
--- src/tests/bin/sh/t_varval.sh:1.1	Wed Mar 16 15:49:19 2016
+++ src/tests/bin/sh/t_varval.sh	Mon Nov 22 05:07:15 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_varval.sh,v 1.1 2016/03/16 15:49:19 christos Exp $
+# $NetBSD: t_varval.sh,v 1.2 2021/11/22 05:07:15 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -82,23 +82,28 @@ aaa_head() {
 aaa_body() {
 	oneline "echo " 9 '' |
 		atf_check -s exit:0 -o inline:'prefix\tsuffix\n' -e empty \
-			${TEST_SH}
+			${TEST_SH} ||
+atf_fail 'echo 9 -> tab'
 
 	oneline "VAR=" 65 '; echo "${#VAR}:${VAR}"' |
 		atf_check -s exit:0 -o inline:'13:prefixAsuffix\n' -e empty \
-			${TEST_SH}
+			${TEST_SH} ||
+atf_fail '65 -> A'
 
 	oneline "VAR=" 1 '; echo "${#VAR}:${VAR}"' |
 		atf_check -s exit:0 -o inline:'13:prefixsuffix\n' -e empty \
-			${TEST_SH}
+			${TEST_SH} ||
+atf_fail '1 -> ^A'
 
 	oneline "VAR=" 10 '; echo "${#VAR}:${VAR}"' |
 		atf_check -s exit:0 -o inline:'13:prefix\nsuffix\n' -e empty \
-			${TEST_SH}
+			${TEST_SH} ||
+atf_fail '10 -> \n'
 
 	rm -f prefix* 2>/dev/null || :
 	oneline "echo hello >" 45 "" |
-		atf_check -s exit:0 -o empty -e empty ${TEST_SH}
+		atf_check -s exit:0 -o empty -e empty ${TEST_SH} ||
+			atf_fail 'redir into 45 -> E'
 	test -f "prefix-suffix" ||
 		atf_fail "failed to create prefix-suffix (45)"
 	test -s "prefix-suffix" ||
@@ -119,7 +124,8 @@ assignment_body() {
 
 	rm -f results || :
 	mkdata "VAR=" -- '; echo ${#VAR}' |
-		atf_check -s exit:0 -o save:results -e empty ${TEST_SH}
+		atf_check -s exit:0 -o save:results -e empty ${TEST_SH} ||
+			atf_fail 'making results'
 	test -z $( grep -v "^13$" results ) ||
 		atf_fail "Incorrect lengths: $(grep -nv '^13$' results)"
 
@@ -136,7 +142,8 @@ cmdline_body() {
 
 	rm -f results || :
 	mkdata "VAR=" -- '; echo "${VAR}"' |
-		atf_check -s exit:0 -o save:results -e empty ${TEST_SH}
+		atf_check -s exit:0 -o save:results -e empty ${TEST_SH} ||
+			atf_fail 'making results'
 
 	# 256 because one output line contains a \n ...
 	test $( wc -l < results ) -eq 256 ||
@@ -165,7 +172,8 @@ redirect_body() {
 
 	mkdir prefix		# one of the files will be prefix/suffix
 	mkdata "VAR=" -- '; echo "${VAR}" > "${VAR}"' |
-		atf_check -s exit:0 -o empty -e empty ${TEST_SH}
+		atf_check -s exit:0 -o empty -e empty ${TEST_SH} ||
+			atf_fail "$VAR -> ./$VAR"
 
 

CVS commit: src/tests/bin/sh

2021-11-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Nov 21 20:50:35 UTC 2021

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

Log Message:
Deal with a lot more pipes into atf_check missed last time.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 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.13 src/tests/bin/sh/t_redir.sh:1.14
--- src/tests/bin/sh/t_redir.sh:1.13	Tue Nov 16 11:15:26 2021
+++ src/tests/bin/sh/t_redir.sh	Sun Nov 21 20:50:35 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.13 2021/11/16 11:15:26 kre Exp $
+# $NetBSD: t_redir.sh,v 1.14 2021/11/21 20:50:35 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -42,30 +42,36 @@ basic_test_method_test_body()
 {
 	cat <<- 'DONE' |
 	DONE
-	atf_check -s exit:0 -o empty -e empty ${TEST_SH}
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} ||
+		atf_fail 'empty piped input'
 	cat <<- 'DONE' |
 	DONE
-	atf_check -s exit:0 -o match:0 -e empty ${TEST_SH} -c 'wc -l'
+	atf_check -s exit:0 -o match:0 -e empty ${TEST_SH} -c 'wc -l' ||
+		atf_fail 'empty piped input line count'
 
 	cat <<- 'DONE' |
 		echo hello
 	DONE
-	atf_check -s exit:0 -o match:hello -e empty ${TEST_SH} 
+	atf_check -s exit:0 -o match:hello -e empty ${TEST_SH}  ||
+		atf_fail 'piped hello'
 	cat <<- 'DONE' |
 		echo hello
 	DONE
-	atf_check -s exit:0 -o match:1 -e empty ${TEST_SH} -c 'wc -l'
+	atf_check -s exit:0 -o match:1 -e empty ${TEST_SH} -c 'wc -l' ||
+		atf_fail 'piped hello line count'
 
 	cat <<- 'DONE' |
 		echo hello\
 	world
 	DONE
-	atf_check -s exit:0 -o match:helloworld -e empty ${TEST_SH} 
+	atf_check -s exit:0 -o match:helloworld -e empty ${TEST_SH}  ||
+		atf_fail 'piped hello world'
 	cat <<- 'DONE' |
 		echo hello\
 	world
 	DONE
-	atf_check -s exit:0 -o match:2 -e empty ${TEST_SH} -c 'wc -l'
+	atf_check -s exit:0 -o match:2 -e empty ${TEST_SH} -c 'wc -l' ||
+		atf_fail 'piped hello world line check'
 
 	printf '%s\n%s\n%s\n' Line1 Line2 Line3 > File
 	atf_check -s exit:0 -o inline:'Line1\nLine2\nLine3\n' -e empty \
@@ -83,7 +89,16 @@ basic_test_method_test_body()
 		EOF
 	DONE
 	atf_check -s exit:0 -o match:ARGS=4 -o match:'-X- -- -- -Y-' \
-		-o match:X=X -o match:'Y=\$4' -e empty ${TEST_SH} 
+		-o match:X=X -o match:'Y=\$4' -e empty ${TEST_SH}  ||
+			atf_fail "complex piped input"
+
+	cat <<- 'DONE' |
+		echo expect to see a non-detected failure here
+	DONE
+	atf_check -s exit:1 -o empty -e empty ${TEST_SH} &&
+		atf_fail "Failed to fail as expected"
+
+	return 0
 }
 
 atf_test_case do_input_redirections
@@ -129,7 +144,8 @@ do_input_redirections_body()
 	EOF
 	atf_check -s exit:0 -e empty \
 		-o inline:'First Line\nFirst Line\nFirst Line\n' \
-		${TEST_SH}
+		${TEST_SH} ||
+			atf_fail 'loop rereading first line'
 
 	cat <<- 'EOF' |
 		for l in 1 2 3; do
@@ -139,7 +155,8 @@ do_input_redirections_body()
 	EOF
 	atf_check -s exit:0 -e empty \
 		-o inline:'First Line\nSecond Line\nLine 3\n' \
-		${TEST_SH}
+		${TEST_SH} ||
+			atf_fail 'loop reading file'
 
 	cat <<- 'EOF' |
 		for l in 1 2 3; do
@@ -149,7 +166,8 @@ do_input_redirections_body()
 	EOF
 	atf_check -s exit:0 -e empty \
 		-o inline:'First Line\nFirst Line\nFirst Line\n' \
-		${TEST_SH}
+		${TEST_SH} ||
+			atf_fail 'double redirect'
 
 	cat <<- 'EOF' |
 		line=
@@ -160,7 +178,8 @@ do_input_redirections_body()
 	EOF
 	atf_check -s exit:0 -e empty \
 		-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
-		${TEST_SH}
+		${TEST_SH} ||
+			atf_fail 'read and test content'
 
 	cat <<- 'EOF' |
 		while :; do
@@ -170,7 +189,8 @@ do_input_redirections_body()
 	EOF
 	atf_check -s exit:0 -e empty \
 		-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
-		${TEST_SH}
+		${TEST_SH} ||
+			atf_fail 'read and test status'
 
 	cat <<- 'EOF' |
 		l=''
@@ -184,7 +204,8 @@ do_input_redirections_body()
 	EOF
 	atf_check -s exit:0 -e empty \
 		-o inline:'First Line\nFirst Line\nFirst Line\nDONE\n' \
-		${TEST_SH}
+		${TEST_SH} ||
+			atf_fail 'read 3 lines'
 
 	cat <<- 'EOF' |
 		while read line
@@ -195,7 +216,8 @@ do_input_redirections_body()
 	EOF
 	atf_check -s exit:0 -e empty \
 		-o inline:'First Line\nSecond Line\nLine 3\nEND\nDONE\n' \
-		${TEST_SH}
+		${TEST_SH} ||
+			atf_fail 'read to EOF'
 
 	cat <<- 'EOF' |
 		l=''
@@ -208,7 +230,9 @@ do_input_redirections_body()
 		echo DONE
 	EOF
 	atf_check -s exit:0 -e empty \
-		-o inline:'First Line\nSecond Line\nLine 3\nDONE\n' ${TEST_SH}
+		-o inline:'First Line\nSecond Line\nLine 3\nDONE\n' \
+		${TEST_SH} ||
+			atf_fail 'read 3 and break'
 
 	cat <<- 'EOF' |
 		l=''
@@ -223,7 +247,8 @@ do_input_redirections_body()
 	EOF
 	atf_check -s exit:0 -e empty \
 	-o inline:'First Line:First Line\nFirst Line:Second Line\nDONE\n' \
-		${TEST_SH}
+		${TEST_SH} ||
+			atf_fail 'read and read again'
 }
 
 

CVS commit: src/tests/bin/sh

2021-11-21 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Nov 21 20:50:35 UTC 2021

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

Log Message:
Deal with a lot more pipes into atf_check missed last time.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 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.



CVS commit: src/tests/bin/sh

2021-11-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Nov 16 11:15:26 UTC 2021

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

Log Message:
Fix a test that has been (unnoticed) failing ever since printf(1) was
changed to exit(1) when it detects a write error to stdout.

Running printf with stdout closed is guaranteed to generate such a
condition.

Until the previous commit, while the test case was actually failing
(stderr was expected to be empty. and was not) this was unnoticed.
We don't want the output (obviously), we also don't want the error
message, so just direct the latter to /dev/null.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 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.12 src/tests/bin/sh/t_redir.sh:1.13
--- src/tests/bin/sh/t_redir.sh:1.12	Tue Nov 16 11:12:14 2021
+++ src/tests/bin/sh/t_redir.sh	Tue Nov 16 11:15:26 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.12 2021/11/16 11:12:14 kre Exp $
+# $NetBSD: t_redir.sh,v 1.13 2021/11/16 11:15:26 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -927,7 +927,7 @@ validate_fn_redirects_body()
 
 	echo '
 		. ./f-def || echo >&2 FAIL
-		f >&-
+		f >&- 2>/dev/null
 		printf "%s\n" stdin2
 	' | atf_check -s exit:0 -o inline:'stdin2\n' -e empty ${TEST_SH} ||
 		atf_fail "stdin2 test failure"



CVS commit: src/tests/bin/sh

2021-11-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Nov 16 11:15:26 UTC 2021

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

Log Message:
Fix a test that has been (unnoticed) failing ever since printf(1) was
changed to exit(1) when it detects a write error to stdout.

Running printf with stdout closed is guaranteed to generate such a
condition.

Until the previous commit, while the test case was actually failing
(stderr was expected to be empty. and was not) this was unnoticed.
We don't want the output (obviously), we also don't want the error
message, so just direct the latter to /dev/null.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 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.



CVS commit: src/tests/bin/sh

2021-11-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Nov 16 11:12:15 UTC 2021

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

Log Message:
Correct a systematic atf_check usage error.   One must not pipe into
atf_check and simply expect it to work - the shell is permitted to,
and our shell currently does, run all commands in a pipeline in subshell
environments - when atf_check attempts to exit to indicate failure, it
only exits from that subshell, and the rest of the test continues, usually
to indicate success

Instead, when it is necessary (or just convenient) to pipe into atf_check
check the exit status of the pipeline (if atf_check is not last, which it
would usually be, then we would need the pipefail option set - there are
currently no such cases), and explicitly fail if atf_check did not exit(0).


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/bin/sh/t_redir.sh
cvs rdiff -u -r1.10 -r1.11 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_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.11 src/tests/bin/sh/t_redir.sh:1.12
--- src/tests/bin/sh/t_redir.sh:1.11	Wed May 19 22:43:18 2021
+++ src/tests/bin/sh/t_redir.sh	Tue Nov 16 11:12:14 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.11 2021/05/19 22:43:18 kre Exp $
+# $NetBSD: t_redir.sh,v 1.12 2021/11/16 11:12:14 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -561,9 +561,11 @@ named_fd_redirections_body()
 		atf_require_prog cat
 
 		echo GOOD | atf_check -s exit:0 -o inline:'GOOD\n' -e empty \
-			${TEST_SH} -c 'read var &2 FAIL
 		f
 		printf '%s\n' stdin1
-	"| atf_check -s exit:0 -o inline:'In-Func\nstdin1\n' -e empty ${TEST_SH}
+	" | atf_check -s exit:0 -o inline:'In-Func\nstdin1\n' -e empty \
+	  ${TEST_SH} ||
+		atf_fail "stdin1 test failure"
 
 	echo '
 		. ./f-def || echo >&2 FAIL
 		f >&-
 		printf "%s\n" stdin2
-	' | atf_check -s exit:0 -o inline:'stdin2\n' -e empty ${TEST_SH}
+	' | atf_check -s exit:0 -o inline:'stdin2\n' -e empty ${TEST_SH} ||
+		atf_fail "stdin2 test failure"
 
 	cat <<- 'DONE' > fgh.def
 		f() {
@@ -983,7 +988,8 @@ validate_fn_redirects_body()
 		echo X $( f >&- & sleep 1; g >&- & sleep 1 ; h ) Y
 		sleep 3
 		exec 4>&1 || echo FD_FAIL
-	' | atf_check -s exit:0 -o inline:'fghX Y\nGF' -e empty ${TEST_SH}
+	' | atf_check -s exit:0 -o inline:'fghX Y\nGF' -e empty ${TEST_SH} ||
+		atf_fail "48875 stdin variant failure"
 }
 
 atf_init_test_cases() {

Index: src/tests/bin/sh/t_syntax.sh
diff -u src/tests/bin/sh/t_syntax.sh:1.10 src/tests/bin/sh/t_syntax.sh:1.11
--- src/tests/bin/sh/t_syntax.sh:1.10	Wed Nov 14 02:37:51 2018
+++ src/tests/bin/sh/t_syntax.sh	Tue Nov 16 11:12:14 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.10 2018/11/14 02:37:51 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.11 2021/11/16 11:12:14 kre Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -134,35 +134,39 @@ c_line_wrapping_body() {
 	atf_require_prog ls
 	atf_require_prog printf
 
-	cat <<- 'DONE' | atf_check -s exit:0 -o ignore -e empty ${TEST_SH} -e
+	cat <<- 'DONE' | atf_check -s exit:0 -o ignore -e empty ${TEST_SH} -e ||
 		l\
 		s
 	DONE
+		atf_fail "#1: ls wrapped fails"
 
-	cat <<- 'DONE' | atf_check -s exit:7 -o empty -e empty ${TEST_SH}
+	cat <<- 'DONE' | atf_check -s exit:7 -o empty -e empty ${TEST_SH} ||
 		e\
 		x\
 		it \
 		7
 	DONE
+		atf_fail "#2: exit7 wrapped fails"
 
 	# Have to do this twice as cannot say "any exit code but 0 or 7" ...
 	cat <<- 'DONE' | atf_check -s not-exit:0 -o empty -e not-empty \
-	${TEST_SH}
+	${TEST_SH} ||
 		e\
 		x\
 		it\
 		7
 	DONE
+		atf_fail "#3a: !exit(0||7) badly wrapped fails (0)"
 	cat <<- 'DONE' | atf_check -s not-exit:7 -o empty -e not-empty \
-	${TEST_SH}
+	${TEST_SH} ||
 		e\
 		x\
 		it\
 		7
 	DONE
+		atf_fail "#3b: !exit(0||7) badly wrapped fails (7)"
 
-	cat <<- 'DONE' | atf_check -s exit:0 -o empty -e empty  ${TEST_SH}
+	cat <<- 'DONE' | atf_check -s exit:0 -o empty -e empty  ${TEST_SH} ||
 		wh\
 		il\
 		e \
@@ -173,9 +177,10 @@ c_line_wrapping_body() {
 		;
 		done
 	DONE
+		atf_fail "#4: wrapped while fails"
 
 	cat <<- 'DONE' | atf_check -s exit:0 -o inline:'hellohellohellohello' \
-	-e empty ${TEST_SH}
+	-e empty ${TEST_SH} ||
 		V\
 		AR=hel\
 		lo
@@ -214,8 +219,9 @@ c_line_wrapping_body() {
 		 \
 		FAIL}
 	DONE
+		atf_fail "#5: wrapped var expansions fails"
 
-	cat <<- 'DONE' | atf_check -s exit:0 -o inline:'2\n' ${TEST_SH}
+	cat <<- 'DONE' | atf_check -s exit:0 -o inline:'2\n' ${TEST_SH} ||
 		l\
 		s=7 bi\
 		n\
@@ -225,6 +231,7 @@ c_line_wrapping_body() {
 		( ls /bin )\
 		)
 	DONE
+		atf_fail "#6: wrapped command substitution fails"
 
 	# Inspired by src/etc/MAKEDEV.tmpl failure with (broken)
 	# sh LINENO code...  avoid it happening again...
@@ -248,7 +255,7 @@ c_line_wrapping_body() {
 			done

CVS commit: src/tests/bin/sh

2021-11-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Nov 16 11:12:15 UTC 2021

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

Log Message:
Correct a systematic atf_check usage error.   One must not pipe into
atf_check and simply expect it to work - the shell is permitted to,
and our shell currently does, run all commands in a pipeline in subshell
environments - when atf_check attempts to exit to indicate failure, it
only exits from that subshell, and the rest of the test continues, usually
to indicate success

Instead, when it is necessary (or just convenient) to pipe into atf_check
check the exit status of the pipeline (if atf_check is not last, which it
would usually be, then we would need the pipefail option set - there are
currently no such cases), and explicitly fail if atf_check did not exit(0).


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/bin/sh/t_redir.sh
cvs rdiff -u -r1.10 -r1.11 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.



CVS commit: src/tests/bin/sh

2021-09-08 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Sep  9 00:04:51 UTC 2021

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

Log Message:
Add a new test case to check for correct parsing and execution
of a few bizarre here document usages, such as

: << do | for x in xxx
do
do echo $x
done

which should work, but never have done.  (See the source for others).

This test case will currently fail, until the bug is fixed
(already done, to be committed very soon).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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.7 src/tests/bin/sh/t_here.sh:1.8
--- src/tests/bin/sh/t_here.sh:1.7	Tue Jan 22 14:31:53 2019
+++ src/tests/bin/sh/t_here.sh	Thu Sep  9 00:04:51 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_here.sh,v 1.7 2019/01/22 14:31:53 kre Exp $
+# $NetBSD: t_here.sh,v 1.8 2021/09/09 00:04:51 kre Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -530,6 +530,35 @@ side_effects_body() {
 		'
 }
 
+# The following tests a problem reported on the austin-list 2021-09-08
+# by oguzismailuy...@gmail.com ... it affected all ash derived shells
+atf_test_case hard_cases
+hard_cases_head() {
+	atf_set "descr" \
+		"Tests here docs in positions that have confised our parser"
+}
+hard_cases_body() {
+
+	atf_check -s exit:0 -o inline:'xxx\n' -e empty ${TEST_SH} -c '
+		: <<- do | for x in xxx
+		do
+		do echo $x
+		done'
+
+	atf_check -s exit:0 -o inline:'xxx\n' -e empty ${TEST_SH} -c '
+		set -- xxx
+		: <<- done | for x in xxx
+		done
+		do echo $x
+		done'
+
+	atf_check -s exit:0 -o inline:'xxx\n' -e empty ${TEST_SH} -c '
+		: <<- in | case xxx
+		in
+		in xxx) echo xxx;;
+		esac'
+}
+
 atf_test_case vicious
 vicious_head() {
 	atf_set "descr" "Tests for obscure and obnoxious uses of here docs"
@@ -600,5 +629,6 @@ atf_init_test_cases() {
 	atf_add_test_case nested	# here docs inside here docs
 	atf_add_test_case quoting	# stuff quoted inside
 	atf_add_test_case side_effects	# here docs that modify environment
+	atf_add_test_case hard_cases	# here doc bodies appearing mid command
 	atf_add_test_case vicious	# evil test from the austin-l list...
 }



CVS commit: src/tests/bin/sh

2021-09-08 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Sep  9 00:04:51 UTC 2021

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

Log Message:
Add a new test case to check for correct parsing and execution
of a few bizarre here document usages, such as

: << do | for x in xxx
do
do echo $x
done

which should work, but never have done.  (See the source for others).

This test case will currently fail, until the bug is fixed
(already done, to be committed very soon).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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.



CVS commit: src/tests/bin/sh

2019-07-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jul 10 05:57:43 UTC 2019

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

Log Message:
Make sure we have enough free inodes before running the filename_expansion
test.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 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.4 src/tests/bin/sh/t_patterns.sh:1.5
--- src/tests/bin/sh/t_patterns.sh:1.4	Sun Nov 18 13:41:24 2018
+++ src/tests/bin/sh/t_patterns.sh	Wed Jul 10 05:57:43 2019
@@ -1,4 +1,4 @@
-# $NetBSD: t_patterns.sh,v 1.4 2018/11/18 13:41:24 kre Exp $
+# $NetBSD: t_patterns.sh,v 1.5 2019/07/10 05:57:43 martin Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -182,6 +182,8 @@ filename_expansion_body() {
 	atf_require_prog mv
 	atf_require_prog rm
 	atf_require_prog mkdir
+	atf_require_prog df
+	atf_require_prog awk
 
 	reset filename_expansion
 
@@ -194,6 +196,11 @@ filename_expansion_body() {
 	# save inodes, but would require running "ln" many times, so
 	# would be a lot slower.
 
+	free_inodes=$( df -i . | awk '/^Filesystem/{next}; { print $7 }' )
+	if [ $free_inodes -lt 17000 ]; then
+		atf_skip "not enough space"
+	fi
+
 	# This should work on a case insensitive, but preserving,
 	# filesystem - but case sensitive filesystems are preferred.
 



CVS commit: src/tests/bin/sh

2019-07-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jul 10 05:57:43 UTC 2019

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

Log Message:
Make sure we have enough free inodes before running the filename_expansion
test.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 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.



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

2016-04-29 Thread Robert Elz
Date:Fri, 29 Apr 2016 14:29:17 -0400
From:"Christos Zoulas" 
Message-ID:  <20160429182917.d265bf...@cvs.netbsd.org>

  | use "" so ${TEST_SH} is expanded.

Ugh!!!

It worked for me as I always have TEST_SH in the environment, so it
was getting expanded (much much) later...

I'm appending a new version of the fd patch - the basics of it are all
more or less unchanged, but the salad dressing has altered a bit.
This applies to the CVS version of src/bin/sh - ignoring the previous patch.

The system re-build finished (more or less, I forgot to fetch my src sets
making script, which is a little different than the standard one, so no
src sets got built) - aside from that, no problems.   That was with the
previous patch, I'm not sure if I will run it again (it took 18 1/2 hrs...)

Sometime later I will also have a patch so that compiling with -DSTATIC=static
works (which it definitely doesn't as it is.)

I have been working on t_redir.sh so I'll append that as I have it at the
minute (it passes with the shell with the patch included here) but there's
still one empty test I want to finish before any of this is ready to commit.

kre



T_REDIR.SH
Description: t_redir.sh
Index: cd.c
===
RCS file: /cvsroot/src/bin/sh/cd.c,v
retrieving revision 1.45
diff -u -u -r1.45 cd.c
--- cd.c4 Jan 2016 03:00:24 -   1.45
+++ cd.c29 Apr 2016 20:16:39 -
@@ -427,11 +427,7 @@
jp = makejob(NULL, 1);
if (forkshell(jp, NULL, FORK_NOJOB) == 0) {
(void) close(pip[0]);
-   if (pip[1] != 1) {
-   close(1);
-   copyfd(pip[1], 1, 1, 0);
-   close(pip[1]);
-   }
+   movefd(pip[1], 1);
(void) execl("/bin/pwd", "pwd", (char *)0);
error("Cannot exec /bin/pwd");
}
Index: eval.c
===
RCS file: /cvsroot/src/bin/sh/eval.c,v
retrieving revision 1.119
diff -u -u -r1.119 eval.c
--- eval.c  16 Mar 2016 21:20:59 -  1.119
+++ eval.c  29 Apr 2016 20:16:39 -
@@ -508,6 +508,7 @@
 
for (redir = n ; redir ; redir = redir->nfile.next) {
struct arglist fn;
+
fn.lastp = 
switch (redir->type) {
case NFROMTO:
@@ -566,18 +567,11 @@
}
if (forkshell(jp, lp->n, n->npipe.backgnd ? FORK_BG : FORK_FG) 
== 0) {
INTON;
-   if (prevfd > 0) {
-   close(0);
-   copyfd(prevfd, 0, 1, 0);
-   close(prevfd);
-   }
+   if (prevfd > 0)
+   movefd(prevfd, 0);
if (pip[1] >= 0) {
close(pip[0]);
-   if (pip[1] != 1) {
-   close(1);
-   copyfd(pip[1], 1, 1, 0);
-   close(pip[1]);
-   }
+   movefd(pip[1], 1);
}
evaltree(lp->n, EV_EXIT);
}
@@ -638,11 +632,7 @@
if (forkshell(jp, n, FORK_NOJOB) == 0) {
FORCEINTON;
close(pip[0]);
-   if (pip[1] != 1) {
-   close(1);
-   copyfd(pip[1], 1, 1, 0);
-   close(pip[1]);
-   }
+   movefd(pip[1], 1);
eflag = 0;
evaltree(n, EV_EXIT);
/* NOTREACHED */
@@ -970,11 +960,7 @@
FORCEINTON;
}
close(pip[0]);
-   if (pip[1] != 1) {
-   close(1);
-   copyfd(pip[1], 1, 1, 0);
-   close(pip[1]);
-   }
+   movefd(pip[1], 1);
}
flags |= EV_EXIT;
}
Index: input.c
===
RCS file: /cvsroot/src/bin/sh/input.c,v
retrieving revision 1.48
diff -u -u -r1.48 input.c
--- input.c 27 Mar 2016 14:34:46 -  1.48
+++ input.c 29 Apr 2016 20:16:39 -
@@ -411,14 +411,13 @@
error("Cannot rewind the file %s", fname);
}
 
-   if (fd < 10) {
-   fd2 = copyfd(fd, 10, 0, 0);
-   close(fd);
-   if (fd2 < 0)
-