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 in file * has different type or width from the same variable in earlier file. In file *, name is a string variable with width 7. In an earlier file, name was a string variable with width 6."
244 match-files.sps:16: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.