52b9be62e4a0196f684d1a160756c91f1329144c
[pspp-builds.git] / tests / expressions / vectors.sh
1 #!/bin/sh
2
3 # This program tests use of vectors in expressions.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6
7 # ensure that top_srcdir and top_builddir  are absolute
8 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
9 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
10 top_srcdir=`cd $top_srcdir; pwd`
11 top_builddir=`cd $top_builddir; pwd`
12 PSPP=$top_builddir/src/ui/terminal/pspp
13
14 STAT_CONFIG_PATH=$top_srcdir/config
15 export STAT_CONFIG_PATH
16
17
18 cleanup()
19 {
20      cd /
21      rm -rf $TEMPDIR
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="create program"
53 cat > $TEMPDIR/vectors.stat <<EOF
54 DATA LIST /N1 TO N5 1-5.
55 MISSING VALUES N1 TO N5 (3 THRU 5, 1).
56 BEGIN DATA.
57 12345
58 6789 
59 END DATA.
60
61 VECTOR N=N1 TO N5.
62 VECTOR X(5).
63 LOOP I=1 TO 5.
64 COMPUTE X(I)=N(I) + 1.
65 END LOOP.
66
67 FORMATS ALL (F2).
68
69 LIST.
70 EOF
71 if [ $? -ne 0 ] ; then no_result ; fi
72
73 activity="run program"
74 $SUPERVISOR $PSPP -o raw-ascii $TEMPDIR/vectors.stat > $TEMPDIR/vectors.err 2> $TEMPDIR/vectors.out
75 if [ $? -ne 0 ] ; then fail ; fi
76
77 activity="compare results"
78 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
79 diff -b  $TEMPDIR/pspp.list - <<EOF
80 1.1 DATA LIST.  Reading 1 record from INLINE.
81 +--------+------+-------+------+
82 |Variable|Record|Columns|Format|
83 #========#======#=======#======#
84 |N1      |     1|  1-  1|F1.0  |
85 |N2      |     1|  2-  2|F1.0  |
86 |N3      |     1|  3-  3|F1.0  |
87 |N4      |     1|  4-  4|F1.0  |
88 |N5      |     1|  5-  5|F1.0  |
89 +--------+------+-------+------+
90 N1 N2 N3 N4 N5 X1 X2 X3 X4 X5  I
91 -- -- -- -- -- -- -- -- -- -- --
92  1  2  3  4  5  .  3  .  .  .  5 
93  6  7  8  9  .  7  8  9 10  .  5 
94 EOF
95
96 if [ $? -ne 0 ] ; then no_result ; fi
97
98
99 if [ $? -ne 0 ] ; then fail ; fi
100
101
102
103 pass;