@@ -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 @@
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_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
}