Fix cleanup of ROC command.
[pspp-builds.git] / tests / command / lag.sh
1 #!/bin/sh
2
3 # This program tests the LAG function
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 cleanup()
24 {
25      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
26         echo "NOT cleaning $TEMPDIR" 
27         return ; 
28      fi
29      cd /
30      rm -rf $TEMPDIR
31 }
32
33
34 fail()
35 {
36     echo $activity
37     echo FAILED
38     cleanup;
39     exit 1;
40 }
41
42
43 no_result()
44 {
45     echo $activity
46     echo NO RESULT;
47     cleanup;
48     exit 2;
49 }
50
51 pass()
52 {
53     cleanup;
54     exit 0;
55 }
56
57 mkdir -p $TEMPDIR
58
59 cd $TEMPDIR
60
61 activity="create program"
62 cat > $TEMPDIR/lag.stat <<EOF
63 data list /W 1.
64 begin data.
65 1
66 2
67 3
68 4
69 5
70 end data.
71
72 compute X=lag(w,1).
73 compute Y=lag(x).
74 compute Z=lag(w,2).
75 list.
76 EOF
77 if [ $? -ne 0 ] ; then no_result ; fi
78
79 activity="run program"
80 $SUPERVISOR $PSPP --testing-mode $TEMPDIR/lag.stat
81 if [ $? -ne 0 ] ; then no_result ; fi
82
83 activity="compare result"
84 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
85 diff -b  $TEMPDIR/pspp.list - <<EOF
86 1.1 DATA LIST.  Reading 1 record from INLINE.
87 +--------+------+-------+------+
88 |Variable|Record|Columns|Format|
89 #========#======#=======#======#
90 |W       |     1|  1-  1|F1.0  |
91 +--------+------+-------+------+
92 W        X        Y        Z
93 - -------- -------- --------
94 1      .        .        .   
95 2     1.00      .        .   
96 3     2.00     1.00     1.00 
97 4     3.00     2.00     2.00 
98 5     4.00     3.00     3.00 
99 EOF
100 if [ $? -ne 0 ] ; then fail ; fi
101
102
103 pass;