Source-Changes-HG archive

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

[src/trunk]: src/tests/bin/sh Finish these tests (or at least, fill in the pl...



details:   https://anonhg.NetBSD.org/src/rev/6ee37de3903f
branches:  trunk
changeset: 814561:6ee37de3903f
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 27 14:53:17 2016 +0000

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

diffstat:

 tests/bin/sh/t_cmdsub.sh |  100 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 97 insertions(+), 3 deletions(-)

diffs (177 lines):

diff -r 650df71e5f42 -r 6ee37de3903f tests/bin/sh/t_cmdsub.sh
--- a/tests/bin/sh/t_cmdsub.sh  Sun Mar 27 14:52:40 2016 +0000
+++ b/tests/bin/sh/t_cmdsub.sh  Sun Mar 27 14:53:17 2016 +0000
@@ -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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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 @@
                        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 @@
        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 @@
        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 @@
        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 @@
        atf_set "descr" "perverse and unusual cmd substitutions & more"
 }
 z_absurd_heredoc_cmdsub_combos_body() {
+
+       echo "Help!" > help
+
+       # This version works in NetBSD (& FreeBSD)'s sh (and most others)
+       atf_check -s exit:0 -o inline:'Help!\nMe 2\n' -e empty ${TEST_SH} -c '
+                       cat <<- EOF
+                               $(
+                                       cat <<- STOP
+                                               $(
+                                                       cat `echo help`
+                                               )
+                                       STOP
+                               )
+                               $(
+                                       cat <<- END 4<<-TRASH
+                                               Me $(( 1 + 1 ))
+                                       END
+                                       This is unused noise!
+                                       TRASH
+                               )
+                       EOF
+               '
+
+       # atf_expect_fail "PR bin/50993 - heredoc parsing done incorrectly"
+       atf_check -s exit:0 -o inline:'Help!\nMe 2\n' -e empty ${TEST_SH} -c '
+                       cat <<- EOF
+                               $(
+                                       cat << STOP
+                                               $(
+                                                       cat `echo help`
+                                               )
+                                       STOP
+                               )
+                               $(
+                                       cat <<- END 4<<TRASH
+                                               Me $(( 1 + 1 ))
+                                       END
+                                       This is unused noise!
+                                       TRASH
+                               )
+                       EOF
+               '
 }
 
 atf_init_test_cases() {



Home | Main Index | Thread Index | Old Index