heredoc10.0 revision 221887
1251886Speter# $FreeBSD: head/tools/regression/bin/sh/parser/heredoc10.0 221887 2011-05-14 14:19:30Z jilles $
2251886Speter
3264400Simp# It may be argued that
4251886Speter#   x=$(cat <<EOF
5251886Speter#   foo
6251886Speter#   EOF)
7289180Speter# is a valid complete command that sets x to foo, because
8251886Speter#   cat <<EOF
9289180Speter#   foo
10251886Speter#   EOF
11289180Speter# is a valid script even without the final newline.
12251886Speter# However, if the here-document is not within a new-style command substitution
13251886Speter# or there are other constructs nested inside the command substitution that
14251886Speter# need terminators, the delimiter at the start of a line followed by a close
15251886Speter# parenthesis is clearly a literal part of the here-document.
16251886Speter
17251886Speter# This file contains tests that may not work with simplistic $(...) parsers.
18251886Speter# The open parentheses in comments help mksh, but not zsh.
19251886Speter
20251886Speterfailures=0
21251886Speter
22251886Spetercheck() {
23251886Speter	if ! eval "[ $* ]"; then
24289180Speter		echo "Failed: $*"
25251886Speter		: $((failures += 1))
26251886Speter	fi
27251886Speter}
28251886Speter
29275079Sbaptcheck '"$(cat <<EOF # (
30275079SbaptEOF )
31251886SpeterEOF
32251886Speter)" = "EOF )"'
33251886Speter
34275079Sbaptcheck '"$({ cat <<EOF # (
35251886SpeterEOF)
36251886SpeterEOF
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