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