Module Name: src
Committed By: christos
Date: Thu Mar 31 16:20:40 UTC 2016
Modified Files:
src/tests/bin/sh: t_cmdsub.sh
Log Message:
Added tests collected by Sven Mascheck
http://www.in-ulm.de/~mascheck/various/cmd-subst/
which test cases of ')' being embedded in command substitutions.
(from kre@)
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 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.2 src/tests/bin/sh/t_cmdsub.sh:1.3
--- src/tests/bin/sh/t_cmdsub.sh:1.2 Sun Mar 27 10:53:17 2016
+++ src/tests/bin/sh/t_cmdsub.sh Thu Mar 31 12:20:39 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_cmdsub.sh,v 1.2 2016/03/27 14:53:17 christos Exp $
+# $NetBSD: t_cmdsub.sh,v 1.3 2016/03/31 16:20:39 christos Exp $
#
# Copyright (c) 2016 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -519,6 +519,116 @@ u_nested_backticks_in_heredoc_body() {
EOF'
}
+atf_test_case v_cmdsub_paren_tests
+v_cmdsub__paren_tests_head() {
+ atf_set "descr" "tests with cmdsubs containing embedded ')'"
+}
+v_cmdsub_paren_tests_body() {
+
+ # Tests from:
+ # http://www.in-ulm.de/~mascheck/various/cmd-subst/
+ # (slightly modified.)
+
+ atf_check -s exit:0 -o inline:'A.1\n' -e empty ${TEST_SH} -c \
+ 'echo $(
+ case x in x) echo A.1;; esac
+ )'
+
+ atf_check -s exit:0 -o inline:'A.2\n' -e empty ${TEST_SH} -c \
+ 'echo $(
+ case x in x) echo A.2;; esac # comment
+ )'
+
+ atf_check -s exit:0 -o inline:'A.3\n' -e empty ${TEST_SH} -c \
+ 'echo $(
+ case x in (x) echo A.3;; esac
+ )'
+
+ atf_check -s exit:0 -o inline:'A.4\n' -e empty ${TEST_SH} -c \
+ 'echo $(
+ case x in (x) echo A.4;; esac # comment
+ )'
+
+ atf_check -s exit:0 -o inline:'A.5\n' -e empty ${TEST_SH} -c \
+ 'echo $(
+ case x in (x) echo A.5
+ esac
+ )'
+
+ atf_check -s exit:0 -o inline:'B: quoted )\n' -e empty ${TEST_SH} -c \
+ 'echo $(
+ echo '\''B: quoted )'\''
+ )'
+
+ atf_check -s exit:0 -o inline:'C: comment then closing paren\n' \
+ -e empty ${TEST_SH} -c \
+ 'echo $(
+ echo C: comment then closing paren # )
+ )'
+
+ atf_check -s exit:0 -o inline:'D.1: here-doc with )\n' \
+ -e empty ${TEST_SH} -c \
+ 'echo $(
+ cat <<-\eof
+ D.1: here-doc with )
+ eof
+ )'
+
+ # D.2 is a bogus test.
+
+ atf_check -s exit:0 -o inline:'D.3: here-doc with \()\n' \
+ -e empty ${TEST_SH} -c \
+ 'echo $(
+ cat <<-\eof
+ D.3: here-doc with \()
+ eof
+ )'
+
+ atf_check -s exit:0 -e empty \
+ -o inline:'E: here-doc terminated with a parenthesis ("academic")\n' \
+ ${TEST_SH} -c \
+ 'echo $(
+ cat <<-\)
+ E: here-doc terminated with a parenthesis ("academic")
+ )
+ )'
+
+ atf_check -s exit:0 -e empty \
+-o inline:'F.1: here-doc embed with unbal single, back- or doublequote '\''\n' \
+ ${TEST_SH} -c \
+ 'echo $(
+ cat <<-"eof"
+ F.1: here-doc embed with unbal single, back- or doublequote '\''
+ eof
+ )'
+ atf_check -s exit:0 -e empty \
+ -o inline:'F.2: here-doc embed with unbal single, back- or doublequote "\n' \
+ ${TEST_SH} -c \
+ 'echo $(
+ cat <<-"eof"
+ F.2: here-doc embed with unbal single, back- or doublequote "
+ eof
+ )'
+ atf_check -s exit:0 -e empty \
+ -o inline:'F.3: here-doc embed with unbal single, back- or doublequote `\n' \
+ ${TEST_SH} -c \
+ 'echo $(
+ cat <<-"eof"
+ F.3: here-doc embed with unbal single, back- or doublequote `
+ eof
+ )'
+
+ atf_check -s exit:0 -e empty -o inline:'G: backslash at end of line\n' \
+ ${TEST_SH} -c \
+ 'echo $(
+ echo G: backslash at end of line # \
+ )'
+
+ atf_check -s exit:0 -e empty \
+ -o inline:'H: empty command-substitution\n' \
+ ${TEST_SH} -c 'echo H: empty command-substitution $( )'
+}
+
atf_test_case z_absurd_heredoc_cmdsub_combos
z_absurd_heredoc_cmdsub_combos_head() {
atf_set "descr" "perverse and unusual cmd substitutions & more"
@@ -590,5 +700,6 @@ atf_init_test_cases() {
atf_add_test_case s_heredoc_in_backticks
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 z_absurd_heredoc_cmdsub_combos
}