3 # This program tests the psql import feature.
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
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`
14 PSPP=$top_builddir/src/ui/terminal/pspp
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
24 PG_CONFIG=${PG_CONFIG:=pg_config}
25 pgpath=`$PG_CONFIG | awk '/BINDIR/{print $3}'`
29 if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then
30 echo "NOT cleaning $TEMPDIR"
33 PGHOST=$TEMPDIR $pgpath/pg_ctl -D $TEMPDIR/cluster stop -W -o "-k $TEMPDIR -h ''" > /dev/null 2>&1
61 if [ ! -x $pgpath/initdb ] ; then
62 echo 'No Postgres server was found, so the postgres database interface cannot be tested.'
71 activity="create cluster"
72 $pgpath/initdb -D $TEMPDIR/cluster -A trust > /dev/null
73 if [ $? -ne 0 ] ; then no_result ; fi
76 PGHOST=$TEMPDIR PGPORT=$port $pgpath/pg_ctl -D $TEMPDIR/cluster start -w -o "-k $TEMPDIR -h ''" > /dev/null
77 if [ $? -ne 0 ] ; then no_result ; fi
80 activity="create database"
81 $pgpath/createdb -h $TEMPDIR -p $port $dbase > /dev/null 2> /dev/null
82 if [ $? -ne 0 ] ; then no_result ; fi
85 activity="populate database"
86 $pgpath/psql -h $TEMPDIR -p $port $dbase > /dev/null << EOF
88 CREATE TABLE empty (a int, b date, c numeric(23, 4));
90 -- a largeish table to check big queries work ok.
91 CREATE TABLE large (x int);
92 INSERT INTO large (select * from generate_series(1, 1000));
102 numeric numeric(50,6) ,
112 timestamp timestamp ,
113 timestamptz timestamptz ,
118 INSERT INTO thing VALUES (
135 'January 8 04:05:06 1999',
136 'January 8 04:05:06 1999 PST',
141 INSERT INTO thing VALUES (
164 INSERT INTO thing VALUES (
181 '10-Jan-1963 23:58:00',
182 '10-Jan-1963 23:58:00 CET',
183 '2 year 1 month 12 days 1 hours 3 minutes 4 seconds',
187 if [ $? -ne 0 ] ; then fail ; fi
189 activity="create program 1"
190 cat > $TESTFILE <<EOF
192 /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
194 /SQL="select * from thing".
200 if [ $? -ne 0 ] ; then no_result ; fi
203 activity="run program 1"
204 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
205 if [ $? -ne 0 ] ; then no_result ; fi
207 activity="compare output 1"
208 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
209 diff -b $TEMPDIR/pspp.list - << 'EOF'
211 +---------------+-------------------------------------------+--------+
212 |Variable |Description |Position|
213 #===============#===========================================#========#
214 |bool |Format: F8.2 | 1|
215 | |Measure: Scale | |
216 | |Display Alignment: Right | |
217 | |Display Width: 8 | |
218 +---------------+-------------------------------------------+--------+
219 |bytea |Format: AHEX2 | 2|
220 | |Measure: Nominal | |
221 | |Display Alignment: Left | |
222 | |Display Width: 1 | |
223 +---------------+-------------------------------------------+--------+
224 |char |Format: A8 | 3|
225 | |Measure: Nominal | |
226 | |Display Alignment: Left | |
227 | |Display Width: 8 | |
228 +---------------+-------------------------------------------+--------+
229 |int8 |Format: F8.2 | 4|
230 | |Measure: Scale | |
231 | |Display Alignment: Right | |
232 | |Display Width: 8 | |
233 +---------------+-------------------------------------------+--------+
234 |int2 |Format: F8.2 | 5|
235 | |Measure: Scale | |
236 | |Display Alignment: Right | |
237 | |Display Width: 8 | |
238 +---------------+-------------------------------------------+--------+
239 |int4 |Format: F8.2 | 6|
240 | |Measure: Scale | |
241 | |Display Alignment: Right | |
242 | |Display Width: 8 | |
243 +---------------+-------------------------------------------+--------+
244 |numeric |Format: E40.6 | 7|
245 | |Measure: Scale | |
246 | |Display Alignment: Right | |
247 | |Display Width: 8 | |
248 +---------------+-------------------------------------------+--------+
249 |text |Format: A16 | 8|
250 | |Measure: Nominal | |
251 | |Display Alignment: Left | |
252 | |Display Width: 16 | |
253 +---------------+-------------------------------------------+--------+
254 |oid |Format: F8.2 | 9|
255 | |Measure: Scale | |
256 | |Display Alignment: Right | |
257 | |Display Width: 8 | |
258 +---------------+-------------------------------------------+--------+
259 |float4 |Format: F8.2 | 10|
260 | |Measure: Scale | |
261 | |Display Alignment: Right | |
262 | |Display Width: 8 | |
263 +---------------+-------------------------------------------+--------+
264 |float8 |Format: F8.2 | 11|
265 | |Measure: Scale | |
266 | |Display Alignment: Right | |
267 | |Display Width: 8 | |
268 +---------------+-------------------------------------------+--------+
269 |money |Format: DOLLAR8.2 | 12|
270 | |Measure: Scale | |
271 | |Display Alignment: Right | |
272 | |Display Width: 8 | |
273 +---------------+-------------------------------------------+--------+
274 |pbchar |Format: A8 | 13|
275 | |Measure: Nominal | |
276 | |Display Alignment: Left | |
277 | |Display Width: 8 | |
278 +---------------+-------------------------------------------+--------+
279 |varchar |Format: A8 | 14|
280 | |Measure: Nominal | |
281 | |Display Alignment: Left | |
282 | |Display Width: 8 | |
283 +---------------+-------------------------------------------+--------+
284 |date |Format: DATE11 | 15|
285 | |Measure: Scale | |
286 | |Display Alignment: Right | |
287 | |Display Width: 8 | |
288 +---------------+-------------------------------------------+--------+
289 |time |Format: TIME11.0 | 16|
290 | |Measure: Scale | |
291 | |Display Alignment: Right | |
292 | |Display Width: 8 | |
293 +---------------+-------------------------------------------+--------+
294 |timestamp |Format: DATETIME22.0 | 17|
295 | |Measure: Scale | |
296 | |Display Alignment: Right | |
297 | |Display Width: 8 | |
298 +---------------+-------------------------------------------+--------+
299 |timestamptz |Format: DATETIME22.0 | 18|
300 | |Measure: Scale | |
301 | |Display Alignment: Right | |
302 | |Display Width: 8 | |
303 +---------------+-------------------------------------------+--------+
304 |interval |Format: DTIME13.0 | 19|
305 | |Measure: Scale | |
306 | |Display Alignment: Right | |
307 | |Display Width: 8 | |
308 +---------------+-------------------------------------------+--------+
309 |interval_months|Format: F3.0 | 20|
310 | |Measure: Scale | |
311 | |Display Alignment: Right | |
312 | |Display Width: 8 | |
313 +---------------+-------------------------------------------+--------+
314 |timetz |Format: TIME11.0 | 21|
315 | |Measure: Scale | |
316 | |Display Alignment: Right | |
317 | |Display Width: 8 | |
318 +---------------+-------------------------------------------+--------+
319 |timetz_zone |Format: F8.2 | 22|
320 | |Measure: Scale | |
321 | |Display Alignment: Right | |
322 | |Display Width: 8 | |
323 +---------------+-------------------------------------------+--------+
324 bool bytea char int8 int2 int4 numeric text oid float4 float8 money pbchar varchar date time timestamp timestamptz interval interval_months timetz timetz_zone
325 -------- ----- -------- -------- -------- -------- ---------------------------------------- ---------------- -------- -------- -------- -------- -------- -------- ----------- ----------- ---------------------- ---------------------- ------------- --------------- ----------- -----------
326 .00 30 a .00 .00 .00 -2.560980E+002 this-long-text .00 .00 .00 $.01 a A 01-JAN-2000 0:00:00 08-JAN-1999 04:05:06 08-JAN-1999 12:05:06 0 00:01:00 0 10:09:00 4.00
327 . 20 . . . . . . . . . . . . . . . .
328 1.00 31 b 1.00 1.00 1.00 6.553500E+004 that-long-text .00 1.00 1.00 $1.23 b B 10-JAN-1963 1:05:02 10-JAN-1963 23:58:00 10-JAN-1963 22:58:00 12 01:03:04 25 1:05:02 -7.00
330 if [ $? -ne 0 ] ; then fail ; fi
333 activity="create program 2"
334 cat > $TESTFILE <<EOF
336 /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
338 /SQL="select * from empty".
344 if [ $? -ne 0 ] ; then no_result ; fi
346 activity="run program 2"
347 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
348 if [ $? -ne 0 ] ; then no_result ; fi
350 activity="compare output 2"
351 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
352 diff -b $TEMPDIR/pspp.list - << 'EOF'
354 +--------+-------------------------------------------+--------+
355 |Variable|Description |Position|
356 #========#===========================================#========#
357 |a |Format: F8.2 | 1|
358 | |Measure: Scale | |
359 | |Display Alignment: Right | |
360 | |Display Width: 8 | |
361 +--------+-------------------------------------------+--------+
362 |b |Format: DATE11 | 2|
363 | |Measure: Scale | |
364 | |Display Alignment: Right | |
365 | |Display Width: 8 | |
366 +--------+-------------------------------------------+--------+
367 |c |Format: E40.2 | 3|
368 | |Measure: Scale | |
369 | |Display Alignment: Right | |
370 | |Display Width: 8 | |
371 +--------+-------------------------------------------+--------+
373 if [ $? -ne 0 ] ; then fail ; fi
375 activity="create program 3"
376 cat > $TESTFILE <<EOF
378 /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
381 /SQL="select * from large".
384 COMPUTE diff = x - lag (x).
387 SELECT IF (diff <> 1).
401 if [ $? -ne 0 ] ; then no_result ; fi
403 activity="run program 3"
404 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
405 if [ $? -ne 0 ] ; then no_result ; fi
407 activity="compare output 3"
408 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
409 diff -b $TEMPDIR/pspp.list - << 'EOF'
427 if [ $? -ne 0 ] ; then fail ; fi