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