Improve VECTOR implementation.
[pspp-builds.git] / tests / command / vector.sh
1 #!/bin/sh
2
3 # This program tests the VECTOR 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/vector.stat <<EOF
60 data list notable/x 1.
61 vector v(4).
62 display vector.
63
64 data list notable/x 1.
65 vector #vec(4, comma10.2).
66 display vector.
67
68 input program.
69 vector x(5).
70 data list/x5 x2 x3 x1 x4 1-5.
71 end input program.
72 display vector.
73
74 data list notable/u w x y z 1-5.
75 vector a=u to y.
76 vector b=x to z.
77 vector c=all.
78 display vector.
79 EOF
80 if [ $? -ne 0 ] ; then no_result ; fi
81
82 activity="run program"
83 $SUPERVISOR $PSPP --testing-mode -o raw-ascii -e $TEMPDIR/stdout $TEMPDIR/vector.stat
84 if [ $? -ne 0 ] ; then no_result ; fi
85
86 activity="compare stdout"
87 perl -pi -e 's/^\s*$//g' $TEMPDIR/stdout
88 diff -b $TEMPDIR/stdout  - <<EOF
89 EOF
90 if [ $? -ne 0 ] ; then fail ; fi
91
92 activity="compare results"
93 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
94 diff  -b $TEMPDIR/pspp.list  - <<EOF
95 +------+--------+--------+------------+
96 |Vector|Position|Variable|Print Format|
97 #======#========#========#============#
98 |v     |       1|v1      |F8.2        |
99 |      |       2|v2      |F8.2        |
100 |      |       3|v3      |F8.2        |
101 |      |       4|v4      |F8.2        |
102 +------+--------+--------+------------+
103 +------+--------+--------+------------+
104 |Vector|Position|Variable|Print Format|
105 #======#========#========#============#
106 |#vec  |       1|#vec1   |COMMA10.2   |
107 |      |       2|#vec2   |COMMA10.2   |
108 |      |       3|#vec3   |COMMA10.2   |
109 |      |       4|#vec4   |COMMA10.2   |
110 +------+--------+--------+------------+
111 1.1 DATA LIST.  Reading 1 record from INLINE.
112 +--------+------+-------+------+
113 |Variable|Record|Columns|Format|
114 #========#======#=======#======#
115 |x5      |     1|  1-  1|F1.0  |
116 |x2      |     1|  2-  2|F1.0  |
117 |x3      |     1|  3-  3|F1.0  |
118 |x1      |     1|  4-  4|F1.0  |
119 |x4      |     1|  5-  5|F1.0  |
120 +--------+------+-------+------+
121 +------+--------+--------+------------+
122 |Vector|Position|Variable|Print Format|
123 #======#========#========#============#
124 |x     |       1|x1      |F8.2        |
125 |      |       2|x2      |F8.2        |
126 |      |       3|x3      |F8.2        |
127 |      |       4|x4      |F8.2        |
128 |      |       5|x5      |F8.2        |
129 +------+--------+--------+------------+
130 +------+--------+--------+------------+
131 |Vector|Position|Variable|Print Format|
132 #======#========#========#============#
133 |a     |       1|u       |F1.0        |
134 |      |       2|w       |F1.0        |
135 |      |       3|x       |F1.0        |
136 |      |       4|y       |F1.0        |
137 +------+--------+--------+------------+
138 |b     |       1|x       |F1.0        |
139 |      |       2|y       |F1.0        |
140 |      |       3|z       |F1.0        |
141 +------+--------+--------+------------+
142 |c     |       1|u       |F1.0        |
143 |      |       2|w       |F1.0        |
144 |      |       3|x       |F1.0        |
145 |      |       4|y       |F1.0        |
146 |      |       5|z       |F1.0        |
147 +------+--------+--------+------------+
148 EOF
149 if [ $? -ne 0 ] ; then fail ; fi
150
151
152 pass;