7aa0dbb909850c8fe13d9e392d9b1f58968063b5
[pspp-builds.git] / tests / command / compute.sh
1 #!/bin/sh
2
3 # This program tests the COMPUTE command
4 # (it also gives LPAD and RPAD a work out)
5
6 TEMPDIR=/tmp/pspp-tst-$$
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 program"
50 cat > $TEMPDIR/compute.stat <<EOF
51 data list /w 1-3(a).
52 begin data.
53 123
54 456
55 919
56 572
57 end data.
58
59 string z(a6).
60 compute x=number(w).
61 compute y=number(w,f8).
62 compute z=lpad(
63         rpad(
64                 substr(string(x,f6),4,1),
65                 3,'@'),
66         6,'*').
67 compute y=y+1e-10.
68 list.
69 EOF
70 if [ $? -ne 0 ] ; then no_result ; fi
71
72
73 activity="run program"
74 $SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii $TEMPDIR/compute.stat
75 if [ $? -ne 0 ] ; then no_result ; fi
76
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 |W       |     1|  1-  3|A3    |
83 +--------+------+-------+------+
84
85   W      Z        X        Y
86 --- ------ -------- --------
87 123 ***1@@   123.00   123.00 
88 456 ***4@@   456.00   456.00 
89 919 ***9@@   919.00   919.00 
90 572 ***5@@   572.00   572.00 
91
92 EOF
93 if [ $? -ne 0 ] ; then fail ; fi
94
95
96 pass;