Merge commit 'origin/stable'
[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 A B C D INA INB FIRST LAST
89 - - - - --- --- ----- ----
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 A B C D INA INB FIRST LAST
108 - - - - --- --- ----- ----
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         perl -pi -e 's/^\s*$//g' pspp.list
182         perl -pi -e 's/^\s*$//g' $types.out
183         diff -b -w pspp.list $types.out
184         if [ $? -ne 0 ] ; then fail ; fi
185     done
186 done
187
188 # Test parallel match.  
189 name="parallel"
190 activity="create $name.pspp"
191 cat > $name.pspp <<EOF
192 $dla
193 $sa
194 $dlb
195 $sb
196 match files file='a.sys' /file='b.sys' /rename (a b c=D E F).
197 list.
198 EOF
199 if [ $? -ne 0 ] ; then no_result ; fi
200
201 activity="run $name.pspp"
202 $SUPERVISOR $PSPP --testing-mode -e /dev/null $name.pspp 
203 if [ $? -ne 0 ] ; then no_result ; fi
204
205 activity="check $name output"
206 perl -pi -e 's/^\s*$//g' pspp.list
207 diff -b -w - pspp.list <<EOF
208 A B C D E F
209 - - - - - -
210 1 a B 1 b N
211 8 a M 3 b O
212 3 a E 4 b P
213 5 a G 6 b Q
214 0 a A 7 b R
215 5 a H 9 b S
216 6 a I
217 7 a J
218 2 a D
219 7 a K
220 1 a C
221 7 a L
222 4 a F
223 EOF
224 if [ $? -ne 0 ] ; then fail ; fi
225
226 # Test bug handling TABLE from active file found by John Darrington.
227 name="active-table"
228 activity="create $name.pspp"
229 cat > $name.pspp <<EOF
230 DATA LIST LIST NOTABLE /x * y *.
231 BEGIN DATA
232 3 30
233 2 21
234 1 22
235 END DATA.
236
237 SAVE OUTFILE='bar.sav'.
238
239 DATA LIST LIST NOTABLE /x * z *.
240 BEGIN DATA
241 3 8
242 2 9
243 END DATA.
244
245 MATCH FILES TABLE=* /FILE='bar.sav' /BY=x.
246 LIST.
247 EOF
248 if [ $? -ne 0 ] ; then no_result ; fi
249
250 activity="run $name.pspp"
251 $SUPERVISOR $PSPP --testing-mode -e /dev/null $name.pspp 
252 if [ $? -ne 0 ] ; then no_result ; fi
253
254 activity="check $name output"
255 perl -pi -e 's/^\s*$//g' pspp.list
256 diff -b -w - pspp.list <<EOF | perl -e 's/^\s*$//g'
257         x        z        y
258  -------- -------- --------
259      3.00     8.00    30.00 
260      2.00      .      21.00 
261      1.00      .      22.00 
262 EOF
263 if [ $? -ne 0 ] ; then fail ; fi
264
265
266 pass;