1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
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.
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.
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/>.
17 AT_BANNER([DO REPEAT])
19 AT_SETUP([DO REPEAT -- simple])
20 AT_DATA([do-repeat.sps], [dnl
23 DO REPEAT xval = 1 2 3 / yval = 'a' 'b' 'c' / var = a b c.
33 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
34 AT_CHECK([cat pspp.csv], [0], [dnl
58 AT_SETUP([DO REPEAT -- containing BEGIN DATA])
59 AT_DATA([do-repeat.sps], [dnl
60 DO REPEAT offset = 1 2 3.
61 DATA LIST NOTABLE /x 1-2.
67 COMPUTE x = x + offset.
71 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
72 AT_CHECK([cat pspp.csv], [0], [dnl
93 AT_SETUP([DO REPEAT -- dummy vars not expanded in include files])
94 AT_DATA([include.sps], [dnl
95 COMPUTE y = y + x + 10.
97 AT_DATA([do-repeat.sps], [dnl
111 AT_CHECK([pspp -o pspp.csv do-repeat.sps], [0], [dnl
112 do-repeat.sps:8.11: warning: DO REPEAT: Dummy variable name `x' hides dictionary variable `x'.
113 8 | DO REPEAT x = 1 2 3.
116 AT_CHECK([cat pspp.csv], [0], [dnl
117 "do-repeat.sps:8.11: warning: DO REPEAT: Dummy variable name `x' hides dictionary variable `x'.
118 8 | DO REPEAT x = 1 2 3.
127 AT_SETUP([DO REPEAT -- nested])
128 AT_DATA([do-repeat.sps], [dnl
129 DATA LIST NOTABLE /a 1.
134 DO REPEAT h = h0 TO h3 / x = 0 TO 3 / y = 8, 7.5, 6, 5.
140 DO REPEAT i = 1 TO 2.
141 DO REPEAT j = 3 TO 5.
143 COMPUTE #idx = #idx + 1.
144 COMPUTE v(#idx) = #x.
150 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
151 AT_CHECK([cat pspp.csv], [0], [dnl
153 a,h0,h1,h2,h3,v1,v2,v3,v4,v5,v6
154 0,8.00,8.50,8.00,8.00,4.00,5.00,6.00,5.00,6.00,7.00
158 dnl This program tests for a bug that crashed PSPP given an empty DO
159 dnl REPEAT...END REPEAT block. See bug #18407.
160 AT_SETUP([DO REPEAT -- empty])
161 AT_DATA([do-repeat.sps], [dnl
162 DATA LIST NOTABLE /a 1.
170 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
171 AT_CHECK([cat pspp.csv], [0], [dnl
175 dnl This program tests for a bug that crashed PSPP when END REPEAT
176 dnl was missing. See bug #31016.
177 AT_SETUP([DO REPEAT -- missing END REPEAT])
178 AT_DATA([do-repeat.sps], [dnl
179 DATA LIST NOTABLE /x 1.
180 DO REPEAT y = 1 TO 10.
182 AT_CHECK([pspp -O format=csv do-repeat.sps], [1], [dnl
183 error: DO REPEAT: At end of input: Syntax error expecting END REPEAT.
187 AT_SETUP([DO REPEAT -- syntax errors])
188 AT_DATA([do-repeat.sps], [dnl
189 DATA LIST LIST NOTABLE /x.
196 DO REPEAT y=a b c **.
200 DO REPEAT y='a' 'b' **.
204 DO REPEAT y=1 2 3/z=4.
206 AT_DATA([insert.sps], [dnl
207 INSERT FILE='do-repeat.sps' ERROR=IGNORE.
209 AT_CHECK([pspp --testing-mode -O format=csv insert.sps], [1], [dnl
210 "do-repeat.sps:2.11-2.12: error: DO REPEAT: Syntax error expecting identifier.
214 "do-repeat.sps:4.11: warning: DO REPEAT: Dummy variable name `x' hides dictionary variable `x'.
218 "do-repeat.sps:4.13-4.14: error: DO REPEAT: Syntax error expecting `='.
222 "do-repeat.sps:6.15: error: DO REPEAT: Dummy variable name `y' is given twice.
223 6 | DO REPEAT y=1/y=2.
226 "do-repeat.sps:8.19-8.20: error: DO REPEAT: Syntax error expecting `/' or end of command.
227 8 | DO REPEAT y=a b c **.
230 "do-repeat.sps:10.17-10.18: error: DO REPEAT: Syntax error expecting number.
231 10 | DO REPEAT y=1 2 **.
234 "do-repeat.sps:12.21-12.22: error: DO REPEAT: Syntax error expecting string.
235 12 | DO REPEAT y='a' 'b' **.
238 "do-repeat.sps:14.13-14.14: error: DO REPEAT: Syntax error expecting substitution values.
242 do-repeat.sps:16: error: DO REPEAT: Each dummy variable must have the same number of substitutions.
244 "do-repeat.sps:16.11-16.17: note: DO REPEAT: Dummy variable y had 3 substitutions.
245 16 | DO REPEAT y=1 2 3/z=4.
248 "do-repeat.sps:16.19-16.21: note: DO REPEAT: Dummy variable z had 1 substitution.
249 16 | DO REPEAT y=1 2 3/z=4.
252 error: DO REPEAT: At end of input: Syntax error expecting END REPEAT.
256 AT_SETUP([DO REPEAT -- duplicate substitutions])
257 AT_DATA([do-repeat.sps], [dnl
258 DATA LIST LIST NOTABLE / numer1 numer2 denom1.
266 * Check that duplicates are OK for both existing (denom1)
267 and nonexistent (perc1) variables.
268 DO REPEAT n=numer1 numer2
271 COMPUTE p = n / d * 100.
274 AT_CHECK([pspp do-repeat.sps], [0], [dnl
275 COMPUTE perc1 = numer1 / denom1 * 100.
277 COMPUTE perc1 = numer2 / denom1 * 100.