Fixed problem with postgres 8.0.x
[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 : ${PERL:=perl}
8
9 # ensure that top_builddir  are absolute
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
12 top_builddir=`cd $top_builddir; pwd`
13 PSPP=$top_builddir/src/ui/terminal/pspp
14
15 # ensure that top_srcdir is absolute
16 top_srcdir=`cd $top_srcdir; pwd`
17
18 STAT_CONFIG_PATH=$top_srcdir/config
19 export STAT_CONFIG_PATH
20
21
22 cleanup()
23 {
24      cd /
25      rm -rf $TEMPDIR
26 }
27
28
29 fail()
30 {
31     echo $activity
32     echo FAILED
33     cleanup;
34     exit 1;
35 }
36
37
38 no_result()
39 {
40     echo $activity
41     echo NO RESULT;
42     cleanup;
43     exit 2;
44 }
45
46 pass()
47 {
48     cleanup;
49     exit 0;
50 }
51
52 mkdir -p $TEMPDIR
53
54 cd $TEMPDIR
55
56 activity="write perl program for generating data"
57 cat > gen-data.pl <<'EOF'
58 use strict;
59 use warnings;
60
61 # Generate shuffled data.
62 my (@data);
63 for my $i (0...$ARGV[0] - 1) {
64     push (@data, $i) foreach 1...$ARGV[1];
65 }
66 fisher_yates_shuffle (\@data);
67
68 # Output shuffled data.
69 my (@shuffled) = map ([$data[$_], $_], 0...$#data);
70 open (SHUFFLED, ">sort.in");
71 print SHUFFLED "$data[$_] $_\n" foreach 0...$#data;
72
73 # Output sorted data.
74 my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled;
75 open (SORTED, ">sort.exp");
76 print SORTED "$_->[0] $_->[1]\n" foreach @sorted;
77
78 # From perlfaq4.
79 sub fisher_yates_shuffle {
80     my $deck = shift;  # $deck is a reference to an array
81     my $i = @$deck;
82     while ($i--) {
83         my $j = int rand ($i+1);
84         @$deck[$i,$j] = @$deck[$j,$i];
85     }
86 }
87 EOF
88
89 for count_repeat_buffers in \
90     "100 5 2" "100 5 3" "100 5 4" "100 5 5" "100 5 10" "100 5 50" "100 5 100" "100 5" \
91     "100 10 2" "100 10 3" "100 10 5" "100 10" \
92     "1000 5 5" "1000 5 50" "1000 5" \
93     "100 100 3" "100 100 5" "100 100" \
94     "10000 5 500" \
95     "50000 1"; do
96   set $count_repeat_buffers
97   count=$1
98   repeat=$2
99   buffers=$3
100
101   printf .
102
103   activity="generate data for $count_repeat_buffers run"
104   $PERL gen-data.pl $count $repeat > sort.data
105   if [ $? -ne 0 ] ; then no_result ; fi
106   
107   activity="generate test program for $count_repeat_buffers run"
108   {
109       echo "data list list file='sort.in'/x y (f8)."
110       if test "$buffers" != ""; then
111           echo "sort by x/buffers=$buffers."
112       else
113           echo "sort by x."
114       fi
115       echo "print outfile='sort.out'/x y."
116       echo "execute."
117   } > sort.pspp || no_result
118   
119   activity="run program"
120   $SUPERVISOR $PSPP --testing-mode sort.pspp
121   if [ $? -ne 0 ] ; then no_result ; fi
122   
123   perl -pi -e 's/^\s*$//g' sort.exp sort.out
124   diff -w sort.exp sort.out
125   if [ $? -ne 0 ] ; then fail ; fi
126 done
127 echo
128 pass;