Merge commit 'origin/stable'
[pspp-builds.git] / tests / bugs / examine-missing2.sh
1 #!/bin/sh
2
3 # This program tests for a bug in which examine didn't
4 # count missing values.
5
6 TEMPDIR=/tmp/pspp-tst-$$
7 TESTFILE=$TEMPDIR/`basename $0`.sps
8
9 # ensure that top_srcdir and top_builddir  are absolute
10 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
11 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
12 top_srcdir=`cd $top_srcdir; pwd`
13 top_builddir=`cd $top_builddir; pwd`
14
15 PSPP=$top_builddir/src/ui/terminal/pspp
16
17 STAT_CONFIG_PATH=$top_srcdir/config
18 export STAT_CONFIG_PATH
19
20 LANG=C
21 export LANG
22
23
24 cleanup()
25 {
26      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
27         echo "NOT cleaning $TEMPDIR"
28         return ; 
29      fi
30      cd /
31      rm -rf $TEMPDIR
32 }
33
34
35 fail()
36 {
37     echo $activity
38     echo FAILED
39     cleanup;
40     exit 1;
41 }
42
43
44 no_result()
45 {
46     echo $activity
47     echo NO RESULT;
48     cleanup;
49     exit 2;
50 }
51
52 pass()
53 {
54     cleanup;
55     exit 0;
56 }
57
58 mkdir -p $TEMPDIR
59
60 cd $TEMPDIR
61
62 activity="create program 1"
63 cat > $TESTFILE << EOF
64 DATA LIST LIST /x * y *.
65 BEGIN DATA.
66 1   1 
67 2   1
68 3   1
69 4   1
70 5   2
71 6   2
72 .   2
73 END DATA
74
75 EXAMINE /x by y.
76 EOF
77 if [ $? -ne 0 ] ; then no_result ; fi
78
79
80 activity="run program 1"
81 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
82 if [ $? -ne 0 ] ; then no_result ; fi
83
84 activity="compare results"
85 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
86 diff -b  $TEMPDIR/pspp.list - <<EOF
87 1.1 DATA LIST.  Reading free-form data from INLINE.
88 +--------+------+
89 |Variable|Format|
90 #========#======#
91 |x       |F8.0  |
92 |y       |F8.0  |
93 +--------+------+
94 2.1 EXAMINE.  Case Processing Summary
95 #=#===============================#
96 # #             Cases             #
97 # #----------+----------+---------#
98 # #   Valid  |  Missing |  Total  #
99 # #-+--------+-+--------+-+-------#
100 # #N| Percent|N| Percent|N|Percent#
101 #=#=#========#=#========#=#=======#
102 #x#6|85.7143%|1|14.2857%|7|   100%#
103 #=#=#========#=#========#=#=======#
104 2.2 EXAMINE.  Case Processing Summary
105 #==========#===============================#
106 #          #             Cases             #
107 #          #----------+----------+---------#
108 #          #   Valid  |  Missing |  Total  #
109 #          #-+--------+-+--------+-+-------#
110 #      y   #N| Percent|N| Percent|N|Percent#
111 #==========#=#========#=#========#=#=======#
112 #x     1.00#4|    100%|0|      0%|4|   100%#
113 #      2.00#2|66.6667%|1|33.3333%|3|   100%#
114 #==========#=#========#=#========#=#=======#
115 EOF
116 if [ $? -ne 0 ] ; then fail ; fi
117
118
119 #Make sure this doesn't interfere with percentiles operation.
120
121 activity="create program 2"
122 cat > $TESTFILE << EOF
123 DATA LIST LIST /X *.
124 BEGIN DATA.
125 99
126 99
127 5.00
128 END DATA.
129
130 MISSING VALUE X (99).
131
132 EXAMINE /x
133         /PERCENTILES=HAVERAGE.
134
135
136 EOF
137 if [ $? -ne 0 ] ; then no_result ; fi
138
139
140 activity="run program 2"
141 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
142 if [ $? -ne 0 ] ; then fail ; fi
143
144
145 pass;