Merge remote-tracking branch 'origin/master' into sheet
[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 at `loop': expecting end of command.
41 batch.sps:3: error: COMPUTE: COMPUTE is allowed only after the active dataset has been defined or inside INPUT PROGRAM.
42 batch.sps:4: error: END CASE: END CASE is allowed only inside INPUT PROGRAM.
43 insert.sps:4: error: LIST: LIST is allowed only after the active dataset has been defined.
44 ])
45 AT_CLEANUP
46
47 AT_SETUP([INSERT SYNTAX=BATCH])
48 CREATE_BATCH_SPS
49 AT_DATA([insert.sps], [dnl
50 INSERT 
51   FILE='batch.sps'
52   SYNTAX=BATCH.
53 LIST.
54 ])
55 AT_CHECK([pspp -o pspp.csv insert.sps])
56 AT_CHECK([cat pspp.csv], [0], [dnl
57 Table: Data List
58 z
59 1.00
60 2.00
61 3.00
62 4.00
63 5.00
64 ])
65 AT_CLEANUP
66
67 AT_SETUP([INSERT CD=NO])
68 AT_DATA([insert.sps], [INSERT FILE='Dir1/foo.sps'.
69 LIST.
70 ])
71 mkdir Dir1
72 AT_DATA([Dir1/foo.sps], [INSERT FILE='bar.sps' CD=NO.
73 ])
74 AT_DATA([Dir1/bar.sps],
75   [DATA LIST LIST /x *.
76 BEGIN DATA.
77 1
78 2
79 3
80 END DATA.
81 ])
82 AT_CHECK([pspp -o pspp.csv insert.sps], [1], [dnl
83 Dir1/foo.sps:1: error: INSERT: Can't find `bar.sps' in include file search path.
84 insert.sps:2: error: LIST: LIST is allowed only after the active dataset has been defined.
85 ])
86 AT_CLEANUP
87
88 AT_SETUP([INSERT CD=YES])
89 AT_DATA([insert.sps], [INSERT FILE='Dir1/foo.sps' CD=YES.
90 LIST.
91 ])
92 mkdir Dir1
93 AT_DATA([Dir1/foo.sps], [INSERT FILE='bar.sps'.
94 ])
95 AT_DATA([Dir1/bar.sps],
96   [DATA LIST LIST /x *.
97 BEGIN DATA.
98 1
99 2
100 3
101 END DATA.
102 ])
103 AT_CHECK([pspp -o pspp.csv insert.sps])
104 AT_CHECK([cat pspp.csv], [0], [dnl
105 Table: Reading free-form data from INLINE.
106 Variable,Format
107 x,F8.0
108
109 Table: Data List
110 x
111 1.00
112 2.00
113 3.00
114 ])
115 AT_CLEANUP
116
117 m4_define([CREATE_ERROR_SPS],
118   [AT_DATA([error.sps], [dnl
119 DATA LIST NOTABLE LIST /x *.
120 BEGIN DATA.
121 1
122 2
123 3
124 END DATA.
125
126 * The following line is erroneous
127
128 DISPLAY AKSDJ.
129 LIST.
130 ])])
131
132 AT_SETUP([INSERT ERROR=STOP])
133 CREATE_ERROR_SPS
134 AT_DATA([insert.sps], [INSERT FILE='error.sps' ERROR=STOP.
135 ])
136 AT_CHECK([pspp -o pspp.csv insert.sps], [1], [dnl
137 error.sps:10: error: DISPLAY: AKSDJ is not a variable name.
138 warning: Error encountered while ERROR=STOP is effective.
139 ])
140 AT_CLEANUP
141
142 AT_SETUP([INSERT ERROR=CONTINUE])
143 CREATE_ERROR_SPS
144 AT_DATA([insert.sps], [INSERT FILE='error.sps' ERROR=CONTINUE.
145 ])
146 AT_CHECK([pspp -o pspp.csv insert.sps], [1], [dnl
147 error.sps:10: error: DISPLAY: AKSDJ is not a variable name.
148 ])
149 AT_CHECK([cat pspp.csv], [0], [dnl
150 error.sps:10: error: DISPLAY: AKSDJ is not a variable name.
151
152 Table: Data List
153 x
154 1.00
155 2.00
156 3.00
157 ])
158 AT_CLEANUP
159
160 dnl Test for regression against bug #24569 in which PSPP crashed
161 dnl upon attempt to insert a nonexistent file.
162 AT_SETUP([INSERT nonexistent file])
163 AT_DATA([insert.sps], [dnl
164 INSERT 
165   FILE='nonexistent'
166   ERROR=CONTINUE.
167   .
168
169 LIST.
170 ])
171 AT_CHECK([pspp -O format=csv insert.sps], [1], [dnl
172 insert.sps:2: error: INSERT: Can't find `nonexistent' in include file search path.
173
174 insert.sps:6: error: LIST: LIST is allowed only after the active dataset has been defined.
175 ])
176 AT_CLEANUP
177
178
179 dnl A test to check the INCLUDE command complete with the 
180 dnl syntax and function of the ENCODING subcommand.
181 AT_SETUP([INCLUDE full check])
182 AT_DATA([two-utf8.sps], [dnl
183 echo 'Äpfelfölfaß'.
184 ])
185
186 AT_DATA([include.sps], [dnl
187 echo 'ONE'.
188
189 include FILE='two-latin1.sps' ENCODING='ISO_8859-1'.
190 ])
191
192 AT_CHECK([iconv -f UTF-8 -t iso-8859-1 two-utf8.sps > two-latin1.sps], [0], [])
193
194 AT_CHECK([pspp -O format=csv include.sps], [0], [dnl
195 ONE
196
197 Äpfelfölfaß
198 ])
199 AT_CLEANUP
200
201
202
203
204 dnl Test for a bug where insert crashed on an unterminated string input
205 AT_SETUP([INSERT unterminated string])
206
207 AT_DATA([insert.sps], [INSERT FILE=7bar.sps' CD=NO.
208 ])
209
210 AT_CHECK([pspp -O format=csv insert.sps], [1], [ignore])
211
212 AT_CLEANUP