Allow building test suite in a different place other than the source code is.
authorHiroshi Inoue <inoue@tpf.co.jp>
Tue, 21 Oct 2014 07:57:28 +0000 (16:57 +0900)
committerHiroshi Inoue <inoue@tpf.co.jp>
Thu, 13 Nov 2014 11:57:36 +0000 (20:57 +0900)
Change the test suite so that it works not only with unixODBC but also with iodbc.

test/Makefile.in
test/expected/odbcini-gen.out [new file with mode: 0644]
test/launcher_i [new file with mode: 0755]
test/src/odbcini-gen.sh [new file with mode: 0755]

index 4a913f3d927adfadd17fcdab37bed5cbfbbfc288..488a35c79f11e1b4780051fc50aa242772e78c45 100644 (file)
@@ -1,36 +1,64 @@
 # The list of test is stored in a separate file, so that it can be shared with
 # the Windows makefile, win.mak.
-include tests
+
+origdir = @srcdir@
+
+vpath %.c $(origdir)
+vpath %.sh $(origdir)
+
+include $(origdir)/tests
 
 # The included file defined variable TESTBINS, which is a list of program
 # names in format src/<testname>-test. Extract the base test names from it.
 TESTNAMES = $(patsubst src/%-test,%, $(TESTBINS))
 TESTSQLS = $(patsubst %,sql/%.sql, $(TESTNAMES))
 
+INIGEN=odbcini-gen
+INIGENSQL=sql/$(INIGEN).sql
+
 # Set by autoconf
 LDFLAGS = @LDFLAGS@
 CFLAGS = @CFLAGS@
 PG_CONFIG = @PG_CONFIG@
+ODBC_CONFIG = @ODBC_CONFIG@
+
+ifneq (,$(findstring iodbc,$(ODBC_CONFIG)))
+   launcher=launcher_i
+else
+   launcher=launcher
+endif
+
+REGRESS = sampletables $(INIGEN) $(TESTNAMES)
 
-REGRESS = sampletables $(TESTNAMES)
+LIBODBC := $(shell $(ODBC_CONFIG) --libs)
 
-all: $(TESTBINS) $(TESTSQLS)
+all: $(TESTBINS) $(TESTSQLS) $(INIGENSQL)
 
 installcheck: all
 
-override CFLAGS += -Wno-pointer-sign
+override CFLAGS += -Wno-pointer-sign $(CFLAGS_ADD)
 
 src/common.o: src/common.c
+   @if test ! -d src; then mkdir -p src; fi
+   $(COMPILE.c) -c $< -o $@
 
 # For each test file, compile the .c file, and create a .sql file that
 # when executed from psql, just runs the binary.
 src/%-test sql/%.sql: src/%-test.c src/common.o
-   $(CC) $(CFLAGS) $(LDFLAGS) src/$*-test.c src/common.o -o src/$*-test -lodbc
+   $(CC) $(CFLAGS) $(LDFLAGS) $^ -o src/$*-test $(LIBODBC)
+   @if test ! -d sql; then mkdir -p sql; fi
    echo "\! \"./src/$*-test\"" > sql/$*.sql
 
-EXTRA_CLEAN = $(TESTBINS) $(TESTSQLS) src/common.o
+# For each shell file, create a .sql file that when executed from psql, 
+# just runs the shell.
+sql/%.sql: src/%.sh
+   @if test ! -d sql; then mkdir -p sql; fi
+   echo "\! \"$<\"" > $@
 
-REGRESS_OPTS = --launcher=./launcher
+EXTRA_CLEAN = $(TESTBINS) $(TESTSQLS) src/common.o $(INIGENSQL)
 
+REGRESS_OPTS = --launcher=$(origdir)/$(launcher) --inputdir=$(origdir)
+ifndef PGXS
 PGXS := $(shell $(PG_CONFIG) --pgxs)
+endif
 include $(PGXS)
diff --git a/test/expected/odbcini-gen.out b/test/expected/odbcini-gen.out
new file mode 100644 (file)
index 0000000..1950379
--- /dev/null
@@ -0,0 +1,3 @@
+\! "./src/odbcini-gen.sh"
+This isn't a test application
+Initializing odbc(inst).ini
diff --git a/test/launcher_i b/test/launcher_i
new file mode 100755 (executable)
index 0000000..6537830
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Lancher script for iodbc
+# Pass ODBCINSTINI and ODBCINI env variables to psql, so that it finds 
+# the odbc.ini and odbcinst.ini files from the current dir.
+ODBCINSTINI=./odbcinst.ini ODBCINI=./odbc.ini $*
diff --git a/test/src/odbcini-gen.sh b/test/src/odbcini-gen.sh
new file mode 100755 (executable)
index 0000000..2c3ee6f
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+#  This isn't a test application.
+#  Initial setting of odbc(inst).ini.
+#
+echo This isn\'t a test application
+echo Initializing odbc\(inst\).ini
+
+outini=odbc.ini
+outinstini=odbcinst.ini
+if test -s ${outini}; then exit; fi
+drvr=../.libs/psqlodbcw
+driver=${drvr}.so
+if test ! -e $driver ; then
+   driver=${drvr}.dll
+   if test ! -e $driver ; then
+       echo Failure:driver ${drvr}.so\(.dll\) not found
+       exit 2
+   fi
+fi
+
+echo creating $outinstini
+cat << _EOT_ > $outinstini
+[psqlodbc test driver]
+Description     = PostgreSQL ODBC driver (Unicode version), for regression tests
+Driver          = $driver
+Debug           = 0
+CommLog         = 1
+_EOT_
+
+server=localhost
+if test "${PGHOST}" != "" ; then
+   server=${PGHOST}
+fi
+port=5432
+if test "${PGPORT}" != "" ; then
+   port=${PGPORT}
+fi
+
+echo creating $outini
+cat << _EOT_ > $outini
+[psqlodbc_test_dsn]
+Description             = psqlodbc regression test DSN
+Driver          = psqlodbc test driver
+Trace           = No
+TraceFile               =
+Database                = contrib_regression
+Servername              = ${server}
+Username                =
+Password                =
+Port            = ${port}
+ReadOnly                = No
+RowVersioning           = No
+ShowSystemTables                = No
+ShowOidColumn           = No
+FakeOidIndex            = No
+ConnSettings            =
+_EOT_