Bug #21111. Reviewed by John Darrington.
[pspp-builds.git] / tests / command / input-program.sh
1 #!/bin/sh
2
3 # This program tests the INPUT PROGRAM command, specifically all of
4 # the examples given in the user manual.
5
6 TEMPDIR=/tmp/pspp-tst-$$
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 cleanup()
24 {
25      cd /
26      rm -rf $TEMPDIR
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="create a.data"
58 cat > a.data <<EOF
59 1
60 2
61 3
62 EOF
63 if [ $? -ne 0 ] ; then no_result ; fi
64
65 activity="create b.data"
66 cat > b.data <<EOF
67 4
68 5
69 6
70 7
71 8
72 EOF
73 if [ $? -ne 0 ] ; then no_result ; fi
74
75 activity="create test1.pspp"
76 cat > test1.pspp <<EOF
77 INPUT PROGRAM.
78         DATA LIST NOTABLE FILE='a.data'/X 1-10.
79         DATA LIST NOTABLE FILE='b.data'/Y 1-10.
80 END INPUT PROGRAM.
81 LIST.
82 EOF
83 if [ $? -ne 0 ] ; then no_result ; fi
84
85 activity="run test1"
86 $SUPERVISOR $PSPP --testing-mode test1.pspp
87 if [ $? -ne 0 ] ; then no_result ; fi
88
89 activity="compare test1 results"
90 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
91 diff -b  $TEMPDIR/pspp.list - << EOF
92          X          Y
93 ---------- ----------
94          1          4
95          2          5
96          3          6
97 EOF
98 if [ $? -ne 0 ] ; then fail ; fi
99
100 activity="create test2.pspp"
101 cat > test2.pspp <<EOF
102 INPUT PROGRAM.
103         NUMERIC #A #B.
104
105         DO IF NOT #A.
106                 DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10.
107         END IF.
108         DO IF NOT #B.
109                 DATA LIST NOTABLE END=#B FILE='b.data'/Y 1-10.
110         END IF.
111         DO IF #A AND #B.
112                 END FILE.
113         END IF.
114         END CASE.
115 END INPUT PROGRAM.
116 LIST.
117 EOF
118 if [ $? -ne 0 ] ; then no_result ; fi
119
120 activity="run test2"
121 $SUPERVISOR $PSPP --testing-mode test2.pspp
122 if [ $? -ne 0 ] ; then no_result ; fi
123
124 activity="compare test2 results"
125 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
126 diff -b  $TEMPDIR/pspp.list - << EOF
127          X          Y
128 ---------- ----------
129          1          4
130          2          5
131          3          6
132          .          7
133          .          8
134 EOF
135 if [ $? -ne 0 ] ; then fail ; fi
136
137 activity="create test3.pspp"
138 cat > test3.pspp <<EOF
139 INPUT PROGRAM.
140         NUMERIC #A #B.
141
142         DO IF #A.
143                 DATA LIST NOTABLE END=#B FILE='b.data'/X 1-10.
144                 DO IF #B.
145                         END FILE.
146                 ELSE.
147                         END CASE.
148                 END IF.
149         ELSE.
150                 DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10.
151                 DO IF NOT #A.
152                         END CASE.
153                 END IF.
154         END IF.
155 END INPUT PROGRAM.
156 LIST.
157 EOF
158 if [ $? -ne 0 ] ; then no_result ; fi
159
160 activity="run test3"
161 $SUPERVISOR $PSPP --testing-mode test3.pspp
162 if [ $? -ne 0 ] ; then no_result ; fi
163
164 activity="compare test3 results"
165 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
166 diff -b  $TEMPDIR/pspp.list - << EOF
167          X
168 ----------
169          1
170          2
171          3
172          4
173          5
174          6
175          7
176          8
177 EOF
178 if [ $? -ne 0 ] ; then fail ; fi
179
180 activity="create test4.pspp"
181 cat > test4.pspp <<EOF
182 INPUT PROGRAM.
183         NUMERIC #EOF.
184
185         LOOP IF NOT #EOF.
186                 DATA LIST NOTABLE END=#EOF FILE='a.data'/X 1-10.
187                 DO IF NOT #EOF.
188                         END CASE.
189                 END IF.
190         END LOOP.
191
192         COMPUTE #EOF = 0.
193         LOOP IF NOT #EOF.
194                 DATA LIST NOTABLE END=#EOF FILE='b.data'/X 1-10.
195                 DO IF NOT #EOF.
196                         END CASE.
197                 END IF.
198         END LOOP.
199
200         END FILE.
201 END INPUT PROGRAM.
202 LIST.
203 EOF
204 if [ $? -ne 0 ] ; then no_result ; fi
205
206 activity="run test4"
207 $SUPERVISOR $PSPP --testing-mode test4.pspp
208 if [ $? -ne 0 ] ; then no_result ; fi
209
210 activity="compare test4 results"
211 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
212 diff -b  $TEMPDIR/pspp.list - << EOF
213          X
214 ----------
215          1
216          2
217          3
218          4
219          5
220          6
221          7
222          8
223 EOF
224 if [ $? -ne 0 ] ; then fail ; fi
225
226 # This example differs slightly from the one in the manual in that
227 # it doesn't generate random variates.  There's already a test that
228 # checks that random variates are predictable, so we don't need
229 # another.
230 activity="create test5.pspp"
231 cat > test5.pspp <<EOF
232 INPUT PROGRAM.
233         LOOP #I=1 TO 50.
234                 COMPUTE X=#I * 3.
235                 END CASE.
236         END LOOP.
237         END FILE.
238 END INPUT PROGRAM.
239 LIST/FORMAT=NUMBERED.
240 EOF
241 if [ $? -ne 0 ] ; then no_result ; fi
242
243 activity="run test5"
244 $SUPERVISOR $PSPP --testing-mode test5.pspp
245 if [ $? -ne 0 ] ; then no_result ; fi
246
247 activity="compare test5 results"
248 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
249 diff -b  $TEMPDIR/pspp.list - << EOF
250 Case#        X
251 ----- --------
252     1     3.00
253     2     6.00
254     3     9.00
255     4    12.00
256     5    15.00
257     6    18.00
258     7    21.00
259     8    24.00
260     9    27.00
261    10    30.00
262    11    33.00
263    12    36.00
264    13    39.00
265    14    42.00
266    15    45.00
267    16    48.00
268    17    51.00
269    18    54.00
270    19    57.00
271    20    60.00
272    21    63.00
273    22    66.00
274    23    69.00
275    24    72.00
276    25    75.00
277    26    78.00
278    27    81.00
279    28    84.00
280    29    87.00
281    30    90.00
282    31    93.00
283    32    96.00
284    33    99.00
285    34   102.00
286    35   105.00
287    36   108.00
288    37   111.00
289    38   114.00
290    39   117.00
291    40   120.00
292    41   123.00
293    42   126.00
294    43   129.00
295    44   132.00
296    45   135.00
297    46   138.00
298    47   141.00
299    48   144.00
300    49   147.00
301    50   150.00
302 EOF
303 if [ $? -ne 0 ] ; then fail ; fi
304
305
306 pass