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([GET DATA /TYPE=TXT])
19 dnl These tests exercise features of GET DATA /TYPE=TXT that
20 dnl it has in common with DATA LIST, using tests drawn from
23 AT_SETUP([GET DATA /TYPE=TXT with explicit delimiters])
24 AT_DATA([get-data.sps], [dnl
25 get data /type=txt /file=inline /delimiters="|X"
26 /variables=A f7.2 B f7.2 C f7.2 D f7.2.
35 AT_CHECK([pspp -o pspp.csv get-data.sps])
36 AT_CHECK([cat pspp.csv], [0], [dnl
40 2.00,22.00,34.00,23.00
41 3.00,34.00,34.00,34.00
45 AT_SETUP([GET DATA /TYPE=TXT with FIRSTCASE])
46 AT_DATA([get-data.sps], [dnl
47 get data /type=txt /file=inline /delimiters=', ' /delcase=variables 4
48 /firstcase=2 /variables=A f7.2 B f7.2 C f7.2 D f7.2.
50 # This record is ignored.
69 AT_CHECK([pspp -o pspp.csv get-data.sps], [0], [ignore])
70 AT_CHECK([cat pspp.csv], [0], [dnl
83 AT_SETUP([GET DATA /TYPE=TXT with FIRSTCASE and tab delimiter])
84 AT_DATA([get-data.sps], [dnl
85 get data /type=txt /file=inline /delimiters='\t' /delcase=variables 4
86 /firstcase=3 /variables=A f7.2 B f7.2 C f7.2 D f7.2.
109 AT_CHECK([pspp -o pspp.csv get-data.sps])
110 AT_CHECK([cat pspp.csv], [0], [dnl
132 AT_SETUP([GET DATA /TYPE=TXT with multiple records per case])
133 AT_DATA([get-data.sps], [dnl
134 get data /type=txt /file=inline /arrangement=fixed /fixcase=3 /variables=
151 AT_CHECK([pspp -o pspp.csv get-data.sps])
152 AT_CHECK([cat pspp.csv], [0], [dnl
155 07/22/07,10/06/2007,321
156 ********,08/26/1789,4
157 01/01/72,12/31/1999,682
161 AT_SETUP([GET DATA /TYPE=TXT with empty trailing record])
162 AT_DATA([get-data.sps], [dnl
163 get data /type=txt /file=inline /arrangement=fixed /fixcase=2 /variables=
180 AT_CHECK([pspp -o pspp.csv get-data.sps])
181 AT_CHECK([cat pspp.csv], [0], [dnl
192 dnl This test is a copy of an example given in the manual
193 dnl in doc/files.texi.
194 AT_SETUP([GET DATA /TYPE=TXT password example])
195 AT_DATA([passwd.data], [dnl
196 root:$1$nyeSP5gD$pDq/:0:0:,,,:/root:/bin/bash
197 blp:$1$BrP/pFg4$g7OG:1000:1000:Ben Pfaff,,,:/home/blp:/bin/bash
198 john:$1$JBuq/Fioq$g4A:1001:1001:John Darrington,,,:/home/john:/bin/bash
199 jhs:$1$D3li4hPL$88X1:1002:1002:Jason Stover,,,:/home/jhs:/bin/csh
201 AT_DATA([passwd.sps], [dnl
202 GET DATA /TYPE=TXT /FILE='passwd.data' /DELIMITERS=':'
203 /VARIABLES=username A20
212 AT_CHECK([pspp -o pspp.csv passwd.sps])
213 AT_CHECK([cat pspp.csv], [0], [dnl
215 username,password,uid,gid,gecos,home,shell
216 root,$1$nyeSP5gD$pDq/,0,0,",,,",/root,/bin/bash
217 blp,$1$BrP/pFg4$g7OG,1000,1000,"Ben Pfaff,,,",/home/blp,/bin/bash
218 john,$1$JBuq/Fioq$g4A,1001,1001,"John Darrington,,,",/home/john,/bin/bash
219 jhs,$1$D3li4hPL$88X1,1002,1002,"Jason Stover,,,",/home/jhs,/bin/csh
223 dnl This test is a copy of an example given in the manual
224 dnl in doc/files.texi.
225 AT_SETUP([GET DATA /TYPE=TXT cars example])
226 AT_DATA([cars.data], [dnl
227 model year mileage price type age
228 Civic 2002 29883 15900 Si 2
229 Civic 2003 13415 15900 EX 1
230 Civic 1992 107000 3800 n/a 12
231 Accord 2002 26613 17900 EX 1
233 AT_DATA([cars.sps], [dnl
234 GET DATA /TYPE=TXT /FILE='cars.data' /DELIMITERS=' ' /FIRSTCASE=2
243 GET DATA /TYPE=TXT /FILE='cars.data' /ARRANGEMENT=FIXED /FIRSTCASE=2
244 /VARIABLES=model 0-7 A
252 AT_CHECK([pspp -o pspp.csv cars.sps])
253 AT_CHECK([cat pspp.csv], [0], [dnl
255 model,year,mileage,price,type,age
256 Civic,2002,29883,15900,Si,2
257 Civic,2003,13415,15900,EX,1
258 Civic,1992,107000,3800,n/a,12
259 Accord,2002,26613,17900,EX,1
262 model,year,mileage,price,type,age
263 Civic,2002,29883,15900,Si,2
264 Civic,2003,13415,15900,EX,1
265 Civic,1992,107000,3800,n/a,12
266 Accord,2002,26613,17900,EX,1
270 dnl This test is a copy of an example given in the manual
271 dnl in doc/files.texi.
272 AT_SETUP([GET DATA /TYPE=TXT pets example])
273 AT_DATA([pets.data], [dnl
274 'Pet''s Name', "Age", "Color", "Date Received", "Price", "Height", "Type"
275 , (Years), , , (Dollars), ,
276 "Rover", 4.5, Brown, "12 Feb 2004", 80, '1''4"', "Dog"
277 "Charlie", , Gold, "5 Apr 2007", 12.3, "3""", "Fish"
278 "Molly", 2, Black, "12 Dec 2006", 25, '5"', "Cat"
279 "Gilly", , White, "10 Apr 2007", 10, "3""", "Guinea Pig"
281 AT_DATA([pets.sps], [dnl
282 GET DATA /TYPE=TXT /FILE='pets.data' /DELIMITERS=', ' /QUALIFIER='''"'
293 AT_CHECK([pspp -o pspp.csv pets.sps])
294 AT_CHECK([cat pspp.csv], [0], [dnl
296 name,age,color,received,price,height,type
297 Rover,4.5,Brown,12.02.2004,80.00,"1'4""",Dog
298 Charlie,. ,Gold,05.04.2007,12.30,"3""",Fish
299 Molly,2.0,Black,12.12.2006,25.00,"5""",Cat
300 Gilly,. ,White,10.04.2007,10.00,"3""",Guinea Pig
303 dnl " (fixes Emacs highlighting)
305 AT_SETUP([GET DATA /TYPE=TXT with IMPORTCASE])
306 AT_CHECK([$PYTHON3 > test.data -c '
307 for i in range(1, 101):
310 AT_DATA([get-data.sps], [dnl
311 get data /type=txt /file='test.data' /importcase=first 10 /variables x f8.0.
312 get data /type=txt /file='test.data' /importcase=percent 1 /variables x f8.0.
313 get data /type=txt /file='test.data' /importcase=percent 35 /variables x f8.0.
314 get data /type=txt /file='test.data' /importcase=percent 95 /variables x f8.0.
315 get data /type=txt /file='test.data' /importcase=percent 100 /variables x f8.0.
317 AT_CHECK([pspp -O format=csv get-data.sps], [0], [dnl
318 "get-data.sps:1.39-1.57: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand. (N OF CASES or SAMPLE may be used to substitute.).
319 1 | get data /type=txt /file='test.data' /importcase=first 10 /variables x f8.0.
320 | ^~~~~~~~~~~~~~~~~~~"
322 "get-data.sps:2.39-2.58: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand. (N OF CASES or SAMPLE may be used to substitute.).
323 2 | get data /type=txt /file='test.data' /importcase=percent 1 /variables x f8.0.
324 | ^~~~~~~~~~~~~~~~~~~~"
326 "get-data.sps:3.39-3.59: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand. (N OF CASES or SAMPLE may be used to substitute.).
327 3 | get data /type=txt /file='test.data' /importcase=percent 35 /variables x f8.0.
328 | ^~~~~~~~~~~~~~~~~~~~~"
330 "get-data.sps:4.39-4.59: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand. (N OF CASES or SAMPLE may be used to substitute.).
331 4 | get data /type=txt /file='test.data' /importcase=percent 95 /variables x f8.0.
332 | ^~~~~~~~~~~~~~~~~~~~~"
334 "get-data.sps:5.39-5.60: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand. (N OF CASES or SAMPLE may be used to substitute.).
335 5 | get data /type=txt /file='test.data' /importcase=percent 100 /variables x f8.0.
336 | ^~~~~~~~~~~~~~~~~~~~~~"
340 AT_SETUP([GET DATA /TYPE=TXT with ENCODING subcommand])
341 AT_CHECK([i18n-test supports_encodings UTF-8 ISO-8859-1])
342 AT_DATA([get-data.sps], [dnl
344 get data /type=txt /file='data.txt' /encoding='iso-8859-1'
345 /delimiters="," /variables=s a8.
348 printf '\351' > data.txt # é in ISO-8859-1.
349 AT_CHECK([pspp -o pspp.csv get-data.sps])
350 AT_CHECK([cat pspp.csv], [0], [dnl
358 AT_SETUP([GET DATA /TYPE= truncated])
360 AT_DATA([x.sps], [dnl
365 AT_CHECK([pspp -o pspp.csv x.sps], [1], [ignore])
371 AT_SETUP([GET DATA /TYPE=txt bug])
374 AT_DATA([thing.txt], [dnl
381 AT_DATA([x.sps], [dnl
385 /ARRANGEMENT=DELIMITED
396 AT_CHECK([pspp -O format=csv x.sps], [0], [dnl
408 AT_SETUP([GET DATA /TYPE=txt another bug])
410 AT_DATA([crash.sps], [dnl
411 get data /type=txt /file=inline /variables=C f7.2 D f7>2.
419 AT_CHECK([pspp -O format=csv crash.sps], [1], [ignore])