3fc5978874d7ed3fc6afffd6c07e8432f20bb204
[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 here=`pwd`;
9
10 # ensure that top_srcdir is absolute
11 cd $top_srcdir; top_srcdir=`pwd`
12
13 export STAT_CONFIG_PATH=$top_srcdir/config
14
15
16 cleanup()
17 {
18      rm -rf $TEMPDIR
19 }
20
21
22 fail()
23 {
24     echo $activity
25     echo FAILED
26     cleanup;
27     exit 1;
28 }
29
30
31 no_result()
32 {
33     echo $activity
34     echo NO RESULT;
35     cleanup;
36     exit 2;
37 }
38
39 pass()
40 {
41     cleanup;
42     exit 0;
43 }
44
45 mkdir -p $TEMPDIR
46
47 cd $TEMPDIR
48
49 activity="create prog"
50 cat > $TEMPDIR/loop.stat <<EOF
51 data list /x 1 y 2 z 3.
52 begin data.
53 125
54 256
55 397
56 401
57 end data.
58 loop i=y to z by abs(z-y)/(z-y).
59 print /x i.
60 break.          /* Generates warning.
61 end loop.
62 execute.
63 EOF
64 if [ $? -ne 0 ] ; then no_result ; fi
65
66 activity="run program"
67 $SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii $TEMPDIR/loop.stat > $TEMPDIR/stdout
68 if [ $? -ne 0 ] ; then no_result ; fi
69
70 activity="compare stdout"
71 diff -B -b $TEMPDIR/stdout  - <<EOF
72 $TEMPDIR/loop.stat:10: warning: BREAK: BREAK not enclosed in DO IF structure.
73 EOF
74 if [ $? -ne 0 ] ; then fail ; fi
75
76 activity="compare results"
77 diff -B -b $TEMPDIR/pspp.list  - <<EOF
78 1.1 DATA LIST.  Reading 1 record from the command file.
79 +--------+------+-------+------+
80 |Variable|Record|Columns|Format|
81 #========#======#=======#======#
82 |X       |     1|  1-  1|F1.0  |
83 |Y       |     1|  2-  2|F1.0  |
84 |Z       |     1|  3-  3|F1.0  |
85 +--------+------+-------+------+
86 1     2.00 
87 2     5.00 
88 3     9.00 
89 4      .00 
90 EOF
91 if [ $? -ne 0 ] ; then fail ; fi
92
93
94 pass;