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
 }

Reply via email to