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