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