Rewrite PSPP output engine.
[pspp-builds.git] / tests / command / match-files.sh
1 #!/bin/sh
2
3 # This program tests the MATCH FILES procedure
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/match-files.pspp
7
8
9 # ensure that top_builddir  are absolute
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
12 top_builddir=`cd $top_builddir; pwd`
13 PSPP=$top_builddir/src/ui/terminal/pspp
14
15 # ensure that top_srcdir is absolute
16 top_srcdir=`cd $top_srcdir; pwd`
17
18
19 STAT_CONFIG_PATH=$top_srcdir/config
20 export STAT_CONFIG_PATH
21
22 cleanup()
23 {
24      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
25         echo "NOT cleaning $TEMPDIR" 
26         return ; 
27      fi
28     cd /
29     rm -rf $TEMPDIR
30 }
31
32
33 fail()
34 {
35     echo $activity
36     echo FAILED
37     cleanup;
38     exit 1;
39 }
40
41
42 no_result()
43 {
44     echo $activity
45     echo NO RESULT;
46     cleanup;
47     exit 2;
48 }
49
50 pass()
51 {
52     cleanup;
53     exit 0;
54 }
55
56 mkdir -p $TEMPDIR
57
58 cd $TEMPDIR
59
60 activity="data create"
61 cat > a.data <<EOF
62 1aB
63 8aM
64 3aE
65 5aG
66 0aA
67 5aH
68 6aI
69 7aJ
70 2aD
71 7aK
72 1aC
73 7aL
74 4aF
75 EOF
76 if [ $? -ne 0 ] ; then no_result ; fi
77 cat > b.data <<EOF
78 1bN
79 3bO
80 4bP
81 6bQ
82 7bR
83 9bS
84 EOF
85 if [ $? -ne 0 ] ; then no_result ; fi
86
87 cat > ff.out <<EOF
88 Table: Data List
89 A,B,C,D,INA,INB,FIRST,LAST
90 0,a,A,,1,0,1,1
91 1,a,B,N,1,1,1,0
92 1,a,C,,1,0,0,1
93 2,a,D,,1,0,1,1
94 3,a,E,O,1,1,1,1
95 4,a,F,P,1,1,1,1
96 5,a,G,,1,0,1,0
97 5,a,H,,1,0,0,1
98 6,a,I,Q,1,1,1,1
99 7,a,J,R,1,1,1,0
100 7,a,K,,1,0,0,0
101 7,a,L,,1,0,0,1
102 8,a,M,,1,0,1,1
103 9,b,,S,0,1,1,1
104 EOF
105
106 cat > ft.out <<EOF
107 Table: Data List
108 A,B,C,D,INA,INB,FIRST,LAST
109 0,a,A,,1,0,1,1
110 1,a,B,N,1,1,1,0
111 1,a,C,N,1,1,0,1
112 2,a,D,,1,0,1,1
113 3,a,E,O,1,1,1,1
114 4,a,F,P,1,1,1,1
115 5,a,G,,1,0,1,0
116 5,a,H,,1,0,0,1
117 6,a,I,Q,1,1,1,1
118 7,a,J,R,1,1,1,0
119 7,a,K,R,1,1,0,0
120 7,a,L,R,1,1,0,1
121 8,a,M,,1,0,1,1
122 EOF
123
124 # Test nonparallel match and table lookup.
125 dla="data list notable file='a.data' /A B C 1-3 (a)."
126 sa="save outfile='a.sys'."
127 dlb="data list notable file='b.data' /A B C 1-3 (a)."
128 sb="save outfile='b.sys'."
129 for types in ff ft; do
130     type1=file
131     if [ $types = ff ]; then 
132         type2=file
133     else
134         type2=table
135     fi
136     for sources in ss sa as; do
137         name="$types-$sources"
138         activity="create $name.pspp"
139         {
140             if [ $sources = ss ]; then
141                 cat <<EOF
142 $dla
143 $sa
144 $dlb
145 $sb
146 match files $type1='a.sys' /in=INA /sort
147            /$type2='b.sys' /in=INB /rename c=D
148            /by a /first=FIRST /last=LAST.
149 EOF
150             elif [ $sources = sa ]; then
151                 cat <<EOF
152 $dla
153 $sa
154 $dlb
155 match files $type1='a.sys' /in=INA /sort
156            /$type2=* /in=INB /rename c=D
157            /by a /first=FIRST /last=LAST.
158 EOF
159             elif [ $sources = as ]; then
160                 cat <<EOF
161 $dlb
162 $sb
163 $dla
164 match files $type1=* /in=INA /sort
165            /$type2='b.sys' /in=INB /rename c=D
166            /by a /first=FIRST /last=LAST.
167 EOF
168             else
169                 activity="internal error"
170                 no_result
171             fi
172             echo 'list.'
173         } > $name.pspp
174         if [ $? -ne 0 ] ; then no_result ; fi
175
176         activity="run $name.pspp"
177         $SUPERVISOR $PSPP --testing-mode -e /dev/null $name.pspp 
178         if [ $? -ne 0 ] ; then no_result ; fi
179
180         activity="check $name output"
181         diff -c pspp.csv $types.out
182         if [ $? -ne 0 ] ; then fail ; fi
183     done
184 done
185
186 # Test parallel match.  
187 name="parallel"
188 activity="create $name.pspp"
189 cat > $name.pspp <<EOF
190 $dla
191 $sa
192 $dlb
193 $sb
194 match files file='a.sys' /file='b.sys' /rename (a b c=D E F).
195 list.
196 EOF
197 if [ $? -ne 0 ] ; then no_result ; fi
198
199 activity="run $name.pspp"
200 $SUPERVISOR $PSPP --testing-mode -e /dev/null $name.pspp 
201 if [ $? -ne 0 ] ; then no_result ; fi
202
203 activity="check $name output"
204 diff -c - pspp.csv <<EOF
205 Table: Data List
206 A,B,C,D,E,F
207 1,a,B,1,b,N
208 8,a,M,3,b,O
209 3,a,E,4,b,P
210 5,a,G,6,b,Q
211 0,a,A,7,b,R
212 5,a,H,9,b,S
213 6,a,I,,,
214 7,a,J,,,
215 2,a,D,,,
216 7,a,K,,,
217 1,a,C,,,
218 7,a,L,,,
219 4,a,F,,,
220 EOF
221 if [ $? -ne 0 ] ; then fail ; fi
222
223 # Test bug handling TABLE from active file found by John Darrington.
224 name="active-table"
225 activity="create $name.pspp"
226 cat > $name.pspp <<EOF
227 DATA LIST LIST NOTABLE /x * y *.
228 BEGIN DATA
229 3 30
230 2 21
231 1 22
232 END DATA.
233
234 SAVE OUTFILE='bar.sav'.
235
236 DATA LIST LIST NOTABLE /x * z *.
237 BEGIN DATA
238 3 8
239 2 9
240 END DATA.
241
242 MATCH FILES TABLE=* /FILE='bar.sav' /BY=x.
243 LIST.
244 EOF
245 if [ $? -ne 0 ] ; then no_result ; fi
246
247 activity="run $name.pspp"
248 $SUPERVISOR $PSPP --testing-mode -e /dev/null $name.pspp 
249 if [ $? -ne 0 ] ; then no_result ; fi
250
251 activity="check $name output"
252 diff -c - pspp.csv <<EOF
253 Table: Data List
254 x,z,y
255 3.00,8.00,30.00
256 2.00,.  ,21.00
257 1.00,.  ,22.00
258 EOF
259 if [ $? -ne 0 ] ; then fail ; fi
260
261
262 pass;