1#
2# This file and its contents are supplied under the terms of the
3# Common Development and Distribution License ("CDDL"), version 1.0.
4# You may only use this file in accordance with the terms of version
5# 1.0 of the CDDL.
6#
7# A full copy of the text of the CDDL should have accompanied this
8# source.  A copy of the CDDL is also available via the Internet at
9# http://www.illumos.org/license/CDDL.
10#
11
12#
13# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
14#
15
16#
17# Test whether ksh mishandles a heredoc that spans a 8K chunk and has
18# a backslash as the last character of the first chunk.
19# See https://www.illumos.org/issues/13434
20#
21
22# test setup
23function err_exit
24{
25	print -u2 -n "\t"
26	print -u2 -r ${Command}[$1]: "${@:2}"
27	(( Errors++ ))
28}
29alias err_exit='err_exit $LINENO'
30
31set -o nounset
32Command=${0##*/}
33integer Errors=0
34
35# .........................................................................
36# This comment introduces the correct number of padding characters to that
37# the \ in the second heredoc below occurs at byte position 8192 of the
38# script.
39# .........................................................................
40# .........................................................................
41# .........................................................................
42# .........................................................................
43# .........................................................................
44# .........................................................................
45# .........................................................................
46# .........................................................................
47# .........................................................................
48# .........................................................................
49# .........................................................................
50# .........................................................................
51# .........................................................................
52# .........................................................................
53# .........................................................................
54# .........................................................................
55# .........................................................................
56# .........................................................................
57# .........................................................................
58# .........................................................................
59# .........................................................................
60# .........................................................................
61# .........................................................................
62# .........................................................................
63# .........................................................................
64# .........................................................................
65# .........................................................................
66# .........................................................................
67# .........................................................................
68# .........................................................................
69# .........................................................................
70# .........................................................................
71# .........................................................................
72# .........................................................................
73# .........................................................................
74# .........................................................................
75# .........................................................................
76# .........................................................................
77# .........................................................................
78# .........................................................................
79# .........................................................................
80# .........................................................................
81# .........................................................................
82# .........................................................................
83# .........................................................................
84# .........................................................................
85# .........................................................................
86# .........................................................................
87# .........................................................................
88# .........................................................................
89# .........................................................................
90# .........................................................................
91# .........................................................................
92# .........................................................................
93# .........................................................................
94# .........................................................................
95# .........................................................................
96# .........................................................................
97# .........................................................................
98# .........................................................................
99# .........................................................................
100# .........................................................................
101# .........................................................................
102# .........................................................................
103# .........................................................................
104# .........................................................................
105# .........................................................................
106# .........................................................................
107# .........................................................................
108# .........................................................................
109# .........................................................................
110# .........................................................................
111# .........................................................................
112# .........................................................................
113# .........................................................................
114# .........................................................................
115# .........................................................................
116# .........................................................................
117# .........................................................................
118# .........................................................................
119# .........................................................................
120# .........................................................................
121# .........................................................................
122# .........................................................................
123# .........................................................................
124# .........................................................................
125# .........................................................................
126# .........................................................................
127# .........................................................................
128# .........................................................................
129# .........................................................................
130# .........................................................
131
132t1=`mktemp`
133t2=`mktemp`
134if [[ ! -f "$t1" || ! -f "$t2" ]]; then
135	# Don't use the global err _ exit function as the test harness uses
136	# calls to that to compute the number of tests present in this file.
137	echo "Could not create temporary files"
138	exit 1
139fi
140
141cat > "$t1" << EOF
142\$
143EOF
144cat > "$t2" << EOF
145\$
146EOF
147
148if ! cmp -s "$t1" "$t2"; then
149	err_exit "Shell truncates heredoc over chunk boundary"
150	#/bin/od -t x1 "$t1"
151	#/bin/od -t x1 "$t2"
152fi
153
154rm -f "$t1" "$t2"
155
156# tests done
157exit $Errors
158