MRSETS: Improve error messages.
[pspp] / tests / language / dictionary / mrsets.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([MRSETS])
18
19 m4_define([DEFINE_MRSETS_DATA],
20   [DATA LIST NOTABLE /w x y z 1-4 a b c d 5-8 (a).
21 BEGIN DATA.
22 1234acbd
23 5678efgh
24 END DATA.])
25
26 m4_define([DEFINE_MRSETS],
27   [DEFINE_MRSETS_DATA
28
29 [VARIABLE LABEL
30     w 'duplicate variable label'
31     x 'Variable x'
32     z 'Duplicate variable label'.
33 VALUE LABELS
34     /w 1 'w value 1'
35     /y 1 'duplicate Value label'
36     /z 1 'duplicate value Label'
37     /a b c d 'a' 'burger' 'b' 'fries' 'c' 'shake' 'd' 'taco'.
38 ADD VALUE LABELS
39     /b 'b' 'Fries'
40     /c 'b' 'XXX'.
41 MRSETS
42     /MDGROUP NAME=$a
43      LABEL='First multiple dichotomy group'
44      CATEGORYLABELS=VARLABELS
45      VARIABLES=w x y z
46      VALUE=5
47     /MDGROUP NAME=$b
48      CATEGORYLABELS=COUNTEDVALUES
49      VARIABLES=z y
50      VALUE=123
51     /MDGROUP NAME=$c
52      LABELSOURCE=VARLABEL
53      CATEGORYLABELS=COUNTEDVALUES
54      VARIABLES=w x y z
55      VALUE=1
56     /MDGROUP NAME=$d
57      LABELSOURCE=VARLABEL
58      VARIABLES=a b c d
59      VALUE='c'
60     /MCGROUP NAME=$e
61      LABEL='First multiple category group'
62      VARIABLES=w x y z
63     /MCGROUP NAME=$f
64      VARIABLES=a b c d.
65 ]])
66
67 m4_define([DEFINE_MRSETS_OUTPUT], [dnl
68 "mrsets.sps:23.16-23.22: warning: MRSETS: Variables w and z specified as part of multiple dichotomy group $a have the same variable label.  Categories represented by these variables will not be distinguishable in output.
69    23 |      VARIABLES=w x y z
70       |                ^~~~~~~"
71
72 "mrsets.sps:27.16-27.18: warning: MRSETS: Variable z specified as part of multiple dichotomy group $b (which has CATEGORYLABELS=COUNTEDVALUES) has no value label for its counted value.  This category will not be distinguishable in output.
73    27 |      VARIABLES=z y
74       |                ^~~"
75
76 "mrsets.sps:27.16-27.18: warning: MRSETS: Variable y specified as part of multiple dichotomy group $b (which has CATEGORYLABELS=COUNTEDVALUES) has no value label for its counted value.  This category will not be distinguishable in output.
77    27 |      VARIABLES=z y
78       |                ^~~"
79
80 "mrsets.sps:32.16-32.22: warning: MRSETS: Variable x specified as part of multiple dichotomy group $c (which has CATEGORYLABELS=COUNTEDVALUES) has no value label for its counted value.  This category will not be distinguishable in output.
81    32 |      VARIABLES=w x y z
82       |                ^~~~~~~"
83
84 "mrsets.sps:32.16-32.22: warning: MRSETS: Variables y and z specified as part of multiple dichotomy group $c (which has CATEGORYLABELS=COUNTEDVALUES) have the same value label for the group's counted value.  These categories will not be distinguishable in output.
85    32 |      VARIABLES=w x y z
86       |                ^~~~~~~"
87
88 "mrsets.sps:35.6-35.25: warning: MRSETS: MDGROUP subcommand for group $d specifies LABELSOURCE=VARLABEL but not CATEGORYLABELS=COUNTEDVALUES.  Ignoring LABELSOURCE.
89    35 |      LABELSOURCE=VARLABEL
90       |      ^~~~~~~~~~~~~~~~~~~~"
91
92 "mrsets.sps:40.16-40.22: warning: MRSETS: Variables specified on MCGROUP should have the same categories, but w and y (and possibly others) in multiple category group $e have different value labels for value 1.
93    40 |      VARIABLES=w x y z
94       |                ^~~~~~~"
95
96 "mrsets.sps:42.16-42.22: warning: MRSETS: Variables specified on MCGROUP should have the same categories, but a and c (and possibly others) in multiple category group $f have different value labels for value b.
97    42 |      VARIABLES=a b c d.
98       |                ^~~~~~~"
99 ])
100
101 m4_define([MRSETS_DISPLAY_OUTPUT], [dnl
102 Table: Multiple Response Sets
103 Name,Label,Encoding,Counted Value,Member Variables
104 $a,First multiple dichotomy group,Dichotomies,5,"w
105 x
106 y
107 z"
108 $b,,Dichotomies,123,"z
109 y"
110 $c,duplicate variable label,Dichotomies,1,"w
111 x
112 y
113 z"
114 $d,,Dichotomies,c,"a
115 b
116 c
117 d"
118 $e,First multiple category group,Categories,,"w
119 x
120 y
121 z"
122 $f,,Categories,,"a
123 b
124 c
125 d"
126 ])
127
128 AT_SETUP([MRSETS add, display, delete])
129 AT_DATA([mrsets.sps],
130   [DEFINE_MRSETS
131 [MRSETS
132     /DISPLAY NAME=[$a]
133     /DISPLAY NAME=ALL
134     /DELETE NAME=[$c]
135     /DISPLAY NAME=ALL
136     /DELETE NAME=ALL
137     /DISPLAY NAME=ALL.
138 ]])
139 AT_CHECK([pspp -o - -O format=csv -o mrsets.csv -o mrsets.txt mrsets.sps], [0],
140   [DEFINE_MRSETS_OUTPUT
141 Table: Multiple Response Sets
142 Name,Label,Encoding,Counted Value,Member Variables
143 $a,First multiple dichotomy group,Dichotomies,5,"w
144 x
145 y
146 z"
147
148 Table: Multiple Response Sets
149 Name,Label,Encoding,Counted Value,Member Variables
150 $a,First multiple dichotomy group,Dichotomies,5,"w
151 x
152 y
153 z"
154 $b,,Dichotomies,123,"z
155 y"
156 $c,duplicate variable label,Dichotomies,1,"w
157 x
158 y
159 z"
160 $d,,Dichotomies,c,"a
161 b
162 c
163 d"
164 $e,First multiple category group,Categories,,"w
165 x
166 y
167 z"
168 $f,,Categories,,"a
169 b
170 c
171 d"
172
173 Table: Multiple Response Sets
174 Name,Label,Encoding,Counted Value,Member Variables
175 $a,First multiple dichotomy group,Dichotomies,5,"w
176 x
177 y
178 z"
179 $b,,Dichotomies,123,"z
180 y"
181 $d,,Dichotomies,c,"a
182 b
183 c
184 d"
185 $e,First multiple category group,Categories,,"w
186 x
187 y
188 z"
189 $f,,Categories,,"a
190 b
191 c
192 d"
193
194 "mrsets.sps:50.19-50.21: note: MRSETS: The active dataset dictionary does not contain any multiple response sets.
195    50 |     /DISPLAY NAME=ALL.
196       |                   ^~~"
197 ])
198 AT_CLEANUP
199
200 AT_SETUP([MRSETS read and write])
201 AT_DATA([mrsets.sps],
202   [DEFINE_MRSETS
203 SAVE OUTFILE='mrsets.sav'.
204 ])
205 AT_CHECK([pspp -O format=csv mrsets.sps], [0], [DEFINE_MRSETS_OUTPUT])
206 AT_DATA([mrsets2.sps],
207   [GET FILE='mrsets.sav'.
208 MRSETS /DISPLAY NAME=ALL.
209 ])
210 AT_CHECK([pspp -O format=csv mrsets2.sps], [0], [MRSETS_DISPLAY_OUTPUT],
211   [], [hd mrsets.sav])
212 AT_CLEANUP
213
214 AT_SETUP([MRSETS syntax errors])
215 AT_DATA([mrsets.sps], [dnl
216 DATA LIST NOTABLE /w x y z 1-4 a b c d 5-8 (a).
217 BEGIN DATA.
218 1234acbd
219 5678efgh
220 END DATA.
221 VARIABLE LABEL
222     w 'duplicate variable label'
223     x 'Variable x'
224     z 'Duplicate variable label'.
225 VALUE LABELS
226     /w 1 'w value 1'
227     /y 1 'duplicate Value label'
228     /z 1 'duplicate value Label'
229     /a b c d 'a' 'burger' 'b' 'fries' 'c' 'shake' 'd' 'taco'.
230 ADD VALUE LABELS
231     /b 'b' 'Fries'
232     /c 'b' 'XXX'.
233
234 MRSETS /MDGROUP NAME **.
235 MRSETS /MDGROUP NAME=**.
236 MRSETS /MDGROUP NAME=x.
237 MRSETS /MDGROUP VARIABLES **.
238 MRSETS /MDGROUP VARIABLES=**.
239 MRSETS /MDGROUP VARIABLES=a.
240 MRSETS /MDGROUP LABEL **.
241 MRSETS /MDGROUP LABEL=**.
242 MRSETS /MDGROUP LABELSOURCE=**.
243 MRSETS /MDGROUP VALUE **.
244 MRSETS /MDGROUP VALUE=1.5.
245 MRSETS /MDGROUP VALUE=**.
246 MRSETS /MDGROUP CATEGORYLABELS **.
247 MRSETS /MDGROUP CATEGORYLABELS=**.
248 MRSETS /MDGROUP **.
249 MRSETS /MCGROUP **.
250 MRSETS /MDGROUP.
251 MRSETS /MDGROUP NAME=[$x].
252 MRSETS /MDGROUP NAME=[$x] VARIABLES=a b VALUE=1.
253 MRSETS /MDGROUP NAME=[$x] VARIABLES=x y VALUE='a'.
254 MRSETS /MDGROUP NAME=[$x] VARIABLES=a b VALUE='xyzzy'.
255 MRSETS /MDGROUP NAME=[$x] VARIABLES=a b VALUE='y' LABELSOURCE=VARLABEL.
256 MRSETS /MDGROUP NAME=[$x] VARIABLES=w z VALUE=1 CATEGORYLABELS=VARLABELS.
257 MRSETS /MDGROUP NAME=[$x] VARIABLES=a b VALUE='y'
258   LABELSOURCE=VARLABEL CATEGORYLABELS=COUNTEDVALUES
259   LABEL='foo'.
260 MRSETS /MDGROUP NAME=[$x] VARIABLES=y z VALUE=1
261   LABELSOURCE=VARLABEL CATEGORYLABELS=COUNTEDVALUES.
262 MRSETS /MCGROUP NAME=[$x] VARIABLES=w x y z.
263
264 MRSETS /DELETE **.
265 MRSETS /DELETE NAME**.
266 MRSETS /DELETE NAME=[[**]].
267 MRSETS /DELETE NAME=[[$x]].
268 MRSETS /DELETE NAME=**.
269
270 MRSETS /DISPLAY NAME=ALL.
271 ])
272 AT_CHECK([pspp -O format=csv mrsets.sps], [1], [dnl
273 "mrsets.sps:19.22-19.23: error: MRSETS: Syntax error expecting `='.
274    19 | MRSETS /MDGROUP NAME **.
275       |                      ^~"
276
277 "mrsets.sps:20.22-20.23: error: MRSETS: Syntax error expecting identifier.
278    20 | MRSETS /MDGROUP NAME=**.
279       |                      ^~"
280
281 "mrsets.sps:21.22: error: MRSETS: x is not a valid name for a multiple response set.  Multiple response set names must begin with `$'.
282    21 | MRSETS /MDGROUP NAME=x.
283       |                      ^"
284
285 "mrsets.sps:22.27-22.28: error: MRSETS: Syntax error expecting `='.
286    22 | MRSETS /MDGROUP VARIABLES **.
287       |                           ^~"
288
289 "mrsets.sps:23.27-23.28: error: MRSETS: Syntax error expecting variable name.
290    23 | MRSETS /MDGROUP VARIABLES=**.
291       |                           ^~"
292
293 "mrsets.sps:24.27: error: MRSETS: At least two variables are required.
294    24 | MRSETS /MDGROUP VARIABLES=a.
295       |                           ^"
296
297 "mrsets.sps:25.23-25.24: error: MRSETS: Syntax error expecting `='.
298    25 | MRSETS /MDGROUP LABEL **.
299       |                       ^~"
300
301 "mrsets.sps:26.23-26.24: error: MRSETS: Syntax error expecting string.
302    26 | MRSETS /MDGROUP LABEL=**.
303       |                       ^~"
304
305 "mrsets.sps:27.28-27.30: error: MRSETS: Syntax error expecting `=VARLABEL'.
306    27 | MRSETS /MDGROUP LABELSOURCE=**.
307       |                            ^~~"
308
309 "mrsets.sps:28.23-28.24: error: MRSETS: Syntax error expecting `='.
310    28 | MRSETS /MDGROUP VALUE **.
311       |                       ^~"
312
313 "mrsets.sps:29.23-29.25: error: MRSETS: Numeric VALUE must be an integer.
314    29 | MRSETS /MDGROUP VALUE=1.5.
315       |                       ^~~"
316
317 "mrsets.sps:30.23-30.24: error: MRSETS: Syntax error expecting integer or string.
318    30 | MRSETS /MDGROUP VALUE=**.
319       |                       ^~"
320
321 "mrsets.sps:31.32-31.33: error: MRSETS: Syntax error expecting `='.
322    31 | MRSETS /MDGROUP CATEGORYLABELS **.
323       |                                ^~"
324
325 "mrsets.sps:32.32-32.33: error: MRSETS: Syntax error expecting VARLABELS or COUNTEDVALUES.
326    32 | MRSETS /MDGROUP CATEGORYLABELS=**.
327       |                                ^~"
328
329 "mrsets.sps:33.17-33.18: error: MRSETS: Syntax error expecting NAME, VARIABLES, LABEL, LABELSOURCE, VALUE, or CATEGORYLABELS.
330    33 | MRSETS /MDGROUP **.
331       |                 ^~"
332
333 "mrsets.sps:34.17-34.18: error: MRSETS: Syntax error expecting NAME, VARIABLES, or LABEL.
334    34 | MRSETS /MCGROUP **.
335       |                 ^~"
336
337 "mrsets.sps:35.16: error: MRSETS: Required NAME specification missing from MDGROUP subcommand.
338    35 | MRSETS /MDGROUP.
339       |                ^"
340
341 "mrsets.sps:36.24: error: MRSETS: Required VARIABLES specification missing from MDGROUP subcommand.
342    36 | MRSETS /MDGROUP NAME=$x.
343       |                        ^"
344
345 mrsets.sps:37: error: MRSETS: VARIABLES and VALUE must have the same type.
346
347 "mrsets.sps:37.35-37.37: note: MRSETS: These are string variables.
348    37 | MRSETS /MDGROUP NAME=$x VARIABLES=a b VALUE=1.
349       |                                   ^~~"
350
351 "mrsets.sps:37.45: note: MRSETS: This is a numeric value.
352    37 | MRSETS /MDGROUP NAME=$x VARIABLES=a b VALUE=1.
353       |                                             ^"
354
355 mrsets.sps:38: error: MRSETS: VARIABLES and VALUE must have the same type.
356
357 "mrsets.sps:38.35-38.37: note: MRSETS: These are numeric variables.
358    38 | MRSETS /MDGROUP NAME=$x VARIABLES=x y VALUE='a'.
359       |                                   ^~~"
360
361 "mrsets.sps:38.45-38.47: note: MRSETS: This is a string value.
362    38 | MRSETS /MDGROUP NAME=$x VARIABLES=x y VALUE='a'.
363       |                                             ^~~"
364
365 mrsets.sps:39: error: MRSETS: The VALUE string must be no longer than the narrowest variable in the group.
366
367 "mrsets.sps:39.45-39.51: note: MRSETS: The VALUE string is 5 bytes long.
368    39 | MRSETS /MDGROUP NAME=$x VARIABLES=a b VALUE='xyzzy'.
369       |                                             ^~~~~~~"
370
371 "mrsets.sps:39.35-39.37: note: MRSETS: Variable a has a width of 1 bytes.
372    39 | MRSETS /MDGROUP NAME=$x VARIABLES=a b VALUE='xyzzy'.
373       |                                   ^~~"
374
375 "mrsets.sps:40.49-40.68: warning: MRSETS: MDGROUP subcommand for group $x specifies LABELSOURCE=VARLABEL but not CATEGORYLABELS=COUNTEDVALUES.  Ignoring LABELSOURCE.
376    40 | MRSETS /MDGROUP NAME=$x VARIABLES=a b VALUE='y' LABELSOURCE=VARLABEL.
377       |                                                 ^~~~~~~~~~~~~~~~~~~~"
378
379 "mrsets.sps:41.35-41.37: warning: MRSETS: Variables w and z specified as part of multiple dichotomy group $x have the same variable label.  Categories represented by these variables will not be distinguishable in output.
380    41 | MRSETS /MDGROUP NAME=$x VARIABLES=w z VALUE=1 CATEGORYLABELS=VARLABELS.
381       |                                   ^~~"
382
383 "mrsets.sps:44: warning: MRSETS: MDGROUP subcommand for group $x specifies both LABEL and LABELSOURCE, but only one of these subcommands may be used at a time.  Ignoring LABELSOURCE."
384
385 "mrsets.sps:44.3-44.13: note: MRSETS: Here is the LABEL setting.
386    44 |   LABEL='foo'.
387       |   ^~~~~~~~~~~"
388
389 "mrsets.sps:43.3-43.22: note: MRSETS: Here is the LABELSOURCE setting.
390    43 |   LABELSOURCE=VARLABEL CATEGORYLABELS=COUNTEDVALUES
391       |   ^~~~~~~~~~~~~~~~~~~~"
392
393 "mrsets.sps:42.35-42.37: warning: MRSETS: Variable a specified as part of multiple dichotomy group $x (which has CATEGORYLABELS=COUNTEDVALUES) has no value label for its counted value.  This category will not be distinguishable in output.
394    42 | MRSETS /MDGROUP NAME=$x VARIABLES=a b VALUE='y'
395       |                                   ^~~"
396
397 "mrsets.sps:42.35-42.37: warning: MRSETS: Variable b specified as part of multiple dichotomy group $x (which has CATEGORYLABELS=COUNTEDVALUES) has no value label for its counted value.  This category will not be distinguishable in output.
398    42 | MRSETS /MDGROUP NAME=$x VARIABLES=a b VALUE='y'
399       |                                   ^~~"
400
401 "mrsets.sps:45.35-45.37: warning: MRSETS: Variables y and z specified as part of multiple dichotomy group $x (which has CATEGORYLABELS=COUNTEDVALUES) have the same value label for the group's counted value.  These categories will not be distinguishable in output.
402    45 | MRSETS /MDGROUP NAME=$x VARIABLES=y z VALUE=1
403       |                                   ^~~"
404
405 "mrsets.sps:47.35-47.41: warning: MRSETS: Variables specified on MCGROUP should have the same categories, but w and y (and possibly others) in multiple category group $x have different value labels for value 1.
406    47 | MRSETS /MCGROUP NAME=$x VARIABLES=w x y z.
407       |                                   ^~~~~~~"
408
409 "mrsets.sps:49.16-49.17: error: MRSETS: Syntax error expecting `NAME='.
410    49 | MRSETS /DELETE **.
411       |                ^~"
412
413 "mrsets.sps:50.16-50.21: error: MRSETS: Syntax error expecting `NAME='.
414    50 | MRSETS /DELETE NAME**.
415       |                ^~~~~~"
416
417 "mrsets.sps:51.22-51.23: error: MRSETS: Syntax error expecting identifier.
418    51 | MRSETS /DELETE NAME=[[**]].
419       |                      ^~"
420
421 "mrsets.sps:53.21-53.22: error: MRSETS: Syntax error expecting `@<:@' or ALL.
422    53 | MRSETS /DELETE NAME=**.
423       |                     ^~"
424
425 "mrsets.sps:55.22-55.24: note: MRSETS: The active dataset dictionary does not contain any multiple response sets.
426    55 | MRSETS /DISPLAY NAME=ALL.
427       |                      ^~~"
428 ])
429 AT_CLEANUP