ba4f543a790e6e595455271974aa3ed5b237b8fc
[pspp-builds.git] / tests / command / insert.sh
1 #!/bin/sh
2
3 # This program tests the INSERT command
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_srcdir and top_builddir  are absolute
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 top_srcdir=`cd $top_srcdir; pwd`
12 top_builddir=`cd $top_builddir; pwd`
13
14 PSPP=$top_builddir/src/ui/terminal/pspp
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19 LANG=C
20 export LANG
21
22
23 cleanup()
24 {
25      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
26         echo "NOT cleaning $TEMPDIR"
27         return ; 
28      fi
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="create wrapper 1"
61 cat <<EOF > $TESTFILE
62 INSERT 
63   FILE='$TEMPDIR/foo.sps'
64   SYNTAX=INTERACTIVE
65   .
66
67
68 LIST.
69
70 EOF
71 if [ $? -ne 0 ] ; then no_result ; fi
72
73 #The following syntax intentionally omits periods from some lines
74 #It's an example of "batch" syntax
75 activity="create insert"
76 cat <<EOF > $TEMPDIR/foo.sps
77 input program.
78 +  loop #i = 1 to 100.
79 +    compute z = #i
80 +    end case.
81 +  end loop
82 end file.
83 end input program.
84
85 EOF
86 if [ $? -ne 0 ] ; then no_result ; fi
87
88
89 #This command should fail
90 activity="run program 1"
91 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
92 if [ $? -eq 0 ] ; then fail ; fi
93
94
95 activity="create wrapper 2"
96 cat <<EOF > $TESTFILE
97 INSERT 
98   FILE='$TEMPDIR/foo.sps'
99   SYNTAX=BATCH
100   .
101
102
103 LIST.
104
105 EOF
106 if [ $? -ne 0 ] ; then no_result ; fi
107
108 activity="run program 2"
109 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
110 if [ $? -ne 0 ] ; then fail ; fi
111
112
113 # Now test the CD subcommand
114
115 activity="mkdir 1"
116 mkdir $TEMPDIR/Dir1
117 if [ $? -ne 0 ] ; then no_result ; fi
118
119 activity="create wrapper 3"
120 cat <<EOF > $TESTFILE
121 INSERT 
122   FILE='$TEMPDIR/Dir1/foo.sps'
123   CD=NO
124   .
125
126
127 LIST.
128
129 EOF
130 if [ $? -ne 0 ] ; then no_result ; fi
131
132 activity="create wrapper 4"
133 cat <<EOF > $TEMPDIR/Dir1/foo.sps
134 INSERT 
135   FILE='bar.sps'
136   CD=NO
137   .
138
139 EOF
140 if [ $? -ne 0 ] ; then no_result ; fi
141
142 activity="create wrapper 5"
143 cat <<EOF > $TEMPDIR/Dir1/bar.sps
144 DATA LIST LIST /x *.
145 BEGIN DATA.
146 1
147 2
148 3
149 END DATA.
150
151 EOF
152 if [ $? -ne 0 ] ; then no_result ; fi
153
154
155 # This command should fail
156 activity="run program 3"
157 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
158 if [ $? -eq 0 ] ; then fail ; fi
159
160 activity="create wrapper 6"
161 cat <<EOF > $TESTFILE
162 INSERT 
163   FILE='$TEMPDIR/Dir1/foo.sps'
164   CD=YES
165   .
166
167 LIST.
168
169 EOF
170 if [ $? -ne 0 ] ; then no_result ; fi
171
172 activity="run program 4"
173 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
174 if [ $? -ne 0 ] ; then fail ; fi
175
176
177 # Now test the ERROR= feature
178
179 activity="create wrapper 7"
180 cat <<EOF > $TESTFILE
181 INSERT 
182   FILE='$TEMPDIR/foo.sps'
183   ERROR=STOP.
184   .
185
186 LIST.
187
188 EOF
189 if [ $? -ne 0 ] ; then no_result ; fi
190
191
192 activity="create included file"
193 cat <<EOF > $TEMPDIR/foo.sps
194 DATA LIST NOTABLE LIST /x *.
195 BEGIN DATA.
196 1
197 2
198 3
199 END DATA.
200
201 * The following line is erroneous
202
203 DISPLAY AKSDJ.
204
205 EOF
206 if [ $? -ne 0 ] ; then no_result ; fi
207
208 activity="run program 5"
209 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
210 if [ $? -ne 1 ] ; then no_result ; fi
211
212 activity="examine output 1"
213 diff $TEMPDIR/pspp.list - <<EOF
214 $TEMPDIR/foo.sps:10: error: DISPLAY: AKSDJ is not a variable name.
215 warning: Error encountered while ERROR=STOP is effective.
216 $TEMPDIR/foo.sps:10: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
217
218 EOF
219 if [ $? -ne 0 ] ; then fail ; fi
220
221
222 activity="create wrapper 8"
223 cat <<EOF > $TESTFILE
224 INSERT 
225   FILE='$TEMPDIR/foo.sps'
226   ERROR=CONTINUE.
227   .
228
229 LIST.
230
231 EOF
232 if [ $? -ne 0 ] ; then no_result ; fi
233
234 activity="run program 6"
235 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
236 if [ $? -ne 1 ] ; then no_result ; fi
237
238 activity="examine output 2"
239 diff $TEMPDIR/pspp.list - <<EOF
240 $TEMPDIR/foo.sps:10: error: DISPLAY: AKSDJ is not a variable name.
241
242        x
243 --------
244     1.00 
245     2.00 
246     3.00 
247
248 EOF
249 if [ $? -ne 0 ] ; then fail ; fi
250
251
252
253 pass;