Automatically infer variables' measurement level from format and data.
[pspp] / tests / data / por-file.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([portable files])
18
19 AT_SETUP([overwriting portable file])
20 AT_DATA([output.por], [abcdef
21 ])
22 cp output.por output.por.backup
23 AT_DATA([porfile.sps], [dnl
24 DATA LIST NOTABLE/x 1.
25 BEGIN DATA.
26 5
27 END DATA.
28 EXPORT OUTFILE='output.por'.
29 ])
30 AT_CHECK([pspp -O format=csv porfile.sps])
31 AT_CHECK([cmp output.por output.por.backup], [1], [ignore])
32 AT_CLEANUP
33
34 AT_SETUP([overwriting portable file atomically])
35 AT_DATA([output.por], [abcdef
36 ])
37 cp output.por output.por.backup
38 AT_DATA([porfile.sps],
39 [[DATA LIST NOTABLE/x 1.
40 BEGIN DATA.
41 5
42 END DATA.
43 XEXPORT OUTFILE='output.por'.
44 HOST COMMAND=['kill -TERM $PPID'].
45 ]])
46 AT_CHECK([pspp -O format=csv porfile.sps], [143], [], [ignore])
47 AT_CHECK([cmp output.por output.por.backup])
48 AT_CHECK(
49   [for file in *.tmp*; do if test -e $file; then echo $file; exit 1; fi; done])
50 AT_CLEANUP
51
52 AT_SETUP([write to same portable file being read])
53 AT_DATA([export.sps], [dnl
54 DATA LIST NOTABLE/x 1.
55 BEGIN DATA.
56 2
57 END DATA.
58 EXPORT OUTFILE='data.por'.
59 ])
60 AT_CHECK([pspp -O format=csv export.sps])
61 AT_CHECK([test -s data.por])
62 AT_CHECK(
63   [for file in *.tmp*; do if test -e $file; then echo $file; exit 1; fi; done])
64 AT_DATA([export2.sps], [dnl
65 IMPORT FILE='data.por'.
66 COMPUTE y = x * 2.
67 EXPORT OUTFILE='data.por'.
68 ])
69 AT_CHECK([pspp -O format=csv export2.sps])
70 AT_CHECK(
71   [for file in *.tmp*; do if test -e $file; then echo $file; exit 1; fi; done])
72 AT_DATA([export3.sps], [dnl
73 IMPORT FILE='data.por'.
74 LIST.
75 ])
76 AT_CHECK([pspp -O format=csv export3.sps], [0], [dnl
77 Table: Data List
78 X,Y
79 2,4.00
80 ])
81 AT_CLEANUP
82
83 dnl This checks for a bug in the portable file writer that caused an infinite
84 dnl loop in some cases, and other problems in other cases, when a variable
85 dnl had value labels.
86 AT_SETUP([write portable file with value labels])
87 AT_DATA([export.sps], [dnl
88 DATA LIST NOTABLE/var1 TO var5 1-5.
89 VALUE LABELS
90         /var1 1 'one'
91         /var2 2 'two'
92         /var3 3 'three'
93         /var4 4 'four'
94         /var5 5 'five'.
95 BEGIN DATA.
96 12345
97 END DATA.
98 EXPORT OUTFILE='data.por'.
99 ])
100 AT_CHECK([pspp -O format=csv export.sps])
101 AT_DATA([import.sps], [dnl
102 IMPORT FILE='data.por'.
103 EXECUTE.
104 DISPLAY DICTIONARY.
105 LIST.
106 ])
107 AT_CHECK([pspp -O format=csv import.sps], [0], [dnl
108 Table: Variables
109 Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
110 VAR1,1,Nominal,Input,8,Right,F1.0,F1.0
111 VAR2,2,Nominal,Input,8,Right,F1.0,F1.0
112 VAR3,3,Nominal,Input,8,Right,F1.0,F1.0
113 VAR4,4,Nominal,Input,8,Right,F1.0,F1.0
114 VAR5,5,Nominal,Input,8,Right,F1.0,F1.0
115
116 Table: Value Labels
117 Variable Value,,Label
118 VAR1,1,one
119 VAR2,2,two
120 VAR3,3,three
121 VAR4,4,four
122 VAR5,5,five
123
124 Table: Data List
125 VAR1,VAR2,VAR3,VAR4,VAR5
126 1,2,3,4,5
127 ])
128 AT_DATA([sys-file-info.sps], [SYSFILE INFO FILE='data.por'
129 ])
130 AT_CHECK([pspp -O format=csv sys-file-info.sps | sed '/Encoding/d
131 /Integer Format/d
132 /Real Format/d
133 /Created/d
134 /Product/d
135 '], [0], [dnl
136 Table: File Information
137 File,data.por
138 Variables,5
139 Cases,Unknown
140 Type,SPSS Portable File
141 Weight,Not weighted
142 Compression,None
143
144 Table: Variables
145 Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
146 VAR1,1,Unknown,Input,8,Right,F1.0,F1.0
147 VAR2,2,Unknown,Input,8,Right,F1.0,F1.0
148 VAR3,3,Unknown,Input,8,Right,F1.0,F1.0
149 VAR4,4,Unknown,Input,8,Right,F1.0,F1.0
150 VAR5,5,Unknown,Input,8,Right,F1.0,F1.0
151
152 Table: Value Labels
153 Variable Value,,Label
154 VAR1,1,one
155 VAR2,2,two
156 VAR3,3,three
157 VAR4,4,four
158 VAR5,5,five
159 ])
160 AT_CLEANUP