output: Move text_item and group_item usage closer to the SPV model.
[pspp] / tests / language / data-io / print.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl 
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl 
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl 
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl
17 AT_BANNER([PRINT and WRITE])
18
19 dnl These tests check unusual aspects of the PRINT and WRITE
20 dnl transformations:
21 dnl
22 dnl   - PRINT puts spaces between variables, unless a format
23 dnl     is specified explicitly.
24 dnl
25 dnl   - WRITE doesn't put space between variables.
26 dnl
27 dnl   - PRINT to an external file prefixes each line with a space.
28 dnl
29 dnl   - PRINT EJECT to an external file indicates a formfeed by a "1"
30 dnl     in the first column.
31 dnl
32 dnl   - WRITE writes out spaces for system-missing values, not a period.
33 dnl
34 dnl   - When no output is specified, an empty record is output.
35
36 AT_SETUP([PRINT numeric variables])
37 AT_DATA([print.sps], [dnl
38 data list notable /x y 1-2.
39 begin data.
40 12
41 34
42  6
43 7
44 90
45 end data.
46
47 print /x y.
48 print eject /x y 1-2.
49 print /x '-' y.
50 print.
51
52 execute.
53 ])
54 AT_CHECK([pspp -O format=csv print.sps], [0], [dnl
55 1 2 @&t@
56
57
58
59 12
60 1 -2 @&t@
61
62 3 4 @&t@
63
64
65
66 34
67 3 -4 @&t@
68
69 . 6 @&t@
70
71
72
73 .6
74 . -6 @&t@
75
76 7 . @&t@
77
78
79
80 7.
81 7 -. @&t@
82
83 9 0 @&t@
84
85
86
87 90
88 9 -0 @&t@
89
90 ])
91 AT_CLEANUP
92
93 AT_SETUP([PRINT string variables])
94 AT_DATA([print.sps], [dnl
95 DATA LIST FREE /s8 (a8) s10 (a10) vl255 (a255) vl258 (a258).
96 BEGIN DATA.
97 12345678
98 AaaaaaaaaZ
99 AbbbbMaryHadALittleLambbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbZ
100 AccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccZ
101 87654321
102 AnnnnnnnnZ
103 AmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmZ
104 AoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooWhyIsItSoZ
105 END DATA.
106
107 print
108         outfile='print.txt'
109         /s10 * vl255 * vl258 *.
110
111 EXECUTE.
112 ])
113 AT_CHECK([pspp -O format=csv print.sps])
114 AT_CHECK([cat print.txt], [0], [dnl
115  AaaaaaaaaZ AbbbbMaryHadALittleLambbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbZ AccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccZ @&t@
116  AnnnnnnnnZ AmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmZ AoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooWhyIsItSoZ @&t@
117 ])
118 AT_CLEANUP
119
120 AT_SETUP([PRINT to file])
121 AT_DATA([print.sps], [dnl
122 data list notable /x y 1-2.
123 begin data.
124 12
125 34
126  6
127 7
128 90
129 end data.
130
131 print outfile='print.out' /x y.
132 print eject outfile='print.out' /x y (f1,f1).
133 print outfile='print.out' /x '-' y.
134 print outfile='print.out'.
135
136 execute.
137 ])
138 AT_CHECK([pspp -O format=csv print.sps])
139 AT_CHECK([cat print.out], [0], [dnl
140  1 2 @&t@
141 112
142  1 -2 @&t@
143  @&t@
144  3 4 @&t@
145 134
146  3 -4 @&t@
147  @&t@
148  . 6 @&t@
149 1.6
150  . -6 @&t@
151  @&t@
152  7 . @&t@
153 17.
154  7 -. @&t@
155  @&t@
156  9 0 @&t@
157 190
158  9 -0 @&t@
159  @&t@
160 ])
161 AT_CLEANUP
162
163 dnl Tests for a bug which crashed when deallocating after a bad PRINT
164 dnl command.
165 AT_SETUP([PRINT crash bug])
166 AT_DATA([print.sps], [dnl
167 DATA LIST LIST NOTABLE /a * b *.
168 BEGIN DATA.
169 1 2
170 3 4
171 END DATA.
172
173 PRINT F8.2
174 LIST.
175 ])
176 AT_CHECK([pspp -O format=csv print.sps], [1], [dnl
177 print.sps:7.7-7.10: error: PRINT: Syntax error at `F8.2': expecting a valid subcommand.
178
179 Table: Data List
180 a,b
181 1.00,2.00
182 3.00,4.00
183 ])
184 AT_CLEANUP
185
186 AT_SETUP([WRITE to file])
187 AT_DATA([write.sps], [dnl
188 data list notable /x y 1-2.
189 begin data.
190 12
191 34
192  6
193 7
194 90
195 end data.
196
197 write outfile='write.out' /x y.
198 write outfile='write.out' /x y (2(f1)).
199 write outfile='write.out' /x '-' y.
200 write outfile='write.out'.
201
202 execute.
203 ])
204 AT_CHECK([pspp -O format=csv write.sps])
205 AT_CHECK([cat write.out], [0], [dnl
206 12
207 12
208 1-2
209
210 34
211 34
212 3-4
213
214  6
215  6
216  -6
217
218 7 @&t@
219 7 @&t@
220 7- @&t@
221
222 90
223 90
224 9-0
225
226 ])
227 AT_CLEANUP
228
229 AT_SETUP([PRINT overwrites file])
230 AT_DATA([output.txt], [abcdef
231 ])
232 AT_DATA([print.sps], [dnl
233 DATA LIST NOTABLE/x 1.
234 BEGIN DATA.
235 5
236 END DATA.
237 PRINT OUTFILE='output.txt'/x.
238 EXECUTE.
239 ])
240 AT_CHECK([pspp -O format=csv print.sps])
241 AT_CHECK([cat output.txt], [0], [ 5 @&t@
242 ])
243 AT_CLEANUP
244
245 AT_SETUP([PRINT overwrites file atomically])
246 AT_DATA([output.txt], [abcdef
247 ])
248 AT_DATA([print.sps],
249 [[DATA LIST NOTABLE/x 1.
250 BEGIN DATA.
251 5
252 END DATA.
253 PRINT OUTFILE='output.txt'/x.
254 HOST COMMAND=['kill -TERM $PPID'].
255 ]])
256 AT_CHECK([pspp -O format=csv print.sps], [143], [], [ignore])
257 AT_CHECK([cat output.txt], [0], [abcdef
258 ])
259 AT_CHECK(
260   [for file in *.tmp*; do if test -e $file; then echo $file; exit 1; fi; done])
261 AT_CLEANUP
262
263 AT_SETUP([PRINT to same file being read])
264 AT_DATA([data.txt], [5
265 ])
266 AT_DATA([print.sps], [dnl
267 DATA LIST FILE='data.txt' NOTABLE/x 1.
268 COMPUTE y = x + 1.
269 PRINT OUTFILE='data.txt'/y.
270 EXECUTE.
271 ])
272 AT_CHECK([pspp -O format=csv print.sps])
273 AT_CHECK([cat data.txt], [0], [     6.00 @&t@
274 ])
275 AT_CHECK(
276   [for file in *.tmp*; do if test -e $file; then echo $file; exit 1; fi; done])
277 AT_CLEANUP
278
279 AT_SETUP([PRINT to special file])
280 AT_SKIP_IF([test ! -c /dev/null])
281 AT_CHECK([ln -s /dev/null foo.out || exit 77])
282 AT_SKIP_IF([test ! -c foo.out])
283 AT_DATA([print.sps], [dnl
284 DATA LIST NOTABLE /x 1.
285 BEGIN DATA.
286 1
287 2
288 3
289 4
290 5
291 END DATA.
292 PRINT OUTFILE='foo.out'/x.
293 PRINT OUTFILE='foo2.out'/x.
294 EXECUTE.
295 ])
296 AT_CHECK([pspp -O format=csv print.sps])
297 AT_CHECK([cat foo2.out], [0], [dnl
298  1 @&t@
299  2 @&t@
300  3 @&t@
301  4 @&t@
302  5 @&t@
303 ])
304 ls -l foo.out foo2.out
305 AT_CHECK([test -c foo.out])
306 AT_CLEANUP
307
308 AT_SETUP([PRINT with special line ends])
309 AT_DATA([print.sps], [dnl
310 FILE HANDLE lf   /NAME='lf.txt'   /ENDS=LF.
311 FILE HANDLE crlf /NAME='crlf.txt' /ENDS=CRLF.
312 DATA LIST NOTABLE /x 1.
313 BEGIN DATA.
314 1
315 2
316 3
317 4
318 5
319 END DATA.
320 PRINT OUTFILE=lf/x.
321 PRINT OUTFILE=crlf/x.
322 EXECUTE.
323 ])
324 AT_CHECK([pspp -O format=csv print.sps])
325 AT_CHECK([cat lf.txt], [0], [dnl
326  1 @&t@
327  2 @&t@
328  3 @&t@
329  4 @&t@
330  5 @&t@
331 ])
332 AT_CHECK([tr '\r' R < crlf.txt], [0], [dnl
333  1 R
334  2 R
335  3 R
336  4 R
337  5 R
338 ])
339 AT_CLEANUP