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/>.
16 dnl AT_BANNER([MATCH FILES])
18 m4_define([PREPARE_MATCH_FILES],
19 [AT_DATA([data1.txt], [dnl
35 AT_DATA([data2.txt], [dnl
44 AT_DATA([prepare.sps], [dnl
45 DATA LIST NOTABLE FILE='data1.txt' /a b c 1-3 (A).
46 SAVE OUTFILE='data1.sav'.
47 DATA LIST NOTABLE FILE='data2.txt' /a b c 1-3 (A).
48 SAVE OUTFILE='data2.sav'.
50 AT_CHECK([pspp -O format=csv prepare.sps])
51 AT_CHECK([test -f data1.sav && test -f data2.sav])])
53 dnl CHECK_MATCH_FILES(TYPE2, SOURCE1, SOURCE2)
55 dnl Checks the MATCH FILES procedure with the specified combination of:
57 dnl - TYPE2: Either "file" or "table" for the type of matching used for
58 dnl the second data source. (The first data source is always "file").
60 dnl - SOURCE1: Either "system" or "active" for the source of data for
61 dnl the first data source.
63 dnl - SOURCE2: Either "system" or "active" for the source of data for
64 dnl the second data source. (SOURCE1 and SOURCE2 may not both be
66 m4_define([CHECK_MATCH_FILES],
67 [AT_SETUP([MATCH FILES -- $2 file and $3 $1])
70 [m4_if([$1], [file], [dnl
72 a,b,c,d,ina,inb,first,last
89 a,b,c,d,ina,inb,first,last
105 AT_DATA([match-files.sps], [dnl
106 m4_if([$2], [active], [GET FILE='data1.sav'.],
107 [$3], [active], [GET FILE='data2.sav'.],
110 FILE=m4_if([$2], [active], [*], ['data1.sav']) /IN=ina /SORT
111 $1=m4_if([$3], [active], [*], ['data2.sav']) /in=inb /rename c=d
112 /BY a /FIRST=first /LAST=last.
115 AT_CHECK([pspp -o pspp.csv match-files.sps])
116 AT_CHECK([cat pspp.csv], [0], [expout])
119 CHECK_MATCH_FILES([file], [system], [system])
120 CHECK_MATCH_FILES([file], [system], [active])
121 CHECK_MATCH_FILES([file], [active], [system])
122 CHECK_MATCH_FILES([table], [system], [system])
123 CHECK_MATCH_FILES([table], [system], [active])
124 CHECK_MATCH_FILES([table], [active], [system])
126 AT_SETUP([MATCH FILES parallel match])
128 AT_DATA([match-files.sps], [dnl
129 MATCH FILES FILE='data1.sav' /FILE='data2.sav' /RENAME (a b c=d e f).
132 AT_CHECK([pspp -o pspp.csv match-files.sps])
133 AT_CHECK([cat pspp.csv], [0], [dnl
152 dnl Test bug handling TABLE from active dataset found by John Darrington.
153 AT_SETUP([MATCH FILES bug with TABLE from active dataset])
154 AT_DATA([match-files.sps], [dnl
155 DATA LIST LIST NOTABLE /x * y *.
162 SAVE OUTFILE='bar.sav'.
164 DATA LIST LIST NOTABLE /x * z *.
170 MATCH FILES TABLE=* /FILE='bar.sav' /BY=x.
173 AT_CHECK([pspp -o pspp.csv match-files.sps])
174 AT_CHECK([cat pspp.csv], [0], [dnl
183 dnl Tests for a bug which caused MATCH FILES to crash
184 dnl when used with scratch variables.
185 AT_SETUP([MATCH FILES bug with scratch variables])
186 AT_DATA([match-files.sps], [dnl
187 DATA LIST LIST /w * x * y * .
198 MATCH FILES FILE=* /DROP=w.
202 AT_CHECK([pspp -o pspp.csv match-files.sps])
203 AT_CHECK([cat pspp.csv], [0], [dnl
204 Table: Reading free-form data from INLINE.
217 dnl Tests for a bug that caused MATCH FILES to crash
218 dnl with incompatible variables, especially but not
219 dnl exclusively when one variable came from the active
221 AT_SETUP([MATCH FILES with incompatible variable types])
222 AT_DATA([match-files.sps], [dnl
223 DATA LIST LIST NOTABLE/name (A6) x.
229 SAVE OUTFILE='x.sav'.
231 DATA LIST LIST NOTABLE/name (A7) y.
237 MATCH FILES/FILE='x.sav'/FILE=*/BY name.
240 AT_CHECK([pspp -O format=csv match-files.sps], [1], [dnl
241 "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."
243 match-files.sps:16: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.