1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#          Copyright (c) 1982-2012 AT&T Intellectual Property          #
5#                      and is licensed under the                       #
6#                 Eclipse Public License, Version 1.0                  #
7#                    by AT&T Intellectual Property                     #
8#                                                                      #
9#                A copy of the License is available at                 #
10#          http://www.eclipse.org/org/documents/epl-v10.html           #
11#         (with md5 checksum b35adb5213ca9657e911e9befb180842)         #
12#                                                                      #
13#              Information and Software Systems Research               #
14#                            AT&T Research                             #
15#                           Florham Park NJ                            #
16#                                                                      #
17#                  David Korn <dgk@research.att.com>                   #
18#                                                                      #
19########################################################################
20function err_exit
21{
22	print -u2 -n "\t"
23	print -u2 -r ${Command}[$1]: "${@:2}"
24	let Errors+=1
25}
26alias err_exit='err_exit $LINENO'
27
28Command=${0##*/}
29integer Errors=0
30
31tmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; }
32trap "cd /; rm -rf $tmp" EXIT
33
34f=$tmp/here1
35g=$tmp/here2
36cat > $f <<!
37hello world
38!
39if	[[ $(<$f) != 'hello world' ]]
40then	err_exit "'hello world' here doc not working"
41fi
42cat > $g <<\!
43hello world
44!
45cmp $f $g 2> /dev/null || err_exit "'hello world' quoted here doc not working"
46cat > $g <<- !
47	hello world
48!
49cmp $f $g 2> /dev/null || err_exit "'hello world' tabbed here doc not working"
50cat > $g <<- \!
51	hello world
52!
53cmp $f $g 2> /dev/null || err_exit "'hello world' quoted tabbed here doc not working"
54x=hello
55cat > $g <<!
56$x world
57!
58cmp $f $g 2> /dev/null || err_exit "'$x world' here doc not working"
59cat > $g <<!
60$(print hello) world
61!
62cmp $f $g 2> /dev/null || err_exit "'$(print hello) world' here doc not working"
63cat > $f <<\!!
64!@#$%%^^&*()_+~"::~;'`<>?/.,{}[]
65!!
66if	[[ $(<$f) != '!@#$%%^^&*()_+~"::~;'\''`<>?/.,{}[]' ]]
67then	err_exit "'hello world' here doc not working"
68fi
69cat > $g <<!!
70!@#\$%%^^&*()_+~"::~;'\`<>?/.,{}[]
71!!
72cmp $f $g 2> /dev/null || err_exit "unquoted here doc not working"
73exec 3<<!
74	foo
75!
76if	[[ $(<&3) != '	foo' ]]
77then	err_exit "leading tabs stripped with <<!"
78fi
79$SHELL -c "
80eval `echo 'cat <<x'` "|| err_exit "eval `echo 'cat <<x'` core dumps"
81cat > /dev/null <<EOF # comments should not cause core dumps
82abc
83EOF
84cat >$g << :
85:
86:
87cmp /dev/null $g 2> /dev/null || err_exit "empty here doc not working"
88x=$(print $( cat <<HUP
89hello
90HUP
91)
92)
93if	[[ $x != hello ]]
94then	err_exit "here doc inside command sub not working"
95fi
96y=$(cat <<!
97${x:+${x}}
98!
99)
100if	[[ $y != "${x:+${x}}" ]]
101then	err_exit '${x:+${x}} not working in here document'
102fi
103$SHELL -c '
104x=0
105while (( x < 100 ))
106do	((x = x+1))
107	cat << EOF
108EOF
109done
110' 2> /dev/null  || err_exit '100 empty here docs fails'
111{
112	print 'builtin -d cat
113	cat <<- EOF'
114	for ((i=0; i < 100; i++))
115	do print XXXXXXXXXXXXXXXXXXXX
116	done
117	print ' XXX$(date)XXXX
118	EOF'
119} > $f
120chmod +x "$f"
121$SHELL "$f" > /dev/null  || err_exit "large here-doc with command substitution fails"
122x=$(/bin/cat <<!
123$0
124!
125)
126[[ "$x" == "$0" ]] || err_exit '$0 not correct inside here documents'
127$SHELL -c 'x=$(
128cat << EOF
129EOF)' 2> /dev/null || err_exit 'here-doc cannot be terminated by )'
130if	[[ $( IFS=:;cat <<-!
131			$IFS$(print hi)$IFS
132		!) != :hi: ]]
133then	err_exit '$IFS unset by command substitution in here docs'
134fi
135if	x=$($SHELL -c 'cat <<< "hello world"' 2> /dev/null)
136then	[[ $x == 'hello world' ]] || err_exit '<<< documents not working'
137	x=$($SHELL -c 'v="hello  world";cat <<< $v' 2> /dev/null)
138	[[ $x == 'hello  world' ]] || err_exit '<<< documents with $x not working'
139	x=$($SHELL -c 'v="hello  world";cat <<< "$v"' 2> /dev/null)
140	[[ $x == 'hello  world' ]] || err_exit '<<< documents with $x not working'
141else	err_exit '<<< syntax not supported'
142fi
143if	[[ $(cat << EOF #testing
144#abc
145abc
146EOF) != $'#abc\nabc' ]]
147then	err_exit 'comments not preserved in here-documents'
148fi
149cat  > "$f" <<- '!!!!'
150	builtin cat
151	: << EOF
152	$PWD
153	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
154	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
155	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
156	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
157	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
158	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
159	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
160	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
161	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
162	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
163	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
164	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
165	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
166	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
167	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
168	EOF
169	command exec 3>&- 4>&- 5>&- 6>&- 7>&- 8>&- 9>&-
170	x=abc
171	cat << EOF
172	$x
173	EOF
174!!!!
175chmod 755 "$f"
176if	[[ $($SHELL  "$f") != abc ]]
177then	err_exit	'here document descritor was closed'
178fi
179cat  > "$f" <<- '!!!!'
180	exec 0<&-
181	foobar()
182	{
183		/bin/cat <<- !
184		foobar
185		!
186	}
187	: << EOF
188	$PWD
189	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
190	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
191	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
192	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
193	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
194	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
195	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
196	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
197	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
198	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
199	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
200	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
201	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
202	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
203	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
204	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
205	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
206	EOF
207	print -r -- "$(foobar)"
208!!!!
209if	[[ $($SHELL  "$f") != foobar ]]
210then	err_exit	'here document with stdin closed failed'
211fi
212printf $'cat   <<# \\!!!\n\thello\n\t\tworld\n!!!' > $f
213[[ $($SHELL "$f") == $'hello\n\tworld' ]] || err_exit "<<# not working for quoted here documents"
214printf $'w=world;cat   <<# !!!\n\thello\n\t\t$w\n!!!' > $f
215[[ $($SHELL "$f") == $'hello\n\tworld' ]] || err_exit "<<# not working for non-quoted here documents"
216[[ $( $SHELL  <<- \++++
217	S=( typeset a )
218	function S.a.get
219	{
220	     .sh.value=$__a
221	}
222	__a=1234
223	cat <<-EOF
224	${S.a}
225	EOF
226++++
227) == 1234 ]]  2> /dev/null || err_exit 'here document with get discipline failed'
228[[ $($SHELL -c 'g(){ print ok;}; cat <<- EOF
229	${ g;}
230	EOF
231	' 2> /dev/null) == ok ]] || err_exit '${ command;} not working in heredoc'
232script=$f
233{
234for ((i=0; i < 406; i++))
235do	print ': 23456789012345678'
236done
237print : 123456789123
238cat <<- \EOF
239eval "$(
240	{ cat                                 ; } <<MARKER
241	  print  hello
242	MARKER
243)"
244EOF
245} > $script
246chmod +x $script
247[[ $($SHELL $script) == hello ]] 2> /dev/null || err_exit 'heredoc embeded in command substitution fails at buffer boundary'
248
249got=$( cat << EOF
250\
251abc
252EOF)
253[[ $got == abc ]] || err_exit 'line continuation at start of buffer not working'
254
255tmpfile1=$tmp/file1
256tmpfile2=$tmp/file2
257function gendata
258{
259	typeset -RZ3 i
260	for ((i=0; i < 500; i++))
261	do	print -r -- "=====================This is line $i============="
262	done
263}
264
265cat > $tmpfile1 <<- +++
266	function foobar
267	{
268		cat << XXX
269		$(gendata)
270		XXX
271	}
272	cat > $tmpfile2 <<- EOF
273	\$(foobar)
274	$(gendata)
275EOF
276+++
277chmod +x $tmpfile1
278$SHELL $tmpfile1
279set -- $(wc < $tmpfile2)
280(( $1 == 1000 )) || err_exit "heredoc $1 lines, should be 1000 lines"
281(( $2 == 4000 )) || err_exit "heredoc $2 words, should be 4000 words"
282
283# comment with here document looses line number count
284integer line=$((LINENO+5))
285function tst
286{
287	[[ $1 == $2 ]] || echo expected $1, got $2
288}
289tst $line $LINENO <<"!" # this comment affects LINENO #
2901
291!
292(( (line+=3) == LINENO )) ||  err_exit "line number=$LINENO should be $line"
293
294[[ $($SHELL -c 'wc -c <<< ""' 2> /dev/null) == *1 ]] || err_exit '<<< with empty string not working'
295
296mkdir $tmp/functions
297cat > $tmp/functions/t2 <<\!!!
298function t2
299{
300cat <<EOF | sed 's/1234567890/qwertyuiopasdfghj/'
301${1}
302EOF
303}
304!!!
305
306FPATH=$tmp/functions
307foo=${
308cat <<EOF
3091 34567890 $(t2 1234567890 ) 0123456789012345678901234567890123
310111111111111111111111111111111111111111111111111111111111111111
311111111111111111111111111111111111111111111111111111111111111111
312111111111111111111111111111111111111111111111111111111111111111
313111111111111111111111111111111111111111111111111111111111111111
314111111111111111111111111111111111111111111111111111111111111111
315111111111111111111111111111111111111111111111111111111111111111
316111111111111111111111111111111111111111111111111111111111111111
317111111111111111111111111111111111111111111111111111111111111111
318111111111111111111111111111111111111111111111111111111111111111
319111111111111111111111111111111111111111111111111111111111111111
320111111111111111111111111111111111111111111111111111111111111111
321111111111111111111111111111111111111111111111111111111111111111
322111111111111111111111111111111111111111111111111111111111111111
323111111111111111111111111111111111111111111111111111111111111111
324111111111111111111111111111111111111111111111111111111111111 1
325
3262 34567890 $(t2 1234567890 ) 0123456789012345678901234567890123
327222222222222222222222222222222222222222222222222222222222222222
328222222222222222222222222222222222222222222222222222222222222222
329222222222222222222222222222222222222222222222222222222222222222
330222222222222222222222222222222222222222222222222222222222222222
331222222222222222222222222222222222222222222222222222222222222222
332222222222222222222222222222222222222222222222222222222222222222
333222222222222222222222222222222222222222222222222222222222222222
334222222222222222222222222222222222222222222222222222222222222222
335222222222222222222222222222222222222222222222222222222222222222
336222222222222222222222222222222222222222222222222222222222222222
337222222222222222222222222222222222222222222222222222222222222222
338222222222222222222222222222222222222222222222222222222222222222
339222222222222222222222222222222222222222222222222222222222222222
340222222222222222222222222222222222222222222222222222222222222222
341222222222222222222222222222222222222222222222222222222222222 2
342
3433 34567890 $(t2 1234567890 ) 0123456789012345678901234567890123
344333333333333333333333333333333333333333333333333333333333333333
345333333333333333333333333333333333333333333333333333333333333333
346333333333333333333333333333333333333333333333333333333333333333
347333333333333333333333333333333333333333333333333333333333333333
348333333333333333333333333333333333333333333333333333333333333333
349333333333333333333333333333333333333333333333333333333333333333
350333333333333333333333333333333333333333333333333333333333333333
351333333333333333333333333333333333333333333333333333333333333333
352333333333333333333333333333333333333333333333333333333333333333
353333333333333333333333333333333333333333333333333333333333333333
354333333333333333333333333333333333333333333333333333333333333333
355333333333333333333333333333333333333333333333333333333333333333
356333333333333333333333333333333333333333333333333333333333333333
357333333333333333333333333333333333333333333333333333333333333333
358333333333333333333333333333333333333333333333333333333333333 3
359
3604 34567890 $(t2 1234567890 ) 0123456789012345678901234567890123
361444444444444444444444444444444444444444444444444444444444444444
362444444444444444444444444444444444444444444444444444444444444444
363444444444444444444444444444444444444444444444444444444444444444
364444444444444444444444444444444444444444444444444444444444444444
365444444444444444444444444444444444444444444444444444444444444444
366444444444444444444444444444444444444444444444444444444444444444
367444444444444444444444444444444444444444444444444444444444444444
368444444444444444444444444444444444444444444444444444444444444444
369444444444444444444444444444444444444444444444444444444444444444
370444444444444444444444444444444444444444444444444444444444444444
371444444444444444444444444444444444444444444444444444444444444444
372444444444444444444444444444444444444444444444444444444444444444
373444444444444444444444444444444444444444444444444444444444444444
374444444444444444444444444444444444444444444444444444444444444444
375444444444444444444444444444444444444444444444444444444444444 4
376
3775 34567890 $(t2 1234567890 ) 0123456789012345678901234567890123
378555555555555555555555555555555555555555555555555555555555555555
379555555555555555555555555555555555555555555555555555555555555555
380555555555555555555555555555555555555555555555555555555555555555
381555555555555555555555555555555555555555555555555555555555555555
382555555555555555555555555555555555555555555555555555555555555555
383555555555555555555555555555555555555555555555555555555555555555
384555555555555555555555555555555555555555555555555555555555555555
385555555555555555555555555555555555555555555555555555555555555555
386555555555555555555555555555555555555555555555555555555555555555
387555555555555555555555555555555555555555555555555555555555555555
388555555555555555555555555555555555555555555555555555555555555555
389555555555555555555555555555555555555555555555555555555555555555
390555555555555555555555555555555555555555555555555555555555555555
391555555555555555555555555555555555555555555555555555555555555555
392555555555555555555555555555555555555555555555555555555555555 5
393
3946 34567890 $(t2 1234567890 ) 0123456789012345678901234567890123
395666666666666666666666666666666666666666666666666666666666666666
396666666666666666666666666666666666666666666666666666666666666666
397666666666666666666666666666666666666666666666666666666666666666
398666666666666666666666666666666666666666666666666666666666666666
399666666666666666666666666666666666666666666666666666666666666666
400666666666666666666666666666666666666666666666666666666666666666
401666666666666666666666666666666666666666666666666666666666666666
402666666666666666666666666666666666666666666666666666666666666666
403666666666666666666666666666666666666666666666666666666666666666
404666666666666666666666666666666666666666666666666666666666666666
405666666666666666666666666666666666666666666666666666666666666666
406666666666666666666666666666666666666666666666666666666666666666
407666666666666666666666666666666666666666666666666666666666666666
408666666666666666666666666666666666666666666666666666666666666666
409666666666666666666666666666666666666666666666666666666666666 6
410
4117 34567890 $(t2 1234567890 ) 0123456789012345678901234567890123
412777777777777777777777777777777777777777777777777777777777777777
413777777777777777777777777777777777777777777777777777777777777777
414777777777777777777777777777777777777777777777777777777777777777
415777777777777777777777777777777777777777777777777777777777777777
416777777777777777777777777777777777777777777777777777777777777777
417777777777777777777777777777777777777777777777777777777777777777
418777777777777777777777777777777777777777777777777777777777777777
419777777777777777777777777777777777777777777777777777777777777777
420777777777777777777777777777777777777777777777777777777777777777
421777777777777777777777777777777777777777777777777777777777777777
422777777777777777777777777777777777777777777777777777777777777777
423777777777777777777777777777777777777777777777777777777777777777
424777777777777777777777777777777777777777777777777777777777777777
425777777777777777777777777777777777777777777777777777777777777777
426777777777777777777777777777777777777777777777777777777777777 7
427
4288 34567890 $(t2 1234567890 ) 0123456789012345678901234567890123
429888888888888888888888888888888888888888888888888888888888888888
430888888888888888888888888888888888888888888888888888888888888888
431888888888888888888888888888888888888888888888888888888888888888
432888888888888888888888888888888888888888888888888888888888888888
433888888888888888888888888888888888888888888888888888888888888888
434888888888888888888888888888888888888888888888888888888888888888
435888888888888888888888888888888888888888888888888888888888888888
436888888888888888888888888888888888888888888888888888888888888888
437888888888888888888888888888888888888888888888888888888888888888
438888888888888888888888888888888888888888888888888888888888888888
439888888888888888888888888888888888888888888888888888888888888888
440888888888888888888888888888888888888888888888888888888888888888
441888888888888888888888888888888888888888888888888888888888888888
442888888888888888888888888888888888888888888888888888888888888888
443888888888888888888888888888888888888888888888888888888888888 8
444
4459 34567890 $(t2 1234567890 ) 0123456789012345678901234567890123
446999999999999999999999999999999999999999999999999999999999999999
447999999999999999999999999999999999999999999999999999999999999999
448999999999999999999999999999999999999999999999999999999999999999
449999999999999999999999999999999999999999999999999999999999999999
450999999999999999999999999999999999999999999999999999999999999999
451999999999999999999999999999999999999999999999999999999999999999
452999999999999999999999999999999999999999999999999999999999999999
453999999999999999999999999999999999999999999999999999999999999999
454999999999999999999999999999999999999999999999999999999999999999
455999999999999999999999999999999999999999999999999999999999999999
456999999999999999999999999999999999999999999999999999999999999999
457999999999999999999999999999999999999999999999999999999999999999
458999999999999999999999999999999999999999999999999999999999999999
459999999999999999999999999999999999999999999999999999999999999999
460999999999999999999999999999999999999999999999999999999999999 9
461
46210 4567890 $(t2 1234567890 ) 0123456789012345678901234567890123
463101010101010101010101010101010101010101010101010101010101010103
464101010101010101010101010101010101010101010101010101010101010103
465101010101010101010101010101010101010101010101010101010101010103
466101010101010101010101010101010101010101010101010101010101010103
467101010101010101010101010101010101010101010101010101010101010103
468101010101010101010101010101010101010101010101010101010101010103
469101010101010101010101010101010101010101010101010101010101010103
470101010101010101010101010101010101010101010101010101010101010103
471101010101010101010101010101010101010101010101010101010101010103
472101010101010101010101010101010101010101010101010101010101010103
473101010101010101010101010101010101010101010101010101010101010103
474101010101010101010101010101010101010101010101010101010101010103
475101010101010101010101010101010101010101010101010101010101010103
476101010101010101010101010101010101010101010101010101010101010103
4771010101010101010101010101010101010101010101010101010101010 END
478
479EOF
480}
481[[ ${#foo} == 10238 ]] || err_exit 'large here docs containing command subs of dynamically loaded functions fails'
482
483{
484     print $'FOO=1\nBAR=foobarbaz'
485     print -- 'cat <<#EOF'
486     integer i
487     for ((i=0; i < 50000; i++))
488     do print -r -- '    $(($FOO + 1))'
489      print -r -- '    $BAR meep'
490     done
491     print EOF
492} > $f
493$SHELL $f > $g
494[[ $(grep meep $g | grep -v foobar) != '' ]] && err_exit 'here-doc loosing $var expansions on boundaries in rare cases'
495
496print foo > $tmp/foofile
497x=$( $SHELL 2> /dev/null 'read <<< $(<'"$tmp"'/foofile) 2> /dev/null;print -r "$REPLY"')
498[[ $x == foo ]] || err_exit '<<< $(<file) not working'
499
500exit $((Errors<125?Errors:125))
501