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