Merge commit 'origin/stable'
[pspp-builds.git] / tests / command / insert.sh
1 #!/bin/sh
2
3 # This program tests the INSERT command
4
5 BASETEMPDIR=/tmp/pspp-tst-$$
6 TEMPDIR=$BASETEMPDIR/link
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 $BASETEMPDIR"
28         return ; 
29      fi
30      cd /
31      rm -rf $BASETEMPDIR
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 $BASETEMPDIR/target
59
60 ln -s $BASETEMPDIR/target $TEMPDIR
61
62 cd $TEMPDIR
63
64 activity="create wrapper 1"
65 cat <<EOF > $TESTFILE
66 INSERT 
67   FILE='$TEMPDIR/foo.sps'
68   SYNTAX=INTERACTIVE
69   .
70
71
72 LIST.
73
74 EOF
75 if [ $? -ne 0 ] ; then no_result ; fi
76
77 #The following syntax intentionally omits periods from some lines
78 #It's an example of "batch" syntax
79 activity="create insert"
80 cat <<EOF > $TEMPDIR/foo.sps
81 input program.
82 +  loop #i = 1 to 100.
83 +    compute z = #i
84 +    end case.
85 +  end loop
86 end file.
87 end input program.
88
89 EOF
90 if [ $? -ne 0 ] ; then no_result ; fi
91
92
93 #This command should fail
94 activity="run program 1"
95 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
96 if [ $? -eq 0 ] ; then fail ; fi
97
98
99 activity="create wrapper 2"
100 cat <<EOF > $TESTFILE
101 INSERT 
102   FILE='$TEMPDIR/foo.sps'
103   SYNTAX=BATCH
104   .
105
106
107 LIST.
108
109 EOF
110 if [ $? -ne 0 ] ; then no_result ; fi
111
112 activity="run program 2"
113 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
114 if [ $? -ne 0 ] ; then fail ; fi
115
116
117 # Now test the CD subcommand
118
119 activity="mkdir 1"
120 mkdir $TEMPDIR/Dir1
121 if [ $? -ne 0 ] ; then no_result ; fi
122
123 activity="create wrapper 3"
124 cat <<EOF > $TESTFILE
125 INSERT 
126   FILE='$TEMPDIR/Dir1/foo.sps'
127   CD=NO
128   .
129
130
131 LIST.
132
133 EOF
134 if [ $? -ne 0 ] ; then no_result ; fi
135
136 activity="create wrapper 4"
137 cat <<EOF > $TEMPDIR/Dir1/foo.sps
138 INSERT 
139   FILE='bar.sps'
140   CD=NO
141   .
142
143 EOF
144 if [ $? -ne 0 ] ; then no_result ; fi
145
146 activity="create wrapper 5"
147 cat <<EOF > $TEMPDIR/Dir1/bar.sps
148 DATA LIST LIST /x *.
149 BEGIN DATA.
150 1
151 2
152 3
153 END DATA.
154
155 EOF
156 if [ $? -ne 0 ] ; then no_result ; fi
157
158
159 # This command should fail
160 activity="run program 3"
161 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
162 if [ $? -eq 0 ] ; then fail ; fi
163
164 activity="create wrapper 6"
165 cat <<EOF > $TESTFILE
166 INSERT 
167   FILE='$TEMPDIR/Dir1/foo.sps'
168   CD=YES
169   .
170
171 LIST.
172
173 EOF
174 if [ $? -ne 0 ] ; then no_result ; fi
175
176 activity="run program 4"
177 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
178 if [ $? -ne 0 ] ; then fail ; fi
179
180
181 # Now test the ERROR= feature
182
183 activity="create wrapper 7"
184 cat <<EOF > $TESTFILE
185 INSERT 
186   FILE='$TEMPDIR/foo.sps'
187   ERROR=STOP.
188   .
189
190 LIST.
191
192 EOF
193 if [ $? -ne 0 ] ; then no_result ; fi
194
195
196 activity="create included file"
197 cat <<EOF > $TEMPDIR/foo.sps
198 DATA LIST NOTABLE LIST /x *.
199 BEGIN DATA.
200 1
201 2
202 3
203 END DATA.
204
205 * The following line is erroneous
206
207 DISPLAY AKSDJ.
208
209 EOF
210 if [ $? -ne 0 ] ; then no_result ; fi
211
212 activity="run program 5"
213 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
214 if [ $? -ne 1 ] ; then no_result ; fi
215
216 activity="examine output 1"
217 diff $TEMPDIR/pspp.list - <<EOF
218 $TEMPDIR/foo.sps:10: error: DISPLAY: AKSDJ is not a variable name.
219 warning: Error encountered while ERROR=STOP is effective.
220 $TEMPDIR/foo.sps:10: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
221
222 EOF
223 if [ $? -ne 0 ] ; then fail ; fi
224
225
226 activity="create wrapper 8"
227 cat <<EOF > $TESTFILE
228 INSERT 
229   FILE='$TEMPDIR/foo.sps'
230   ERROR=CONTINUE.
231   .
232
233 LIST.
234
235 EOF
236 if [ $? -ne 0 ] ; then no_result ; fi
237
238 activity="run program 6"
239 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
240 if [ $? -ne 1 ] ; then no_result ; fi
241
242 activity="examine output 2"
243 diff $TEMPDIR/pspp.list - <<EOF
244 $TEMPDIR/foo.sps:10: error: DISPLAY: AKSDJ is not a variable name.
245
246        x
247 --------
248     1.00 
249     2.00 
250     3.00 
251
252 EOF
253 if [ $? -ne 0 ] ; then fail ; fi
254
255 # Test for regression against bug #24569 in which PSPP crashed
256 # upon attempt to insert a nonexistent file.
257 activity="create wrapper 9"
258 cat <<EOF > $TESTFILE
259 INSERT 
260   FILE='$TEMPDIR/nonexistent'
261   ERROR=CONTINUE.
262   .
263
264 LIST.
265
266 EOF
267 if [ $? -ne 0 ] ; then no_result ; fi
268
269 #This command should fail
270 activity="run program 7"
271 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE > /dev/null
272 if [ $? -eq 0 ] ; then no_result ; fi
273
274 pass;