Use signal handlers with the window as the first argument where reasonable to do so
[pspp-builds.git] / tests / command / do-if.sh
1 #!/bin/sh
2
3 # This program tests the DO IF command.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6
7 # ensure that top_builddir  are absolute
8 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 top_builddir=`cd $top_builddir; pwd`
11 PSPP=$top_builddir/src/ui/terminal/pspp
12
13 # ensure that top_srcdir is absolute
14 top_srcdir=`cd $top_srcdir; pwd`
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19 LANG=C
20 export LANG
21
22 cleanup()
23 {
24      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
25         echo "NOT cleaning $TEMPDIR" 
26         return ; 
27      fi
28      cd /
29      rm -rf $TEMPDIR
30 }
31
32
33 fail()
34 {
35     echo $activity
36     echo FAILED
37     cleanup;
38     exit 1;
39 }
40
41
42 no_result()
43 {
44     echo $activity
45     echo NO RESULT;
46     cleanup;
47     exit 2;
48 }
49
50 pass()
51 {
52     cleanup;
53     exit 0;
54 }
55
56 mkdir -p $TEMPDIR
57
58 cd $TEMPDIR
59
60 activity="generate input and expected output"
61 (for a in 0 1 ' '; do
62     for b in 0 1 ' '; do
63         for c in 0 1 ' '; do
64             for d in 0 1 ' '; do
65                 abcd=$a$b$c$d
66                 echo "$abcd" 1>&3
67                 if test "$a" = "1"; then
68                     echo " $abcd A"
69                 elif test "$a" = " "; then
70                     :
71                 elif test "$b" = "1"; then
72                     echo " $abcd B"
73                 elif test "$b" = " "; then
74                     :
75                 elif test "$c" = "1"; then
76                     echo " $abcd C"
77                 elif test "$c" = " "; then
78                     :
79                 elif test "$d" = "1"; then
80                     echo " $abcd D"
81                 elif test "$d" = " "; then
82                     :
83                 else
84                     echo " $abcd E"
85                 fi
86             done
87         done
88     done
89 done) >test1.expected 3>test1.data
90 if [ $? -ne 0 ] ; then no_result ; fi
91
92 activity="create test1.pspp"
93 cat > test1.pspp <<EOF
94 DATA LIST FILE="test1.data"/A B C D 1-4 ABCD 1-4 (A).
95 DO IF A.
96 PRINT OUTFILE="test1.out"/ABCD 'A'.
97 ELSE IF B.
98 PRINT OUTFILE="test1.out"/ABCD 'B'.
99 ELSE IF C.
100 PRINT OUTFILE="test1.out"/ABCD 'C'.
101 ELSE IF D.
102 PRINT OUTFILE="test1.out"/ABCD 'D'.
103 ELSE.
104 PRINT OUTFILE="test1.out"/ABCD 'E'.
105 END IF.
106 EXECUTE.
107 EOF
108 if [ $? -ne 0 ] ; then no_result ; fi
109
110 activity="run test1"
111 $SUPERVISOR $PSPP -o pspp.csv test1.pspp
112 if [ $? -ne 0 ] ; then no_result ; fi
113
114 activity="compare test1 results"
115 diff -u $TEMPDIR/test1.out $TEMPDIR/test1.expected
116 if [ $? -ne 0 ] ; then fail ; fi
117
118 pass