xref: /freebsd/bin/sh/tests/parser/heredoc10.0 (revision f126890a)
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 may not work with simplistic $(...) parsers.
17# The open parentheses in comments help mksh, but not zsh.
18
19failures=0
20
21check() {
22	if ! eval "[ $* ]"; then
23		echo "Failed: $*"
24		: $((failures += 1))
25	fi
26}
27
28check '"$(cat <<EOF # (
29EOF )
30EOF
31)" = "EOF )"'
32
33check '"$({ cat <<EOF # (
34EOF)
35EOF
36})" = "EOF)"'
37
38check '"$(if :; then cat <<EOF # (
39EOF)
40EOF
41fi)" = "EOF)"'
42
43check '"$( (cat <<EOF # (
44EOF)
45EOF
46))" = "EOF)"'
47
48exit $((failures != 0))
49