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