Postgres test: Create socket in /tmp instead of current directory
[pspp] / tests / language / data-io / get-data-psql.at
index 8aa777c514ae27511dd0e519100d44fdafdb4015..163b7e36d624a94d602ea02a2bb813c8b1ca1b97 100644 (file)
@@ -6,14 +6,15 @@ m4_define([INIT_PSQL],
    export PATH
    PGDATA=`pwd`/cluster
    export PGDATA
-   PGHOST=`pwd`
-   export PGHOST
    PGPORT=$PG_PORT
    export PGPORT
+   socket_dir=`mktemp -d`
+   PGHOST="$socket_dir"
+   export PGHOST
    AT_CHECK([initdb -A trust], [0], [ignore])
-   AT_CHECK([pg_ctl start -w -o "-k `pwd` -h ''"], [0], [ignore])
+   AT_CHECK([pg_ctl start -w -o "-k $socket_dir -h ''"], [0], [ignore])
    trap 'CLEANUP_PSQL' 0
-   AT_CHECK([createdb -h "`pwd`" -p $PG_PORT $PG_DBASE],
+   AT_CHECK([createdb -h "$socket_dir" -p $PG_PORT $PG_DBASE],
       [0], [ignore], [ignore])
    AT_DATA([populate.sql], 
      [CREATE TABLE empty (a int, b date, c numeric(23, 4));
@@ -115,17 +116,18 @@ m4_define([INIT_PSQL],
        '01:05:02 UTC-7'
       );
 ])
-   AT_CHECK([psql -h "`pwd`" -p $PG_PORT $PG_DBASE < populate.sql],
+   AT_CHECK([psql -h "$socket_dir" -p $PG_PORT $PG_DBASE < populate.sql],
       [0], [ignore])])
 
-m4_define([CLEANUP_PSQL], [pg_ctl stop -W -o "-k `pwd` -h ''"])
+m4_define([CLEANUP_PSQL], [pg_ctl stop -W -o "-k $socket_dir -h ''"])
 
-AT_SETUP([GET DATA /TYPE=PSQL -- ordinary query])
+AT_SETUP([GET DATA /TYPE=PSQL])
 INIT_PSQL
-AT_CAPTURE_FILE([get-data.sps])
-AT_CHECK([cat > get-data.sps <<EOF
+
+dnl Test with an ordinary query.
+AT_CHECK([cat > ordinary-query.sps <<EOF
 GET DATA /TYPE=psql 
-       /CONNECT="host=$PGHOST port=$PGPORT dbname=$PG_DBASE"
+       /CONNECT="host=$socket_dir port=$PGPORT dbname=$PG_DBASE"
        /UNENCRYPTED
        /SQL="select * from thing".
 
@@ -134,7 +136,7 @@ DISPLAY DICTIONARY.
 LIST.
 EOF
 ])
-AT_CHECK([pspp -o pspp.csv get-data.sps])
+AT_CHECK([pspp -o pspp.csv ordinary-query.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
 Variable,Description,,Position
 bool,Format: F8.2,,1
@@ -232,14 +234,11 @@ bool,bytea,char,int8,int2,int4,numeric,text,oid,float4,float8,money,pbchar,varch
 .  ,20,,.  ,.  ,.  ,.          ,,.  ,.  ,.  ,.  ,,,.,.,.,.,.,.,.,.  @&t@
 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
 ])
-AT_CLEANUP
 
-AT_SETUP([GET DATA /TYPE=PSQL -- empty result set])
-INIT_PSQL
-AT_CAPTURE_FILE([get-data.sps])
-AT_CHECK([cat > get-data.sps <<EOF
+dnl Test query with empty result set.
+AT_CHECK([cat > empty-result.sps <<EOF
 GET DATA /TYPE=psql 
-       /CONNECT="host=$PGHOST port=$PGPORT dbname=$PG_DBASE"
+       /CONNECT="host=$socket_dir port=$PGPORT dbname=$PG_DBASE"
        /UNENCRYPTED
        /SQL="select * from empty".
 
@@ -248,7 +247,7 @@ DISPLAY DICTIONARY.
 LIST.
 EOF
 ])
-AT_CHECK([pspp -o pspp.csv get-data.sps])
+AT_CHECK([pspp -o pspp.csv empty-result.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
 Variable,Description,,Position
 a,Format: F8.2,,1
@@ -264,14 +263,11 @@ c,Format: E40.2,,3
 ,Display Alignment: Right,,
 ,Display Width: 8,,
 ])
-AT_CLEANUP
 
-AT_SETUP([GET DATA /TYPE=PSQL -- large result set])
-INIT_PSQL
-AT_CAPTURE_FILE([get-data.sps])
-AT_CHECK([cat > get-data.sps <<EOF
+dnl Test query with large result set.
+AT_CHECK([cat > large-result.sps <<EOF
 GET DATA /TYPE=psql 
-       /CONNECT="host=$PGHOST port=$PGPORT dbname=$PG_DBASE"
+       /CONNECT="host=$socket_dir port=$PGPORT dbname=$PG_DBASE"
        /UNENCRYPTED
        /SQL="select * from large".
 
@@ -293,7 +289,7 @@ N OF CASES 6.
 LIST.
 EOF
 ])
-AT_CHECK([pspp -o pspp.csv get-data.sps])
+AT_CHECK([pspp -o pspp.csv large-result.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
 Table: Data List
 x,diff
@@ -313,12 +309,9 @@ x,diff
 996.00,1.00
 995.00,1.00
 ])
-AT_CLEANUP
 
 dnl Check for a bug caused by having string variables in the database,
 dnl all of which are null.
-AT_SETUP([GET DATA /TYPE=PSQL -- all-null string])
-INIT_PSQL
 AT_DATA([all-null-string.sql],
   [-- a table which has a text field containing only null, or zero
    -- length entries.
@@ -329,12 +322,12 @@ AT_DATA([all-null-string.sql],
 
    INSERT INTO foo VALUES (null, '');
 ])
-AT_CHECK([psql -h "`pwd`" -p $PG_PORT $PG_DBASE < all-null-string.sql],
+AT_CHECK([psql -h "$socket_dir" -p $PG_PORT $PG_DBASE < all-null-string.sql],
   [0], [ignore])
 AT_CAPTURE_FILE([get-data.sps])
 AT_CHECK([cat > get-data.sps <<EOF
 GET DATA /TYPE=psql 
-       /CONNECT="host=$PGHOST port=$PGPORT dbname=$PG_DBASE"
+       /CONNECT="host=$socket_dir port=$PGPORT dbname=$PG_DBASE"
        /UNENCRYPTED
        /SQL="select * from foo".
 
@@ -345,4 +338,5 @@ EOF
 ])
 AT_CHECK([pspp -o pspp.csv get-data.sps])
 AT_CAPTURE_FILE([pspp.csv])
+rm -rf "$socket_dir"
 AT_CLEANUP