3517296841a4e6a5f3189f0e9a1cd5f6e5ef1d31
[pspp] / tests / language / utilities / insert.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([INSERT])
18
19 dnl Create a file "batch.sps" that is valid syntax only in batch mode.
20 m4_define([CREATE_BATCH_SPS],
21   [AT_DATA([batch.sps], [dnl
22 input program
23 loop #i = 1 to 5
24 +  compute z = #i
25 +  end case
26 end loop
27 end file
28 end input program
29 ])])
30
31 AT_SETUP([INSERT SYNTAX=INTERACTIVE])
32 CREATE_BATCH_SPS
33 AT_DATA([insert.sps], [dnl
34 INSERT
35   FILE='batch.sps'
36   SYNTAX=interactive.
37 LIST.
38 ])
39 AT_CHECK([pspp -o pspp.csv insert.sps], [1], [dnl
40 batch.sps:2.1-2.4: error: INPUT PROGRAM: Syntax error expecting end of command.
41     2 | loop #i = 1 to 5
42       | ^~~~
43 batch.sps:3.4-3.10: error: COMPUTE: COMPUTE is allowed only after the active dataset has been defined or inside INPUT PROGRAM.
44     3 | +  compute z = #i
45       |    ^~~~~~~
46 batch.sps:4.4-4.11: error: END CASE: END CASE is allowed only inside INPUT PROGRAM.
47     4 | +  end case
48       |    ^~~~~~~~
49 insert.sps:4.1-4.4: error: LIST: LIST is allowed only after the active dataset has been defined.
50     4 | LIST.
51       | ^~~~
52 ])
53 AT_CLEANUP
54
55 AT_SETUP([INSERT SYNTAX=BATCH])
56 CREATE_BATCH_SPS
57 AT_DATA([insert.sps], [dnl
58 INSERT
59   FILE='batch.sps'
60   SYNTAX=BATCH.
61 LIST.
62 ])
63 AT_CHECK([pspp -o pspp.csv insert.sps])
64 AT_CHECK([cat pspp.csv], [0], [dnl
65 Table: Data List
66 z
67 1.00
68 2.00
69 3.00
70 4.00
71 5.00
72 ])
73 AT_CLEANUP
74
75 AT_SETUP([INSERT CD=NO])
76 AT_DATA([insert.sps], [INSERT FILE='Dir1/foo.sps'.
77 LIST.
78 ])
79 mkdir Dir1
80 AT_DATA([Dir1/foo.sps], [INSERT FILE='bar.sps' CD=NO.
81 ])
82 AT_DATA([Dir1/bar.sps],
83   [DATA LIST LIST /x *.
84 BEGIN DATA.
85 1
86 2
87 3
88 END DATA.
89 ])
90 AT_CHECK([pspp -o pspp.csv insert.sps], [1], [dnl
91 Dir1/foo.sps:1: error: INSERT: Can't find `bar.sps' in include file search path.
92 insert.sps:2.1-2.4: error: LIST: LIST is allowed only after the active dataset has been defined.
93     2 | LIST.
94       | ^~~~
95 ])
96 AT_CLEANUP
97
98 AT_SETUP([INSERT CD=YES])
99 AT_DATA([insert.sps], [INSERT FILE='Dir1/foo.sps' CD=YES.
100 LIST.
101 ])
102 mkdir Dir1
103 AT_DATA([Dir1/foo.sps], [INSERT FILE='bar.sps'.
104 ])
105 AT_DATA([Dir1/bar.sps],
106   [DATA LIST LIST /x *.
107 BEGIN DATA.
108 1
109 2
110 3
111 END DATA.
112 ])
113 AT_CHECK([pspp -o pspp.csv insert.sps])
114 AT_CHECK([cat pspp.csv], [0], [dnl
115 Table: Reading free-form data from INLINE.
116 Variable,Format
117 x,F8.0
118
119 Table: Data List
120 x
121 1.00
122 2.00
123 3.00
124 ])
125 AT_CLEANUP
126
127 m4_define([CREATE_ERROR_SPS],
128   [AT_DATA([error.sps], [dnl
129 DATA LIST NOTABLE LIST /x *.
130 BEGIN DATA.
131 1
132 2
133 3
134 END DATA.
135
136 * The following line is erroneous
137
138 DISPLAY AKSDJ.
139 LIST.
140 ])])
141
142 AT_SETUP([INSERT ERROR=STOP])
143 CREATE_ERROR_SPS
144 AT_DATA([insert.sps], [INSERT FILE='error.sps' ERROR=STOP.
145 ])
146 AT_CHECK([pspp -o pspp.csv insert.sps], [1], [dnl
147 error.sps:10.9-10.13: error: DISPLAY: AKSDJ is not a variable name.
148    10 | DISPLAY AKSDJ.
149       |         ^~~~~
150 warning: Error encountered while ERROR=STOP is effective.
151 ])
152 AT_CLEANUP
153
154 AT_SETUP([INSERT ERROR=CONTINUE])
155 CREATE_ERROR_SPS
156 AT_DATA([insert.sps], [INSERT FILE='error.sps' ERROR=CONTINUE.
157 ])
158 AT_CHECK([pspp -o pspp.csv insert.sps], [1], [dnl
159 error.sps:10.9-10.13: error: DISPLAY: AKSDJ is not a variable name.
160    10 | DISPLAY AKSDJ.
161       |         ^~~~~
162 ])
163 AT_CHECK([cat pspp.csv], [0], [dnl
164 "error.sps:10.9-10.13: error: DISPLAY: AKSDJ is not a variable name.
165    10 | DISPLAY AKSDJ.
166       |         ^~~~~"
167
168 Table: Data List
169 x
170 1.00
171 2.00
172 3.00
173 ])
174 AT_CLEANUP
175
176 dnl Test for regression against bug #24569 in which PSPP crashed
177 dnl upon attempt to insert a nonexistent file.
178 AT_SETUP([INSERT nonexistent file])
179 AT_DATA([insert.sps], [dnl
180 INSERT
181   FILE='nonexistent'
182   ERROR=CONTINUE.
183   .
184
185 LIST.
186 ])
187 AT_CHECK([pspp -O format=csv insert.sps], [1], [dnl
188 insert.sps:2: error: INSERT: Can't find `nonexistent' in include file search path.
189
190 "insert.sps:6.1-6.4: error: LIST: LIST is allowed only after the active dataset has been defined.
191     6 | LIST.
192       | ^~~~"
193 ])
194 AT_CLEANUP
195
196
197 dnl A test to check the INCLUDE command complete with the
198 dnl syntax and function of the ENCODING subcommand.
199 AT_SETUP([INCLUDE full check])
200 AT_DATA([two-utf8.sps], [dnl
201 echo 'Äpfelfölfaß'.
202 ])
203
204 AT_DATA([include.sps], [dnl
205 echo 'ONE'.
206
207 include FILE='two-latin1.sps' ENCODING='ISO_8859-1'.
208 ])
209
210 AT_CHECK([iconv -f UTF-8 -t iso-8859-1 two-utf8.sps > two-latin1.sps], [0], [])
211
212 AT_CHECK([pspp -O format=csv include.sps], [0], [dnl
213 ONE
214
215 Äpfelfölfaß
216 ])
217 AT_CLEANUP
218
219
220
221
222 dnl Test for a bug where insert crashed on an unterminated string input
223 AT_SETUP([INSERT unterminated string])
224
225 AT_DATA([insert.sps], [INSERT FILE=7bar.sps' CD=NO.
226 ])
227
228 AT_CHECK([pspp -O format=csv insert.sps], [1], [ignore])
229
230 AT_CLEANUP
231
232 AT_SETUP([INSERT syntax errors])
233 AT_KEYWORDS([INCLUDE])
234 : >inner.sps
235 AT_DATA([insert.sps], [dnl
236 INSERT **.
237 INSERT 'nonexistent.sps'.
238 INSERT 'inner.sps' ENCODING=**.
239 INSERT 'inner.sps' SYNTAX=**.
240 INSERT 'inner.sps' CD=**.
241 INSERT 'inner.sps' ERROR=**.
242 INSERT 'inner.sps' **.
243 INCLUDE 'inner.sps' **.
244 ])
245 AT_CHECK([pspp -O format=csv insert.sps], [1], [dnl
246 "insert.sps:1.8-1.9: error: INSERT: Syntax error expecting string.
247     1 | INSERT **.
248       |        ^~"
249
250 insert.sps:2: error: INSERT: Can't find `nonexistent.sps' in include file search path.
251
252 "insert.sps:3.29-3.30: error: INSERT: Syntax error expecting string.
253     3 | INSERT 'inner.sps' ENCODING=**.
254       |                             ^~"
255
256 "insert.sps:4.27-4.28: error: INSERT: Syntax error expecting BATCH, INTERACTIVE, or AUTO.
257     4 | INSERT 'inner.sps' SYNTAX=**.
258       |                           ^~"
259
260 "insert.sps:5.23-5.24: error: INSERT: Syntax error expecting YES or NO.
261     5 | INSERT 'inner.sps' CD=**.
262       |                       ^~"
263
264 "insert.sps:6.26-6.27: error: INSERT: Syntax error expecting CONTINUE or STOP.
265     6 | INSERT 'inner.sps' ERROR=**.
266       |                          ^~"
267
268 "insert.sps:7.20-7.21: error: INSERT: Syntax error expecting ENCODING, SYNTAX, CD, or ERROR.
269     7 | INSERT 'inner.sps' **.
270       |                    ^~"
271
272 "insert.sps:8.21-8.22: error: INCLUDE: Syntax error expecting ENCODING.
273     8 | INCLUDE 'inner.sps' **.
274       |                     ^~"
275 ])
276 AT_CLEANUP