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