xref: /freebsd/bin/sh/tests/parser/heredoc9.0 (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1
2# It may be argued that
3#   x=$(cat <<EOF
4#   foo
5#   EOF)
6# is a valid complete command that sets x to foo, because
7#   cat <<EOF
8#   foo
9#   EOF
10# is a valid script even without the final newline.
11# However, if the here-document is not within a new-style command substitution
12# or there are other constructs nested inside the command substitution that
13# need terminators, the delimiter at the start of a line followed by a close
14# parenthesis is clearly a literal part of the here-document.
15
16# This file contains tests that also work with simplistic $(...) parsers.
17
18failures=0
19
20check() {
21	if ! eval "[ $* ]"; then
22		echo "Failed: $*"
23		: $((failures += 1))
24	fi
25}
26
27check '`${SH} -c "cat <<EOF
28EOF)
29EOF
30"` = "EOF)"'
31
32check '`${SH} -c "(cat <<EOF
33EOF)
34EOF
35)"` = "EOF)"'
36
37check '"`cat <<EOF
38EOF x
39EOF
40`" = "EOF x"'
41
42check '"`cat <<EOF
43EOF )
44EOF
45`" = "EOF )"'
46
47check '"`cat <<EOF
48EOF)
49EOF
50`" = "EOF)"'
51
52check '"$(cat <<EOF
53EOF x
54EOF
55)" = "EOF x"'
56
57exit $((failures != 0))
58