get-data-psql.at: Make test work with Debian pg_wrapper arrangement.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 3 Dec 2018 02:36:51 +0000 (18:36 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 3 Dec 2018 02:42:07 +0000 (18:42 -0800)
It had been years since I tested Postgres, but I was making a change that
would affect the Postgres test, and I found out that the test didn't work.
This fixes it.

tests/language/data-io/get-data-psql.at

index fc99babf348d49bdc4fc1f4367644e08460f21ec..3096073b03f4a8db7d85348d035ea1ddc1eeeea8 100644 (file)
@@ -18,8 +18,6 @@ AT_BANNER([GET DATA /TYPE=PSQL])
 
 m4_define([INIT_PSQL], 
   [AT_SKIP_IF([test "$PSQL_SUPPORT" = no])
-   PATH=$PG_PATH:$PATH
-   export PATH
    PGDATA=`pwd`/cluster
    export PGDATA
    PGPORT=$PG_PORT
@@ -27,10 +25,10 @@ m4_define([INIT_PSQL],
    socket_dir=`mktemp -d`
    PGHOST="$socket_dir"
    export PGHOST
-   AT_CHECK([initdb -A trust], [0], [ignore])
-   AT_CHECK([pg_ctl start -w -o "-k $socket_dir -h ''"], [0], [ignore])
+   AT_CHECK([PATH=$PG_PATH:$PATH initdb -A trust], [0], [ignore])
+   AT_CHECK([PATH=$PG_PATH:$PATH pg_ctl start -w -o "-k $socket_dir -h ''"], [0], [ignore])
    trap 'CLEANUP_PSQL' 0
-   AT_CHECK([createdb -h "$socket_dir" -p $PG_PORT $PG_DBASE],
+   AT_CHECK([PATH=$PG_PATH:$PATH 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));
@@ -132,10 +130,19 @@ m4_define([INIT_PSQL],
        '01:05:02 UTC-7'
       );
 ])
+
+   # On Debian, the psql binary in the postgres bindir won't work because
+   # it needs libreadline to be LD_PRELOADed into it.  The psql in the
+   # normal $PATH works fine though.
+   if (PATH=$PG_PATH:$PATH psql -V) >/dev/null 2>&1; then
+       psql () {
+           PATH=$PG_PATH:$PATH command psql "$@"
+       }
+   fi
    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 $socket_dir -h ''"])
+m4_define([CLEANUP_PSQL], [PATH=$PG_PATH:$PATH pg_ctl stop -W -o "-k $socket_dir -h ''"])
 
 AT_SETUP([GET DATA /TYPE=PSQL])
 INIT_PSQL