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 10000 ); 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
 }

Reply via email to