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