Fixed some buglets in the tests
[pspp-builds.git] / tests / command / sample.sh
1 #!/bin/sh
2
3 # This program tests the SAMPLE function
4
5 TEMPDIR=/tmp/pspp-tst-$$
6
7 here=`pwd`;
8
9 # ensure that top_srcdir is absolute
10 cd $top_srcdir; top_srcdir=`pwd`
11
12 export STAT_CONFIG_PATH=$top_srcdir/config
13
14
15 cleanup()
16 {
17      rm -rf $TEMPDIR
18 }
19
20
21 fail()
22 {
23     echo $activity
24     echo FAILED
25     cleanup;
26     exit 1;
27 }
28
29
30 no_result()
31 {
32     echo $activity
33     echo NO RESULT;
34     cleanup;
35     exit 2;
36 }
37
38 pass()
39 {
40     cleanup;
41     exit 0;
42 }
43
44 mkdir -p $TEMPDIR
45
46 cd $TEMPDIR
47
48
49 activity="create program"
50 cat > $TEMPDIR/sample.stat <<EOF
51 set seed=3
52
53 data list notable /a 1-2.
54 begin data.
55 1
56 2
57 3
58 4
59 5
60 6
61 7
62 8
63 9
64 10
65 end data.
66 sample .5.
67 list.
68 EOF
69 if [ $? -ne 0 ] ; then no_result ; fi
70
71
72 activity="run program"
73 $here/../src/pspp -o raw-ascii --testing-mode $TEMPDIR/sample.stat 
74 if [ $? -ne 0 ] ; then no_result ; fi
75
76 activity="create head"
77 grep -v '^\ *$' $TEMPDIR/pspp.list | head -2 > $TEMPDIR/head
78 if [ $? -ne 0 ] ; then no_result ; fi
79
80 activity="extract data"
81 grep  '[0-9][0-9]*' $TEMPDIR/pspp.list > $TEMPDIR/data
82 if [ $? -ne 0 ] ; then no_result ; fi
83
84
85 activity="compare head"
86 diff -B -b $TEMPDIR/head - << EOF
87  A
88 --
89 EOF
90 if [ $? -ne 0 ] ; then fail ; fi
91
92 activity="compare data"
93 diff -w $TEMPDIR/data - << EOF > $TEMPDIR/diffs
94 1
95 2
96 3
97 4
98 5
99 6
100 7
101 8
102 9
103 10
104 EOF
105 # note   vv 
106 if [ $? -eq 0 ] ; then fail ; fi
107
108 # Check that there was nothing added
109 grep '^<' $TEMPDIR/diffs
110 # note   vv
111 if [ $? -eq 0 ] ; then fail ; fi
112
113
114 pass;