Rewrite PSPP output engine.
[pspp-builds.git] / tests / command / loop.sh
1 #!/bin/sh
2
3 # This program tests the LOOP command
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_builddir  are absolute
9 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
10 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
11 top_builddir=`cd $top_builddir; pwd`
12 PSPP=$top_builddir/src/ui/terminal/pspp
13
14 # ensure that top_srcdir is absolute
15 top_srcdir=`cd $top_srcdir; pwd`
16
17 STAT_CONFIG_PATH=$top_srcdir/config
18 export STAT_CONFIG_PATH
19
20 LANG=C
21 export LANG
22
23
24 cleanup()
25 {
26      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
27         echo "NOT cleaning $TEMPDIR" 
28         return ; 
29      fi
30      cd /
31      rm -rf $TEMPDIR
32 }
33
34
35 fail()
36 {
37     echo $activity
38     echo FAILED
39     cleanup;
40     exit 1;
41 }
42
43
44 no_result()
45 {
46     echo $activity
47     echo NO RESULT;
48     cleanup;
49     exit 2;
50 }
51
52 pass()
53 {
54     cleanup;
55     exit 0;
56 }
57
58 mkdir -p $TEMPDIR
59
60 cd $TEMPDIR
61
62 activity="create prog"
63 cat > $TEMPDIR/loop.stat <<EOF
64 data list notable /x 1 y 2 z 3.
65 begin data.
66 121
67 252
68 393
69 404
70 end data.
71
72 echo 'Loop with index'.
73 loop #i=x to y by z.
74 print /#i.
75 end loop.
76 print/'--------'.
77 execute.
78
79 echo 'Loop with IF condition'.
80 compute #j=x.
81 loop if #j <= y.
82 print /#j.
83 compute #j = #j + z.
84 end loop.
85 print/'--------'.
86 execute.
87
88 echo 'Loop with END IF condition'.
89 compute #k=x.
90 loop.
91 print /#k.
92 compute #k = #k + z.
93 end loop if #k > y.
94 print/'--------'.
95 execute.
96
97 echo 'Loop with index and IF condition based on index'.
98 loop #m=x to y by z if #m < 4.
99 print /#m.
100 end loop.
101 print/'--------'.
102 execute.
103
104 echo 'Loop with index and END IF condition based on index'.
105 loop #n=x to y by z.
106 print /#n.
107 end loop if #n >= 4.
108 print/'--------'.
109 execute.
110
111 echo 'Loop with index and IF and END IF condition based on index'.
112 loop #o=x to y by z if mod(#o,2) = 0.
113 print /#o.
114 end loop if #o >= 4.
115 print/'--------'.
116 execute.
117
118 echo 'Loop with no conditions'.
119 set mxloops = 2.
120 compute #p = x.
121 loop.
122 print /#p.
123 compute #p = #p + z.
124 do if #p >= y.
125 break.
126 end if.
127 end loop.
128 print/'--------'.
129 execute.
130 EOF
131 if [ $? -ne 0 ] ; then no_result ; fi
132
133 activity="run program"
134 $SUPERVISOR $PSPP --testing-mode -e $TEMPDIR/stdout $TEMPDIR/loop.stat 
135 if [ $? -ne 0 ] ; then no_result ; fi
136
137 activity="compare stdout"
138 perl -pi -e 's/^\s*$//g' $TEMPDIR/stdout
139 diff -b $TEMPDIR/stdout  - <<EOF
140 EOF
141 if [ $? -ne 0 ] ; then fail ; fi
142
143 activity="compare results"
144 diff -c $TEMPDIR/pspp.csv  - <<EOF
145 Loop with index
146
147 1.00 
148
149 2.00 
150
151 --------
152
153 2.00 
154
155 4.00 
156
157 --------
158
159 3.00 
160
161 6.00 
162
163 9.00 
164
165 --------
166
167 --------
168
169 Loop with IF condition
170
171 1.00 
172
173 2.00 
174
175 --------
176
177 2.00 
178
179 4.00 
180
181 --------
182
183 3.00 
184
185 6.00 
186
187 9.00 
188
189 --------
190
191 --------
192
193 Loop with END IF condition
194
195 1.00 
196
197 2.00 
198
199 --------
200
201 2.00 
202
203 4.00 
204
205 --------
206
207 3.00 
208
209 6.00 
210
211 9.00 
212
213 --------
214
215 4.00 
216
217 --------
218
219 Loop with index and IF condition based on index
220
221 1.00 
222
223 2.00 
224
225 --------
226
227 2.00 
228
229 --------
230
231 3.00 
232
233 --------
234
235 --------
236
237 Loop with index and END IF condition based on index
238
239 1.00 
240
241 2.00 
242
243 --------
244
245 2.00 
246
247 4.00 
248
249 --------
250
251 3.00 
252
253 6.00 
254
255 --------
256
257 --------
258
259 Loop with index and IF and END IF condition based on index
260
261 --------
262
263 2.00 
264
265 4.00 
266
267 --------
268
269 --------
270
271 --------
272
273 Loop with no conditions
274
275 1.00 
276
277 --------
278
279 2.00 
280
281 4.00 
282
283 --------
284
285 3.00 
286
287 6.00 
288
289 --------
290
291 4.00 
292
293 --------
294 EOF
295 if [ $? -ne 0 ] ; then fail ; fi
296
297
298 pass;