Beginning of VFM cleanup.
[pspp-builds.git] / tests / command / sort.sh
1 #!/bin/sh
2
3 # This program tests the sort command
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="generate stat program"
50 cat > $TEMPDIR/sort.stat <<EOF
51 title 'Test SORT procedure'.
52
53 data list file='$here/sort.data' notable /X000 to X126 1-127.
54 sort by X000 to x005.
55 print /X000 to X005.
56 execute.
57 EOF
58 if [ $? -ne 0 ] ; then no_result ; fi
59
60 activity="run program"
61 $SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/sort.stat
62 if [ $? -ne 0 ] ; then no_result ; fi
63
64 # Now there should be some sorted data in $TEMPDIR/pspp.list
65 # We have to do some checks on it.
66
67 # 1. Is it sorted ?
68
69 activity="check sorted"
70 sort $TEMPDIR/pspp.list  > $TEMPDIR/sortsort
71 cp $TEMPDIR/pspp.list ~/pspp.list
72 if [ $? -ne 0 ] ; then no_result ; fi
73
74 diff -u -B -b $TEMPDIR/sortsort $TEMPDIR/pspp.list
75 if [ $? -ne 0 ] ; then fail ; fi
76
77 # 2. It should be six elements wide
78 activity="check data width"
79 awk '!/^\ *$/{if (NF!=6) exit 1}' $TEMPDIR/pspp.list 
80 if [ $? -ne 0 ] ; then fail ; fi
81
82
83 pass;