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