1221887Sjilles# $FreeBSD: releng/11.0/bin/sh/tests/parser/heredoc10.0 221887 2011-05-14 14:19:30Z jilles $
2221887Sjilles
3221887Sjilles# It may be argued that
4221887Sjilles#   x=$(cat <<EOF
5221887Sjilles#   foo
6221887Sjilles#   EOF)
7221887Sjilles# is a valid complete command that sets x to foo, because
8221887Sjilles#   cat <<EOF
9221887Sjilles#   foo
10221887Sjilles#   EOF
11221887Sjilles# is a valid script even without the final newline.
12221887Sjilles# However, if the here-document is not within a new-style command substitution
13221887Sjilles# or there are other constructs nested inside the command substitution that
14221887Sjilles# need terminators, the delimiter at the start of a line followed by a close
15221887Sjilles# parenthesis is clearly a literal part of the here-document.
16221887Sjilles
17221887Sjilles# This file contains tests that may not work with simplistic $(...) parsers.
18221887Sjilles# The open parentheses in comments help mksh, but not zsh.
19221887Sjilles
20221887Sjillesfailures=0
21221887Sjilles
22221887Sjillescheck() {
23221887Sjilles	if ! eval "[ $* ]"; then
24221887Sjilles		echo "Failed: $*"
25221887Sjilles		: $((failures += 1))
26221887Sjilles	fi
27221887Sjilles}
28221887Sjilles
29221887Sjillescheck '"$(cat <<EOF # (
30221887SjillesEOF )
31221887SjillesEOF
32221887Sjilles)" = "EOF )"'
33221887Sjilles
34221887Sjillescheck '"$({ cat <<EOF # (
35221887SjillesEOF)
36221887SjillesEOF
37221887Sjilles})" = "EOF)"'
38221887Sjilles
39221887Sjillescheck '"$(if :; then cat <<EOF # (
40221887SjillesEOF)
41221887SjillesEOF
42221887Sjillesfi)" = "EOF)"'
43221887Sjilles
44221887Sjillescheck '"$( (cat <<EOF # (
45221887SjillesEOF)
46221887SjillesEOF
47221887Sjilles))" = "EOF)"'
48221887Sjilles
49221887Sjillesexit $((failures != 0))
50