4d530989c9b9c5087c525c22708ce0e92e929cc6
[pspp-builds.git] / tests / command / missing-values.sh
1 #!/bin/sh
2
3 # This program tests MISSING VALUES
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 STAT_CONFIG_PATH=$top_srcdir/config
14 export STAT_CONFIG_PATH
15
16
17 cleanup()
18 {
19      cd /
20      rm -rf $TEMPDIR
21 }
22
23
24 fail()
25 {
26     echo $activity
27     echo FAILED
28     cleanup;
29     exit 1;
30 }
31
32
33 no_result()
34 {
35     echo $activity
36     echo NO RESULT;
37     cleanup;
38     exit 2;
39 }
40
41 pass()
42 {
43     cleanup;
44     exit 0;
45 }
46
47 mkdir -p $TEMPDIR
48
49 cd $TEMPDIR
50
51 # Copy this file --- it's shared with another test
52 activity="create data"
53 cp $top_srcdir/tests/data-list.data $TEMPDIR
54 if [ $? -ne 0 ] ; then no_result ; fi
55
56
57 activity="create program"
58 cat > $TEMPDIR/missing-values.stat << foobar
59 DATA LIST NOTABLE/str1 1-5 (A) str2 6-8 (A) date1 9-19 (DATE) num1 20-25.
60
61 /* Valid: numeric missing values.
62 MISSING VALUES date1 num1 (1).
63 MISSING VALUES date1 num1 (1, 2).
64 MISSING VALUES date1 num1 (1, 2, 3).
65
66 /* Valid: numeric missing values using the first variable's format.
67 MISSING VALUES num1 date1 ('1').
68 MISSING VALUES num1 date1 ('1', '2').
69 MISSING VALUES num1 date1 ('1', '2', '3').
70 MISSING VALUES date1 num1 ('06-AUG-05').
71 MISSING VALUES date1 num1 ('06-AUG-05', '01-OCT-78').
72 MISSING VALUES date1 num1 ('06-AUG-05', '01-OCT-78', '14-FEB-81').
73
74 /* Valid: ranges of numeric missing values.
75 MISSING VALUES num1 (1 THRU 2).
76 MISSING VALUES num1 (LO THRU 2).
77 MISSING VALUES num1 (LOWEST THRU 2).
78 MISSING VALUES num1 (1 THRU HI).
79 MISSING VALUES num1 (1 THRU HIGHEST).
80
81 /* Valid: a range of numeric missing values, plus an individual value.
82 MISSING VALUES num1 (1 THRU 2, 3).
83 MISSING VALUES num1 (LO THRU 2, 3).
84 MISSING VALUES num1 (LOWEST THRU 2, 3).
85 MISSING VALUES num1 (1 THRU HI, -1).
86 MISSING VALUES num1 (1 THRU HIGHEST, -1).
87
88 /* Valid: string missing values.
89 MISSING VALUES str1 str2 ('abc  ','def').
90
91 /* Invalid: too long for str2.
92 MISSING VALUES str1 str2 ('abcde').
93
94 /* Invalid: no string ranges.
95 MISSING VALUES str1 ('a' THRU 'z').
96
97 /* Invalid: mixing string and numeric variables.
98 MISSING VALUES str1 num1 ('123').
99
100 /* Valid: may mix variable types when clearing missing values.
101 MISSING VALUES ALL ().
102
103 foobar
104 if [ $? -ne 0 ] ; then no_result ; fi
105
106
107 activity="run program"
108 $SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii --testing-mode $TEMPDIR/missing-values.stat > $TEMPDIR/errs
109 # Note   vv   --- there are errors in input.  Therefore, the  command must FAIL
110 if [ $? -eq 0 ] ; then fail ; fi
111
112 activity="compare error messages"
113 diff -w $TEMPDIR/errs - <<EOF
114 $TEMPDIR/missing-values.stat:34: error: MISSING VALUES: Missing values provided are too long to assign to variable of width 3.
115 $TEMPDIR/missing-values.stat:34: warning: Skipping the rest of this command.  Part of this command may have been executed.
116 $TEMPDIR/missing-values.stat:37: error: MISSING VALUES: Syntax error expecting string at \`THRU'.
117 $TEMPDIR/missing-values.stat:37: error: MISSING VALUES: THRU is not a variable name.
118 $TEMPDIR/missing-values.stat:37: warning: Skipping the rest of this command.  Part of this command may have been executed.
119 $TEMPDIR/missing-values.stat:40: error: MISSING VALUES: Cannot mix numeric variables (e.g. num1) and string variables (e.g. str1) within a single list.
120 $TEMPDIR/missing-values.stat:40: warning: Skipping the rest of this command.  Part of this command may have been executed.
121 EOF
122 if [ $? -ne 0 ] ; then fail ; fi
123
124
125 pass;