Source-Changes-HG archive

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

[src/trunk]: src/tests/bin/sh Add a test case for here documents positioned o...



details:   https://anonhg.NetBSD.org/src/rev/44ccb5aaba39
branches:  trunk
changeset: 344554:44ccb5aaba39
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Apr 04 12:40:13 2016 +0000

description:
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@)

diffstat:

 tests/bin/sh/t_cmdsub.sh |  94 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 86 insertions(+), 8 deletions(-)

diffs (121 lines):

diff -r e98dd97fe567 -r 44ccb5aaba39 tests/bin/sh/t_cmdsub.sh
--- a/tests/bin/sh/t_cmdsub.sh  Mon Apr 04 12:39:08 2016 +0000
+++ b/tests/bin/sh/t_cmdsub.sh  Mon Apr 04 12:40:13 2016 +0000
@@ -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 @@
                                        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 @@
                ${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_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
 }



Home | Main Index | Thread Index | Old Index