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([MATCH FILES])
19 m4_define([PREPARE_MATCH_FILES],
20 [AT_DATA([data1.txt], [dnl
36 AT_DATA([data2.txt], [dnl
45 AT_DATA([prepare.sps], [dnl
46 DATA LIST NOTABLE FILE='data1.txt' /a b c 1-3 (A).
47 SAVE OUTFILE='data1.sav'.
48 DATA LIST NOTABLE FILE='data2.txt' /a b c 1-3 (A).
49 SAVE OUTFILE='data2.sav'.
51 AT_CHECK([pspp -O format=csv prepare.sps])
52 AT_CHECK([test -f data1.sav && test -f data2.sav])])
54 dnl CHECK_MATCH_FILES(TYPE2, SOURCE1, SOURCE2)
56 dnl Checks the MATCH FILES procedure with the specified combination of:
58 dnl - TYPE2: Either "file" or "table" for the type of matching used for
59 dnl the second data source. (The first data source is always "file").
61 dnl - SOURCE1: Either "system" or "active" for the source of data for
62 dnl the first data source.
64 dnl - SOURCE2: Either "system" or "active" for the source of data for
65 dnl the second data source. (SOURCE1 and SOURCE2 may not both be
67 m4_define([CHECK_MATCH_FILES],
68 [AT_SETUP([MATCH FILES -- $2 file and $3 $1])
71 [m4_if([$1], [file], [dnl
73 a,b,c,d,ina,inb,first,last
90 a,b,c,d,ina,inb,first,last
106 AT_DATA([match-files.sps], [dnl
107 m4_if([$2], [active], [GET FILE='data1.sav'.],
108 [$3], [active], [GET FILE='data2.sav'.],
111 FILE=m4_if([$2], [active], [*], ['data1.sav']) /IN=ina /SORT
112 $1=m4_if([$3], [active], [*], ['data2.sav']) /in=inb /rename c=d
113 /BY a /FIRST=first /LAST=last.
116 AT_CHECK([pspp -o pspp.csv match-files.sps])
117 AT_CHECK([cat pspp.csv], [0], [expout])
120 CHECK_MATCH_FILES([file], [system], [system])
121 CHECK_MATCH_FILES([file], [system], [active])
122 CHECK_MATCH_FILES([file], [active], [system])
123 CHECK_MATCH_FILES([table], [system], [system])
124 CHECK_MATCH_FILES([table], [system], [active])
125 CHECK_MATCH_FILES([table], [active], [system])
127 AT_SETUP([MATCH FILES parallel match])
129 AT_DATA([match-files.sps], [dnl
130 MATCH FILES FILE='data1.sav' /FILE='data2.sav' /RENAME (a b c=d e f).
133 AT_CHECK([pspp -o pspp.csv match-files.sps])
134 AT_CHECK([cat pspp.csv], [0], [dnl
153 dnl Test bug handling TABLE from active dataset found by John Darrington.
154 AT_SETUP([MATCH FILES bug with TABLE from active dataset])
155 AT_DATA([match-files.sps], [dnl
156 DATA LIST LIST NOTABLE /x * y *.
163 SAVE OUTFILE='bar.sav'.
165 DATA LIST LIST NOTABLE /x * z *.
171 MATCH FILES TABLE=* /FILE='bar.sav' /BY=x.
174 AT_CHECK([pspp -o pspp.csv match-files.sps])
175 AT_CHECK([cat pspp.csv], [0], [dnl
184 dnl Tests for a bug which caused MATCH FILES to crash
185 dnl when used with scratch variables.
186 AT_SETUP([MATCH FILES bug with scratch variables])
187 AT_DATA([match-files.sps], [dnl
188 DATA LIST LIST /w * x * y * .
199 MATCH FILES FILE=* /DROP=w.
203 AT_CHECK([pspp -o pspp.csv match-files.sps])
204 AT_CHECK([cat pspp.csv], [0], [dnl
205 Table: Reading free-form data from INLINE.
218 dnl Tests for a bug that caused MATCH FILES to crash
219 dnl with incompatible variables, especially but not
220 dnl exclusively when one variable came from the active
222 AT_SETUP([MATCH FILES with incompatible variable types])
223 AT_DATA([match-files.sps], [dnl
224 DATA LIST LIST NOTABLE/name (A6) x.
230 SAVE OUTFILE='x.sav'.
232 DATA LIST LIST NOTABLE/name (A7) y.
238 MATCH FILES/FILE='x.sav'/FILE=*/BY name.
241 AT_CHECK([pspp -O format=csv match-files.sps], [1], [dnl
242 match-files.sps:15: error: MATCH FILES: Variable name has different type or width in different files.
244 "match-files.sps:15.13-15.24: note: MATCH FILES: In file `x.sav', name is a string with width 6.
245 15 | MATCH FILES/FILE='x.sav'/FILE=*/BY name.
248 "match-files.sps:15.26-15.31: note: MATCH FILES: In file *, name is a string with width 7.
249 15 | MATCH FILES/FILE='x.sav'/FILE=*/BY name.
252 match-files.sps:16: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
256 AT_SETUP([MATCH FILES syntax errors])
257 AT_DATA([insert.sps], [dnl
258 INSERT FILE='match-files.sps' ERROR=IGNORE.
260 AT_DATA([match-files.sps], [dnl
263 DATA LIST LIST NOTABLE/name (A6) x.
269 SAVE OUTFILE='x.sav'.
274 DATA LIST LIST NOTABLE/name (A7) y.
280 MATCH FILES/FILE='x.sav'/FILE=*/BY name.
281 MATCH FILES/FILE='x.sav'/IN=**.
282 MATCH FILES/FILE='x.sav'/IN=x/IN=y.
283 MATCH FILES/FILE='x.sav'/BY=x/BY=y.
284 MATCH FILES/FILE='x.sav'/BY=**.
285 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/BY y.
286 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/BY x.
287 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/FIRST x/FIRST y.
288 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/FIRST=**.
289 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/LAST x/LAST y.
290 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/LAST=**.
291 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/DROP=xyzzy.
292 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/DROP=ALL.
293 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/KEEP=xyzzy.
294 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/LAST=x **.
295 MATCH FILES/FILE='x.sav'/TABLE=*/RENAME(name=name2).
296 MATCH FILES/FILE='x.sav'/SORT/FILE=*/RENAME(name=name2)/SORT.
297 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/FIRST=x.
298 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/LAST=x.
299 MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/IN=x.
301 AT_CHECK([pspp --testing-mode -O format=csv insert.sps], [1], [dnl
302 "match-files.sps:1.18: error: MATCH FILES: Cannot specify the active dataset since none has been defined.
303 1 | MATCH FILES/FILE=*.
306 "match-files.sps:12.18: error: MATCH FILES: This command may not be used after TEMPORARY when the active dataset is an input source. Temporary transformations will be made permanent.
307 12 | MATCH FILES/FILE=*.
310 match-files.sps:20: error: MATCH FILES: Variable name has different type or width in different files.
312 "match-files.sps:20.13-20.24: note: MATCH FILES: In file `x.sav', name is a string with width 6.
313 20 | MATCH FILES/FILE='x.sav'/FILE=*/BY name.
316 "match-files.sps:20.26-20.31: note: MATCH FILES: In file *, name is a string with width 7.
317 20 | MATCH FILES/FILE='x.sav'/FILE=*/BY name.
320 "match-files.sps:21.29-21.30: error: MATCH FILES: Syntax error expecting identifier.
321 21 | MATCH FILES/FILE='x.sav'/IN=**.
324 "match-files.sps:22.34: error: MATCH FILES: Multiple IN subcommands for a single FILE or TABLE.
325 22 | MATCH FILES/FILE='x.sav'/IN=x/IN=y.
328 "match-files.sps:23.31-23.32: error: MATCH FILES: Subcommand BY may only be specified once.
329 23 | MATCH FILES/FILE='x.sav'/BY=x/BY=y.
332 "match-files.sps:24.29-24.30: error: MATCH FILES: Syntax error expecting variable name.
333 24 | MATCH FILES/FILE='x.sav'/BY=**.
336 "match-files.sps:25.13-25.24: error: MATCH FILES: File `x.sav' lacks BY variable y.
337 25 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/BY y.
340 "match-files.sps:26.26-26.31: error: MATCH FILES: File * lacks BY variable x.
341 26 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/BY x.
344 "match-files.sps:27.60-27.64: error: MATCH FILES: Subcommand FIRST may only be specified once.
345 27 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/FIRST x/FIRST y.
348 "match-files.sps:28.58-28.59: error: MATCH FILES: Syntax error expecting identifier.
349 28 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/FIRST=**.
352 "match-files.sps:29.59-29.62: error: MATCH FILES: Subcommand LAST may only be specified once.
353 29 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/LAST x/LAST y.
356 "match-files.sps:30.57-30.58: error: MATCH FILES: Syntax error expecting identifier.
357 30 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/LAST=**.
360 "match-files.sps:31.57-31.61: error: MATCH FILES: xyzzy is not a variable name.
361 31 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/DROP=xyzzy.
364 "match-files.sps:32.52-32.59: error: MATCH FILES: Cannot DROP all variables from dictionary.
365 32 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/DROP=ALL.
368 "match-files.sps:33.57-33.61: error: MATCH FILES: xyzzy is not a variable name.
369 33 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/KEEP=xyzzy.
372 "match-files.sps:34.59-34.60: error: MATCH FILES: Syntax error expecting end of command.
373 34 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/LAST=x **.
376 "match-files.sps:35.26-35.32: error: MATCH FILES: BY is required when TABLE is specified.
377 35 | MATCH FILES/FILE='x.sav'/TABLE=*/RENAME(name=name2).
380 "match-files.sps:36.26-36.29: error: MATCH FILES: BY is required when SORT is specified.
381 36 | MATCH FILES/FILE='x.sav'/SORT/FILE=*/RENAME(name=name2)/SORT.
384 "match-files.sps:37.58: error: MATCH FILES: Variable name x specified on FIRST subcommand duplicates an existing variable name.
385 37 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/FIRST=x.
388 "match-files.sps:38.57: error: MATCH FILES: Variable name x specified on LAST subcommand duplicates an existing variable name.
389 38 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/LAST=x.
392 "match-files.sps:39.55: error: MATCH FILES: Variable name x specified on IN subcommand duplicates an existing variable name.
393 39 | MATCH FILES/FILE='x.sav'/FILE=*/RENAME(name=name2)/IN=x.