d8f930c8b51d7e3eb36ad2527a596896fa73052b
[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      cd /
27      rm -rf $TEMPDIR
28 }
29
30
31 fail()
32 {
33     echo $activity
34     echo FAILED
35     cleanup;
36     exit 1;
37 }
38
39
40 no_result()
41 {
42     echo $activity
43     echo NO RESULT;
44     cleanup;
45     exit 2;
46 }
47
48 pass()
49 {
50     cleanup;
51     exit 0;
52 }
53
54 mkdir -p $TEMPDIR
55
56 cd $TEMPDIR
57
58 activity="create prog"
59 cat > $TEMPDIR/loop.stat <<EOF
60 data list notable /x 1 y 2 z 3.
61 begin data.
62 121
63 252
64 393
65 404
66 end data.
67
68 echo 'Loop with index'.
69 loop #i=x to y by z.
70 print /#i.
71 end loop.
72 print/'--------'.
73 execute.
74
75 echo 'Loop with IF condition'.
76 compute #j=x.
77 loop if #j <= y.
78 print /#j.
79 compute #j = #j + z.
80 end loop.
81 print/'--------'.
82 execute.
83
84 echo 'Loop with END IF condition'.
85 compute #k=x.
86 loop.
87 print /#k.
88 compute #k = #k + z.
89 end loop if #k > y.
90 print/'--------'.
91 execute.
92
93 echo 'Loop with index and IF condition based on index'.
94 loop #m=x to y by z if #m < 4.
95 print /#m.
96 end loop.
97 print/'--------'.
98 execute.
99
100 echo 'Loop with index and END IF condition based on index'.
101 loop #n=x to y by z.
102 print /#n.
103 end loop if #n >= 4.
104 print/'--------'.
105 execute.
106
107 echo 'Loop with index and IF and END IF condition based on index'.
108 loop #o=x to y by z if mod(#o,2) = 0.
109 print /#o.
110 end loop if #o >= 4.
111 print/'--------'.
112 execute.
113
114 echo 'Loop with no conditions'.
115 set mxloops = 2.
116 compute #p = x.
117 loop.
118 print /#p.
119 compute #p = #p + z.
120 do if #p >= y.
121 break.
122 end if.
123 end loop.
124 print/'--------'.
125 execute.
126 EOF
127 if [ $? -ne 0 ] ; then no_result ; fi
128
129 activity="run program"
130 $SUPERVISOR $PSPP --testing-mode -e $TEMPDIR/stdout $TEMPDIR/loop.stat 
131 if [ $? -ne 0 ] ; then no_result ; fi
132
133 activity="compare stdout"
134 perl -pi -e 's/^\s*$//g' $TEMPDIR/stdout
135 diff -b $TEMPDIR/stdout  - <<EOF
136 EOF
137 if [ $? -ne 0 ] ; then fail ; fi
138
139 activity="compare results"
140 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
141 diff  -b $TEMPDIR/pspp.list  - <<EOF
142 Loop with index
143     1.00 
144     2.00 
145 --------
146     2.00 
147     4.00 
148 --------
149     3.00 
150     6.00 
151     9.00 
152 --------
153 --------
154 Loop with IF condition
155     1.00 
156     2.00 
157 --------
158     2.00 
159     4.00 
160 --------
161     3.00 
162     6.00 
163     9.00 
164 --------
165 --------
166 Loop with END IF condition
167     1.00 
168     2.00 
169 --------
170     2.00 
171     4.00 
172 --------
173     3.00 
174     6.00 
175     9.00 
176 --------
177     4.00 
178 --------
179 Loop with index and IF condition based on index
180     1.00 
181     2.00 
182 --------
183     2.00 
184 --------
185     3.00 
186 --------
187 --------
188 Loop with index and END IF condition based on index
189     1.00 
190     2.00 
191 --------
192     2.00 
193     4.00 
194 --------
195     3.00 
196     6.00 
197 --------
198 --------
199 Loop with index and IF and END IF condition based on index
200 --------
201     2.00 
202     4.00 
203 --------
204 --------
205 --------
206 Loop with no conditions
207     1.00 
208 --------
209     2.00 
210     4.00 
211 --------
212     3.00 
213     6.00 
214 --------
215     4.00 
216 --------
217 EOF
218 if [ $? -ne 0 ] ; then fail ; fi
219
220
221 pass;