psqlodbc.git / summary / log / commit / refs

commit    2002b71d25f07a62e4b722e63f079c8678d3bf8b
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Mon Jan 26 07:01:29 2015 +0000

    Refactor regression tests to use a custom program instead of pg_regress.
    
    Using pg_regress was awkward, because it used a dummy .sql file for each
    test that just launched the test program. Also, it added a dependency;
    the driver doesn't require PostgreSQL sources to build, just libpq
    headers, but the pgxs program is not usually shipped with libpq headers.
    
    The new "runsuite" program runs all the test programs given on the command
    line, compares the results with the expected output, and produces
    TAP-compatible output. It can be run stand-alone, as the TAP output is
    human-readable, or with the perl 'prove' program which gives more pretty
    output.


configure.ac | 2 + test/.gitignore | 5 + test/Makefile.in | 55 +++---- test/expected/alter.out | 1 - test/expected/arraybinding.out | 1 - test/expected/bindcol.out | 1 - test/expected/bookmark.out | 1 - test/expected/boolsaschar.out | 1 - test/expected/bulkoperations.out | 1 - test/expected/catalogfunctions.out | 1 - test/expected/colattribute.out | 1 - test/expected/colattribute_1.out | 1 - test/expected/commands.out | 1 - test/expected/connect.out | 1 - test/expected/cte.out | 1 - test/expected/cursor-commit.out | 1 - test/expected/cursor-movement.out | 1 - test/expected/cursor-movement_1.out | 1 - test/expected/cursor-name.out | 1 - test/expected/cursors.out | 1 - test/expected/cursors_1.out | 1 - test/expected/cvtnulldate.out | 1 - test/expected/dataatexecution.out | 1 - test/expected/declare-fetch-commit.out | 1 - test/expected/deprecated.out | 1 - test/expected/diagnostic.out | 1 - test/expected/error-rollback.out | 1 - test/expected/errors.out | 1 - test/expected/errors_1.out | 1 - test/expected/errors_2.out | 1 - test/expected/getresult.out | 1 - test/expected/insertreturning.out | 1 - test/expected/large-object.out | 1 - test/expected/lfconversion.out | 1 - test/expected/multistmt.out | 1 - test/expected/notice.out | 1 - test/expected/numeric.out | 1 - test/expected/odbc-escapes.out | 1 - test/expected/param-conversions.out | 1 - test/expected/param-conversions_1.out | 1 - test/expected/params.out | 1 - test/expected/params_1.out | 1 - test/expected/parse.out | 1 - test/expected/positioned-update.out | 1 - test/expected/premature.out | 1 - test/expected/prepare.out | 1 - test/expected/quotes.out | 1 - test/expected/result-conversions.out | 1 - test/expected/sampletables.out | 33 ---- test/expected/select.out | 1 - test/expected/stmthandles.out | 1 - test/expected/update.out | 1 - test/launcher | 5 - test/launcher_i | 6 - test/reset-db.c | 114 +++++++++++++ test/runsuite.c | 289 +++++++++++++++++++++++++++++++++ }/sampletables.sql | 10 +- test/sql/.gitignore | 2 - test/win.mak | 35 ++-- 59 files changed, 450 insertions(+), 154 deletions(-) diff --git a/configure.ac b/configure.ac index b318ba37..c0587de6 100644 --- a/configure.ac +++ b/configure.ac @@ -178,6 +178,8 @@ fi # 1. Programs +# 'prove' is used to pretty-print regression test results, if available. +AC_CHECK_PROGS(PROVE, prove) # 2. Libraries diff --git a/test/.gitignore b/test/.gitignore index 92408371..13cf0cfb 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,3 +1,8 @@ +/runsuite +/runsuite.exe +/reset-db +/reset-db.exe + # Generated by running the tests /results/ # Generated by autoconf diff --git a/test/Makefile.in b/test/Makefile.in index b558ff7c..b293341b 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -11,57 +11,46 @@ 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)) # 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 $(TESTNAMES) +PROVE = @PROVE@ LIBODBC := $(shell $(ODBC_CONFIG) --libs) -all: $(TESTBINS) $(TESTSQLS) +all: $(TESTBINS) runsuite reset-db odbc.ini: ./odbcini-gen.sh $(odbc_ini_extras) -installcheck: all odbc.ini +installcheck: all odbc.ini reset-db runsuite + rm -f regression.diffs + @if test ! -d results; then mkdir -p results; fi + ODBCSYSINI=. ODBCINSTINI=./odbcinst.ini ODBCINI=./odbc.ini ./reset-db < sampletables.sql +# If the perl 'prove' test running utility is available, use it. It produces +# nice output. But otherwise just run the plain suite, it's usable as is too. +ifdef PROVE + prove -e ./runsuite $(TESTNAMES) +else + ./runsuite $(TESTNAMES) +endif override CFLAGS += -Wno-pointer-sign $(CFLAGS_ADD) +runsuite: runsuite.c + +reset-db: reset-db.c + $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(LIBODBC) + 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 +# For each test, compile the .c file. +src/%-test: src/%-test.c src/common.o $(CC) $(CFLAGS) $(LDFLAGS) $^ -o src/$*-test $(LIBODBC) - @if test ! -d sql; then mkdir -p sql; fi - echo "\! \"./src/$*-test\"" > sql/$*.sql - -# 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 "\! \"$<\"" > $@ - -EXTRA_CLEAN = $(TESTBINS) $(TESTSQLS) src/common.o - -REGRESS_OPTS = --launcher=$(origdir)/$(launcher) --inputdir=$(origdir) -ifndef PGXS -PGXS := $(shell $(PG_CONFIG) --pgxs) -endif -include $(PGXS) # This target runs the regression tests with all combinations of # UseDeclareFetch, UseServerSidePrepare and Protocol options. @@ -93,3 +82,7 @@ installcheck-all: $(MAKE) installcheck odbc_ini_extras="UseDeclareFetch=1 UseServerSidePrepare=0 Protocol=7.4-1" rm -f odbc.ini odbcinst.ini $(MAKE) installcheck odbc_ini_extras="UseDeclareFetch=1 UseServerSidePrepare=0 Protocol=7.4-0" + +clean: + rm -f $(TESTBINS) src/*.o runsuite reset-db + rm -f results/* diff --git a/test/expected/alter.out b/test/expected/alter.out index f08b5463..f81dc357 100644 --- a/test/expected/alter.out +++ b/test/expected/alter.out @@ -1,4 +1,3 @@ -\! "./src/alter-test" connected Result set metadata: t: VARCHAR(40) digits: 0, nullable diff --git a/test/expected/arraybinding.out b/test/expected/arraybinding.out index ec1f9f21..5eebcd2b 100644 --- a/test/expected/arraybinding.out +++ b/test/expected/arraybinding.out @@ -1,4 +1,3 @@ -\! "./src/arraybinding-test" connected Parameter Status Result set: diff --git a/test/expected/bindcol.out b/test/expected/bindcol.out index 9c152543..0c4cb21a 100644 --- a/test/expected/bindcol.out +++ b/test/expected/bindcol.out @@ -1,4 +1,3 @@ -\! "./src/bindcol-test" connected Result set: 1 foo1 diff --git a/test/expected/bookmark.out b/test/expected/bookmark.out index 7cd2a91a..0c217cf3 100644 --- a/test/expected/bookmark.out +++ b/test/expected/bookmark.out @@ -1,4 +1,3 @@ -\! "./src/bookmark-test" connected Getting bookmark to beginning of result set... fetched: foo1 diff --git a/test/expected/boolsaschar.out b/test/expected/boolsaschar.out index 947dcbc6..d73d3255 100644 --- a/test/expected/boolsaschar.out +++ b/test/expected/boolsaschar.out @@ -1,4 +1,3 @@ -\! "./src/boolsaschar-test" connected Result set metadata: b: VARCHAR(5) digits: 0, nullable diff --git a/test/expected/bulkoperations.out b/test/expected/bulkoperations.out index eea9bb85..b832319e 100644 --- a/test/expected/bulkoperations.out +++ b/test/expected/bulkoperations.out @@ -1,4 +1,3 @@ -\! "./src/bulkoperations-test" connected Creating test table bulkoperations_test Opening a cursor for update, and fetching 10 rows diff --git a/test/expected/catalogfunctions.out b/test/expected/catalogfunctions.out index 6f0e8c99..b45ea5d4 100644 --- a/test/expected/catalogfunctions.out +++ b/test/expected/catalogfunctions.out @@ -1,4 +1,3 @@ -\! "./src/catalogfunctions-test" connected Check for SQLTypeInfo Result set metadata: diff --git a/test/expected/colattribute.out b/test/expected/colattribute.out index 17cf5be2..734a3047 100644 --- a/test/expected/colattribute.out +++ b/test/expected/colattribute.out @@ -1,4 +1,3 @@ -\! "./src/colattribute-test" Running tests with UnknownSizes=-1;MaxVarcharSize=100... connected Testing SQLColAttribute... diff --git a/test/expected/colattribute_1.out b/test/expected/colattribute_1.out index b1fb6c54..5d533b60 100644 --- a/test/expected/colattribute_1.out +++ b/test/expected/colattribute_1.out @@ -1,4 +1,3 @@ -\! "./src/colattribute-test" Running tests with UnknownSizes=-1;MaxVarcharSize=100... connected Testing SQLColAttribute... diff --git a/test/expected/commands.out b/test/expected/commands.out index 0d075759..3105fc2e 100644 --- a/test/expected/commands.out +++ b/test/expected/commands.out @@ -1,4 +1,3 @@ -\! "./src/commands-test" connected Testing VACUUM with SQLExecDirect... Testing VACUUM with SQLPrepare/SQLExecute... diff --git a/test/expected/connect.out b/test/expected/connect.out index 354d9d24..32bb7181 100644 --- a/test/expected/connect.out +++ b/test/expected/connect.out @@ -1,4 +1,3 @@ -\! "./src/connect-test" connected disconnecting Connecting with SQLConnect...connected diff --git a/test/expected/cte.out b/test/expected/cte.out index 1b80aff3..a66e2ac4 100644 --- a/test/expected/cte.out +++ b/test/expected/cte.out @@ -1,4 +1,3 @@ -\! "./src/cte-test" connected Result set: 1 foo1 diff --git a/test/expected/cursor-commit.out b/test/expected/cursor-commit.out index 5c2a1247..341cb424 100644 --- a/test/expected/cursor-commit.out +++ b/test/expected/cursor-commit.out @@ -1,4 +1,3 @@ -\! "./src/cursor-commit-test" connected first row: 1 row 2: 2 diff --git a/test/expected/cursor-movement.out b/test/expected/cursor-movement.out index 13b0f205..c9bf2c6c 100644 --- a/test/expected/cursor-movement.out +++ b/test/expected/cursor-movement.out @@ -1,4 +1,3 @@ -\! "./src/cursor-movement-test" connected SQL_CURSOR_COMMIT_BEHAVIOR: SQL_CB_PRESERVE SQL_CURSOR_ROLLBACK_BEHAVIOR: SQL_CB_PRESERVE diff --git a/test/expected/cursor-movement_1.out b/test/expected/cursor-movement_1.out index f24c8098..a173e30c 100644 --- a/test/expected/cursor-movement_1.out +++ b/test/expected/cursor-movement_1.out @@ -1,4 +1,3 @@ -\! "./src/cursor-movement-test" connected SQL_CURSOR_COMMIT_BEHAVIOR: SQL_CB_PRESERVE SQL_CURSOR_ROLLBACK_BEHAVIOR: SQL_CB_CLOSE diff --git a/test/expected/cursor-name.out b/test/expected/cursor-name.out index e2195fcd..7bc49e58 100644 --- a/test/expected/cursor-name.out +++ b/test/expected/cursor-name.out @@ -1,4 +1,3 @@ -\! "./src/cursor-name-test" connected cursor name prefix: SQL_CUR disconnecting diff --git a/test/expected/cursors.out b/test/expected/cursors.out index 90182914..d1674758 100644 --- a/test/expected/cursors.out +++ b/test/expected/cursors.out @@ -1,4 +1,3 @@ -\! "./src/cursors-test" connected SQL_CURSOR_COMMIT_BEHAVIOR: SQL_CB_PRESERVE SQL_CURSOR_ROLLBACK_BEHAVIOR: SQL_CB_PRESERVE diff --git a/test/expected/cursors_1.out b/test/expected/cursors_1.out index 88a3e4e9..a65c6982 100644 --- a/test/expected/cursors_1.out +++ b/test/expected/cursors_1.out @@ -1,4 +1,3 @@ -\! "./src/cursors-test" connected SQL_CURSOR_COMMIT_BEHAVIOR: SQL_CB_PRESERVE SQL_CURSOR_ROLLBACK_BEHAVIOR: SQL_CB_CLOSE diff --git a/test/expected/cvtnulldate.out b/test/expected/cvtnulldate.out index daafba7e..b678aa7b 100644 --- a/test/expected/cvtnulldate.out +++ b/test/expected/cvtnulldate.out @@ -1,4 +1,3 @@ -\! "./src/cvtnulldate-test" connected Result set: 1 diff --git a/test/expected/dataatexecution.out b/test/expected/dataatexecution.out index fbe8b39b..51b8e328 100644 --- a/test/expected/dataatexecution.out +++ b/test/expected/dataatexecution.out @@ -1,4 +1,3 @@ -\! "./src/dataatexecution-test" connected Result set: 2 diff --git a/test/expected/declare-fetch-commit.out b/test/expected/declare-fetch-commit.out index ea80bf16..23b429fc 100644 --- a/test/expected/declare-fetch-commit.out +++ b/test/expected/declare-fetch-commit.out @@ -1,4 +1,3 @@ -\! "./src/declare-fetch-commit-test" connected Result set: 1 diff --git a/test/expected/deprecated.out b/test/expected/deprecated.out index 4bfb342f..17973fb3 100644 --- a/test/expected/deprecated.out +++ b/test/expected/deprecated.out @@ -1,4 +1,3 @@ -\! "./src/deprecated-test" Check for SQLAllocEnv Check for SQLAllocConnect Check for SQLAllocStmt diff --git a/test/expected/diagnostic.out b/test/expected/diagnostic.out index 05f31cb6..143bcb06 100644 --- a/test/expected/diagnostic.out +++ b/test/expected/diagnostic.out @@ -1,4 +1,3 @@ -\! "./src/diagnostic-test" connected SQLExecDirect 42601=ERROR: syntax error at or near "broken"; diff --git a/test/expected/error-rollback.out b/test/expected/error-rollback.out index 5581514d..99eb3594 100644 --- a/test/expected/error-rollback.out +++ b/test/expected/error-rollback.out @@ -1,4 +1,3 @@ -\! "./src/error-rollback-test" Test for rollback protocol 0 connected Executing query that will succeed diff --git a/test/expected/errors.out b/test/expected/errors.out index 965f4fc3..6ab9ac59 100644 --- a/test/expected/errors.out +++ b/test/expected/errors.out @@ -1,4 +1,3 @@ -\! "./src/errors-test" connected 42703=ERROR: column "doesnotexist" does not exist; diff --git a/test/expected/errors_1.out b/test/expected/errors_1.out index 49d169d0..348f6d2f 100644 --- a/test/expected/errors_1.out +++ b/test/expected/errors_1.out @@ -1,4 +1,3 @@ -\! "./src/errors-test" connected 42703=ERROR: column "doesnotexist" does not exist; diff --git a/test/expected/errors_2.out b/test/expected/errors_2.out index 3a37f897..65c8470f 100644 --- a/test/expected/errors_2.out +++ b/test/expected/errors_2.out @@ -1,4 +1,3 @@ -\! "./src/errors-test" connected 42703=ERROR: column "doesnotexist" does not exist; diff --git a/test/expected/getresult.out b/test/expected/getresult.out index 3bca7ac7..1eb8de8b 100644 --- a/test/expected/getresult.out +++ b/test/expected/getresult.out @@ -1,4 +1,3 @@ -\! "./src/getresult-test" connected Result set: varcharcol: foo diff --git a/test/expected/insertreturning.out b/test/expected/insertreturning.out index 1e925eb7..4e59a9d1 100644 --- a/test/expected/insertreturning.out +++ b/test/expected/insertreturning.out @@ -1,4 +1,3 @@ -\! "./src/insertreturning-test" Testing with UseServerSidePrepare=1 connected # of result cols before SQLExecute: 1, after: 1 diff --git a/test/expected/large-object.out b/test/expected/large-object.out index 78dd408e..b60b3228 100644 --- a/test/expected/large-object.out +++ b/test/expected/large-object.out @@ -1,4 +1,3 @@ -\! "./src/large-object-test" connected inserting large object... reading it back... diff --git a/test/expected/lfconversion.out b/test/expected/lfconversion.out index bb92181f..6d733c26 100644 --- a/test/expected/lfconversion.out +++ b/test/expected/lfconversion.out @@ -1,4 +1,3 @@ -\! "./src/lfconversion-test" connected reading to char buffer... strlen 22, SQLGetData claims 22 diff --git a/test/expected/multistmt.out b/test/expected/multistmt.out index 9e5ce9be..68a9e920 100644 --- a/test/expected/multistmt.out +++ b/test/expected/multistmt.out @@ -1,4 +1,3 @@ -\! "./src/multistmt-test" connected --1 Result set: 1 diff --git a/test/expected/notice.out b/test/expected/notice.out index 7c653143..aebf2a05 100644 --- a/test/expected/notice.out +++ b/test/expected/notice.out @@ -1,4 +1,3 @@ -\! "./src/notice-test" connected got SUCCESS_WITH_INFO 00000=NOTICE: test notice: foo diff --git a/test/expected/numeric.out b/test/expected/numeric.out index 17f8ae18..4db4b19d 100644 --- a/test/expected/numeric.out +++ b/test/expected/numeric.out @@ -1,4 +1,3 @@ -\! "./src/numeric-test" connected Testing SQL_NUMERIC_STRUCT params... diff --git a/test/expected/odbc-escapes.out b/test/expected/odbc-escapes.out index c32a0241..a7a6cfd6 100644 --- a/test/expected/odbc-escapes.out +++ b/test/expected/odbc-escapes.out @@ -1,4 +1,3 @@ -\! "./src/odbc-escapes-test" connected Query: SELECT {fn CONCAT(?, ?) } diff --git a/test/expected/param-conversions.out b/test/expected/param-conversions.out index da9a8a88..449a398f 100644 --- a/test/expected/param-conversions.out +++ b/test/expected/param-conversions.out @@ -1,4 +1,3 @@ -\! "./src/param-conversions-test" connected Testing conversions... diff --git a/test/expected/param-conversions_1.out b/test/expected/param-conversions_1.out index a6e2a0cd..8c8e0031 100644 --- a/test/expected/param-conversions_1.out +++ b/test/expected/param-conversions_1.out @@ -1,4 +1,3 @@ -\! "./src/param-conversions-test" connected Testing conversions... diff --git a/test/expected/params.out b/test/expected/params.out index 9dda4b4e..02056106 100644 --- a/test/expected/params.out +++ b/test/expected/params.out @@ -1,4 +1,3 @@ -\! "./src/params-test" connected # of result cols: 2 Result set: diff --git a/test/expected/params_1.out b/test/expected/params_1.out index 00d6ad0e..242d5769 100644 --- a/test/expected/params_1.out +++ b/test/expected/params_1.out @@ -1,4 +1,3 @@ -\! "./src/params-test" connected # of result cols: 2 Result set: diff --git a/test/expected/parse.out b/test/expected/parse.out index a5491dfc..96690b38 100644 --- a/test/expected/parse.out +++ b/test/expected/parse.out @@ -1,4 +1,3 @@ -\! "./src/parse-test" connected Result set metadata: id: INTEGER(10) digits: 0, not nullable diff --git a/test/expected/positioned-update.out b/test/expected/positioned-update.out index 0770206e..8f4784b7 100644 --- a/test/expected/positioned-update.out +++ b/test/expected/positioned-update.out @@ -1,4 +1,3 @@ -\! "./src/positioned-update-test" connected Creating test table pos_update_test Opening a cursor for update, and fetching 10 rows diff --git a/test/expected/premature.out b/test/expected/premature.out index 9d682d68..5f9cb948 100644 --- a/test/expected/premature.out +++ b/test/expected/premature.out @@ -1,4 +1,3 @@ -\! "./src/premature-test" connected Preparing an INSERT statement diff --git a/test/expected/prepare.out b/test/expected/prepare.out index b656f907..0afb1bff 100644 --- a/test/expected/prepare.out +++ b/test/expected/prepare.out @@ -1,4 +1,3 @@ -\! "./src/prepare-test" connected # of result cols: 2 Result set: diff --git a/test/expected/quotes.out b/test/expected/quotes.out index 358d60cf..6dc437be 100644 --- a/test/expected/quotes.out +++ b/test/expected/quotes.out @@ -1,4 +1,3 @@ -\! "./src/quotes-test" connected SET standard_conforming_strings=on diff --git a/test/expected/result-conversions.out b/test/expected/result-conversions.out index 91b0ee38..fe1ada31 100644 --- a/test/expected/result-conversions.out +++ b/test/expected/result-conversions.out @@ -1,4 +1,3 @@ -\! "./src/result-conversions-test" connected Executed: SET intervalstyle=postgres Executed: SET bytea_output=escape diff --git a/test/expected/sampletables.out b/test/expected/sampletables.out deleted file mode 100644 index c54b3257..00000000 --- a/test/expected/sampletables.out +++ /dev/null @@ -1,33 +0,0 @@ --- This file creates some tables to be used in the tests -SET client_min_messages TO WARNING; -CREATE TABLE testtab1 (id integer PRIMARY KEY, t varchar(20)); -INSERT INTO testtab1 VALUES (1, 'foo'); -INSERT INTO testtab1 VALUES (2, 'bar'); -INSERT INTO testtab1 VALUES (3, 'foobar'); -CREATE TABLE testtab_fk (id integer REFERENCES testtab1, t varchar(20)); -INSERT INTO testtab_fk VALUES (1, 'hoge'); -INSERT INTO testtab_fk VALUES (2, 'pogno'); -INSERT INTO testtab_fk VALUES (3, 'poco'); -CREATE TABLE byteatab (id integer, t bytea); -INSERT INTO byteatab VALUES (1, E'\\001\\002\\003\\004\\005\\006\\007\\010'::bytea); -INSERT INTO byteatab VALUES (2, 'bar'); -INSERT INTO byteatab VALUES (3, 'foobar'); -INSERT INTO byteatab VALUES (4, 'foo'); -INSERT INTO byteatab VALUES (5, 'barf'); -CREATE TABLE intervaltable(id integer, iv interval, d varchar(100)); -INSERT INTO intervaltable VALUES (1, '1 day', 'one day'); -INSERT INTO intervaltable VALUES (2, '10 seconds', 'ten secs'); -INSERT INTO intervaltable VALUES (3, '100 years', 'hundred years'); -CREATE TABLE booltab (id integer, t varchar(5), b boolean); -INSERT INTO booltab VALUES (1, 'yeah', true); -INSERT INTO booltab VALUES (2, 'yes', true); -INSERT INTO booltab VALUES (3, 'true', true); -INSERT INTO booltab VALUES (4, 'false', false); -INSERT INTO booltab VALUES (5, 'not', false); --- Procedure for catalog function checks -CREATE FUNCTION simple_add(in int, in int, out int) -AS $$ SELECT $1 + $2; -$$ LANGUAGE SQL; --- Large object support -CREATE DOMAIN lo AS oid; -CREATE TABLE lo_test_tab (id int4, large_data lo); diff --git a/test/expected/select.out b/test/expected/select.out index 82dfd4aa..c841073c 100644 --- a/test/expected/select.out +++ b/test/expected/select.out @@ -1,4 +1,3 @@ -\! "./src/select-test" connected Result set: 1 diff --git a/test/expected/stmthandles.out b/test/expected/stmthandles.out index 864a54ca..f9e2a947 100644 --- a/test/expected/stmthandles.out +++ b/test/expected/stmthandles.out @@ -1,4 +1,3 @@ -\! "./src/stmthandles-test" connected 10 statements allocated... 20 statements allocated... diff --git a/test/expected/update.out b/test/expected/update.out index 8ff08085..bf60f4d0 100644 --- a/test/expected/update.out +++ b/test/expected/update.out @@ -1,4 +1,3 @@ -\! "./src/update-test" connected # of rows inserted: 1 # of rows inserted: 1 diff --git a/test/launcher b/test/launcher deleted file mode 100755 index cdafdc86..00000000 --- a/test/launcher +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -# Pass ODBCSYSINI env variable to psql, so that it finds the odbc.ini and -# odbcinst.ini files from the current dir. -ODBCSYSINI=. $* diff --git a/test/launcher_i b/test/launcher_i deleted file mode 100755 index 6537830a..00000000 --- a/test/launcher_i +++ /dev/null @@ -1,6 +0,0 @@ -#!/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/reset-db.c b/test/reset-db.c new file mode 100644 index 00000000..3e442be9 --- /dev/null +++ b/test/reset-db.c @@ -0,0 +1,114 @@ +/* + * Initializes contrib_regression database. + * + * DROPs and CREATEs the database, then executes all statements passed in + * stdin. Use "reset-db < sampletables.sql" to run. + * + * This uses the same psqlodbc_test_dsn datasource to connect that the + * actual regression tests use. + */ +#include <stdio.h> +#include <stdlib.h> + +#ifdef WIN32 +#include <windows.h> +#endif + +#include <sql.h> +#include <sqlext.h> + +static SQLHENV env; +static SQLHDBC conn; +static HSTMT hstmt = SQL_NULL_HSTMT; + +static void +connect_to_db(char *dsn) +{ + SQLRETURN ret; + char errmsg[500]; + SQLSMALLINT textlen; + char sqlstate[20]; + + SQLAllocHandle(SQL_HANDLE_DBC, env, &conn); + + ret = SQLDriverConnect(conn, NULL, (SQLCHAR *) dsn, SQL_NTS, NULL, 0, NULL, + SQL_DRIVER_NOPROMPT); + if (!SQL_SUCCEEDED(ret)) + { + printf("connection to %s failed\n", dsn); + + ret = SQLGetDiagRec(SQL_HANDLE_DBC, conn, 1, sqlstate, NULL, + errmsg, sizeof(errmsg), &textlen); + if (ret == SQL_INVALID_HANDLE) + printf("Invalid handle\n"); + else if (SQL_SUCCEEDED(ret)) + printf("%s=%s\n", sqlstate, errmsg); + exit(1); + } + + printf("connected to %s\n", dsn); + + ret = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt); + if (!SQL_SUCCEEDED(ret)) + { + printf("SQLAllocHandle failed\n"); + exit(1); + } +} + +static void +run_statement(char *statement) +{ + SQLRETURN ret; + char errmsg[500]; + SQLSMALLINT textlen; + char sqlstate[20]; + + /* + * Skip empty lines. The server would just ignore them too, but might as + * well avoid the round-trip. + */ + if (statement[0] == '\0' || statement[0] == '\n') + return; + + /* Skip comment lines too. */ + if (statement[0] == '-' && statement[1] == '-') + return; + + ret = SQLExecDirect(hstmt, (SQLCHAR *) statement, SQL_NTS); + if (!SQL_SUCCEEDED(ret)) + { + printf("Statement failed: %s\n", statement); + ret = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, 1, sqlstate, NULL, + errmsg, sizeof(errmsg), &textlen); + if (ret == SQL_INVALID_HANDLE) + printf("Invalid handle\n"); + else if (SQL_SUCCEEDED(ret)) + printf("%s=%s\n", sqlstate, errmsg); + exit(1); + } + (void) SQLFreeStmt(hstmt, SQL_CLOSE); +} + +int main(int argc, char **argv) +{ + char line[500]; + + SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env); + SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0); + + connect_to_db("DSN=psqlodbc_test_dsn;Database=postgres"); + printf("Dropping and creating database contrib_regression...\n"); + run_statement("DROP DATABASE IF EXISTS contrib_regression"); + run_statement("CREATE DATABASE contrib_regression"); + + connect_to_db("DSN=psqlodbc_test_dsn;Database=contrib_regression"); + + printf("Running initialization script...\n"); + while (fgets(line, sizeof(line), stdin) != NULL) + run_statement(line); + + printf("Done!\n"); + + return 0; +} diff --git a/test/runsuite.c b/test/runsuite.c new file mode 100644 index 00000000..9bb5d8f1 --- /dev/null +++ b/test/runsuite.c @@ -0,0 +1,289 @@ +/* + * A test driver for the psqlodbc regression tests. + * + * This program runs one regression tests from the src/ directory, + * and compares the output with the expected output in the expected/ directory. + * Reports success or failure in TAP compatible fashion. + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#ifndef WIN32 +#include <unistd.h> +#endif +#include <stdarg.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#ifdef WIN32 +#define snprintf _snprintf +#define vsnprintf _vsnprintf +#define strdup _strdup +#endif + +static int rundiff(const char *testname); +static int runtest(const char *binname, const char *testname, int testno); + +static char *slurpfile(const char *filename, size_t *len); + +static void +bailout(const char *fmt, ...) +{ + va_list argp; + + va_start(argp, fmt); + + printf("Bail out! "); + vprintf(fmt, argp); + + va_end(argp); + + exit(1); +} + +#ifdef WIN32 +#define DIR_SEP '\\' +#else +#define DIR_SEP '/' +#endif + +/* Given a test program's name, get the test name */ +void +parse_argument(const char *in, char *testname, char *binname) +{ + const char *basename; +#ifdef WIN32 + const char *suffix = "-test.exe"; +#else + const char *suffix = "-test"; +#endif + size_t len; + + /* if the input is a plain test name, construct the binary name from it */ + if (strchr(in, DIR_SEP) == NULL) + { + strcpy(testname, in); + sprintf(binname, "src%c%s-test", DIR_SEP, in); + return; + } + + /* + * Otherwise the input is a binary name, and we'll construct the test name + * from it. + */ + strcpy(binname, in); + + /* Find the last / or \ character */ + basename = strrchr(in, DIR_SEP) + 1; + + /* Strip -test or -test.exe suffix */ + if (strlen(basename) <= strlen(suffix)) + { + strcpy(testname, basename); + return; + } + + len = strlen(basename) - strlen(suffix); + if (strcmp(&basename[len], suffix) != 0) + { + strcpy(testname, basename); + return; + } + + memcpy(testname, basename, len); + testname[len] = '\0'; +} + +int main(int argc, char **argv) +{ + char binname[1000]; + char testname[100]; + int numtests; + int i; + int failures; + + if (argc < 2) + { + printf("Usage: runsuite <test binary> ...\n"); + exit(1); + } + numtests = argc - 1; + + printf("TAP version 13\n"); + printf("1..%d\n", numtests); + + /* + * We accept either test binary name or plain test name. + */ + failures = 0; + for (i = 1; i <= numtests; i++) + { + parse_argument(argv[i], testname, binname); + if (runtest(binname, testname, i) != 0) + failures++; + } + + exit(failures > 254 ? 254 : failures); +} + +/* Return 0 on success, 1 on failure */ +static int +runtest(const char *binname, const char *testname, int testno) +{ + char cmdline[1024]; + int rc; + int ret; + int diff; + + /* + * ODBCSYSINI=. tells unixodbc where to find the driver config file, + * odbcinst.ini + * + * ODBCINSTINI=./odbcinst.ini tells the same for iodbc. iodbc also requires + * ODBCINI=./odbc.ini to tell it where to find the datasource config. + * + * We wouldn't need to iodbc stuff when building with unixodbc and vice + * versa, but it doesn't hurt either. + */ +#ifndef WIN32 + snprintf(cmdline, sizeof(cmdline), + "ODBCSYSINI=. ODBCINSTINI=./odbcinst.ini ODBCINI=./odbc.ini " + "%s > results/%s.out", + binname, testname); +#else + snprintf(cmdline, sizeof(cmdline), + "%s > results\\%s.out", + binname, testname); +#endif + rc = system(cmdline); + + diff = rundiff(testname); + if (rc != 0) + { + printf("not ok %d - %s test returned %d\n", testno, testname, rc); + ret = 1; + } + else if (diff != 0) + { + printf("not ok %d - %s test output differs\n", testno, testname); + ret = 1; + } + else + { + printf("ok %d - %s\n", testno, testname); + ret = 0; + } + fflush(stdout); + + return ret; +} + +static int +rundiff(const char *testname) +{ + char filename[1024]; + char cmdline[1024]; + int outputno; + char *result; + size_t result_len; + + snprintf(filename, sizeof(filename), "results/%s.out", testname); + result = slurpfile(filename, &result_len); + + outputno = 0; + for (;;) + { + char *expected; + size_t expected_len; + + if (outputno == 0) + snprintf(filename, sizeof(filename), "expected/%s.out", testname); + else + snprintf(filename, sizeof(filename), "expected/%s_%d.out", testname, outputno); + expected = slurpfile(filename, &expected_len); + if (expected == NULL) + { + if (outputno == 0) + bailout("could not open file %s: %s\n", filename, strerror(ENOENT)); + free(result); + break; + } + + if (expected_len == result_len && + memcmp(expected, result, expected_len) == 0) + { + /* The files are equal. */ + free(result); + free(expected); + return 0; + } + + free(expected); + + outputno++; + } + /* no matching output found */ + + /* + * Try to run diff. If this fails, e.g. because the 'diff' program is + * not installed, which is typical on Windows system, that's OK. You'll + * miss the regression.diffs output, but we'll still report "not ok" + * correctly. You can always compare the files manually... + * + * XXX: Somewhat arbitrarily, always run the diff against the primary + * expected output file. Perhaps we should run it against all output + * files and print the smallest diff? + */ + snprintf(cmdline, sizeof(cmdline), + "diff -c expected/%s.out results/%s.out >> regression.diffs", + testname, testname); + if (system(cmdline) == -1) + printf("# diff failed\n"); + + return 1; +} + + +/* + * Reads file to memory. The file is returned, or NULL if it doesn't exist. + * Length is returned in *len. + */ +static char * +slurpfile(const char *filename, size_t *len) +{ + int fd; + struct stat stbuf; + int readlen; + off_t filelen; + char *p; + +#ifdef WIN32 + fd = open(filename, O_RDONLY | O_BINARY, 0); +#else + fd = open(filename, O_RDONLY, 0); +#endif + if (fd == -1) + { + if (errno == ENOENT) + return NULL; + + bailout("could not open file %s: %s\n", filename, strerror(errno)); + } + if (fstat(fd, &stbuf) < 0) + bailout("fstat failed on file %s: %s\n", filename, strerror(errno)); + + filelen = stbuf.st_size; + p = malloc(filelen + 1); + if (!p) + bailout("out of memory reading file %s\n", filename); + readlen = read(fd, p, filelen); + if (readlen != filelen) + bailout("read only %d bytes out of %d from %s\n", (int) readlen, (int) filelen, filename); + p[readlen] = '\0'; + close(fd); + + *len = readlen; + return p; +} diff --git a/test/sql/sampletables.sql b/test/sampletables.sql similarity index 82% rename from test/sql/sampletables.sql rename to test/sampletables.sql index df774e1c..c29fef2f 100644 --- a/test/sql/sampletables.sql +++ b/test/sampletables.sql @@ -1,5 +1,7 @@ --- This file creates some tables to be used in the tests -SET client_min_messages TO WARNING; +-- This file creates some tables to be used in the tests. +-- +-- Note that the reset-db program that reads this file is dumb and reads +-- it one line at a time. Hence each statement must be on a single line. CREATE TABLE testtab1 (id integer PRIMARY KEY, t varchar(20)); INSERT INTO testtab1 VALUES (1, 'foo'); @@ -31,9 +33,7 @@ INSERT INTO booltab VALUES (4, 'false', false); INSERT INTO booltab VALUES (5, 'not', false); -- Procedure for catalog function checks -CREATE FUNCTION simple_add(in int, in int, out int) -AS $$ SELECT $1 + $2; -$$ LANGUAGE SQL; +CREATE FUNCTION simple_add(in int, in int, out int) AS $$ SELECT $1 + $2; $$ LANGUAGE SQL; -- Large object support CREATE DOMAIN lo AS oid; diff --git a/test/sql/.gitignore b/test/sql/.gitignore deleted file mode 100644 index 77394512..00000000 --- a/test/sql/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.sql -!sampletables.sql diff --git a/test/win.mak b/test/win.mak index 74a2eb64..0445301c 100644 --- a/test/win.mak +++ b/test/win.mak @@ -10,14 +10,8 @@ # # Environment checks -!IF "$(CPU)" == "" -!MESSAGE Making 64bit DLL... -!MESSAGE You should set the CPU environment variable -!MESSAGE to distinguish your OS -!ENDIF !IFNDEF PG_BIN -PG_LIB=C:\develop\bin\$(CPU) !MESSAGE Using default PostgreSQL Binary directory: $(PG_BIN) !ENDIF @@ -32,18 +26,13 @@ PG_LIB=C:\develop\bin\$(CPU) # prefix/suffix to a list in nmake. Removing them is much easier.) TESTS = $(TESTBINS:src/=) TESTS = $(TESTS:-test=) -TESTS = sampletables $(TESTS) -# Now create names of the test .exe and .sql files from the base names +# Now create names of the test .exe from the base names # src\<testname>.exe TESTEXES = $(TESTBINS:-test=-test.exe) TESTEXES = $(TESTEXES:src/=src\) -# sql\<testname>.sql -TESTSQLS = $(TESTBINS:-test=.sql) -TESTSQLS = $(TESTSQLS:src/=sql\) - # Flags CLFLAGS=/D WIN32 @@ -59,25 +48,23 @@ LINKFLAGS=/link odbc32.lib odbccp32.lib .c.exe: cl /Fe.\src\ /Fo.\src\ $*.c src/common.c $(CLFLAGS) $(LINKFLAGS) -all: $(TESTEXES) $(TESTSQLS) +all: $(TESTEXES) runsuite.exe -# A rule to generate sql/<testname>.sql files. The expected output files -# are used as the dependent files, to give nmake a hint on how to build -# them, even though the .sql files don't really depend on the .out files. -{expected\}.out{sql\}.sql: - echo \! "./src/$(*:sql\=)-test" > $*.sql +runsuite.exe: runsuite.c + cl runsuite.c $(CLFLAGS) $(LINKFLAGS) + +reset-db.exe: reset-db.c + cl reset-db.c $(CLFLAGS) $(LINKFLAGS) # activate the above inference rule .SUFFIXES: .out - # Run regression tests -installcheck: - cmd /c $(PG_BIN)\pg_regress --inputdir=. --psqldir="$(PG_BIN)" \ - --dbname="contrib_regression" $(REGRESSOPTS) \ - $(TESTS) +installcheck: runsuite.exe $(TESTEXES) reset-db.exe + del regression.diffs + .\reset-db < sampletables.sql + .\runsuite $(TESTS) clean: -del src\*.exe -del src\*.obj - -del $(TESTSQLS) [parent: be8f057adbc2]