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