44e5fd0546cb8146a3f3f7556430c67152413bfc
[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 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 export STAT_CONFIG_PATH=$top_srcdir/config
14
15
16 cleanup()
17 {
18      rm -rf $TEMPDIR
19 }
20
21
22 fail()
23 {
24     echo $activity
25     echo FAILED
26     cleanup;
27     exit 1;
28 }
29
30
31 no_result()
32 {
33     echo $activity
34     echo NO RESULT;
35     cleanup;
36     exit 2;
37 }
38
39 pass()
40 {
41     cleanup;
42     exit 0;
43 }
44
45 mkdir -p $TEMPDIR
46
47 cd $TEMPDIR
48
49
50 activity="generate stat program"
51 cat > $TESTFILE <<EOF
52 title 'Test SORT procedure'.
53
54 data list file='$here/sort.data' notable /X000 to X126 1-127.
55 sort by X000 to x005.
56 print /X000 to X005.
57 execute.
58 EOF
59 if [ $? -ne 0 ] ; then no_result ; fi
60
61 activity="run program"
62 $SUPERVISOR $here/../src/pspp -o raw-ascii $TESTFILE
63 if [ $? -ne 0 ] ; then no_result ; fi
64
65 # Now there should be some sorted data in $TEMPDIR/pspp.list
66 # We have to do some checks on it.
67
68 # 1. Is it sorted ?
69
70 activity="check sorted"
71 sort $TEMPDIR/pspp.list  > $TEMPDIR/sortsort
72 if [ $? -ne 0 ] ; then no_result ; fi
73
74 diff -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;