diff --git a/Makefile b/Makefile index f81c355..edceee8 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ MODULE_big = plparrot OBJS= plparrot.o DATA_built = plparrot.sql REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-language=plpgsql -TESTS = $(wildcard t/sql/*.sql) +TESTS = t/sql/test.sql +PLPERL6_TESTS = t/sql/plperl6.sql REGRESS = $(patsubst t/sql/%.sql,%,$(TESTS)) EXTRA_CLEAN = @@ -60,3 +61,6 @@ endif test: all psql -AX -f $(TESTS) + +test_plperl6: all + psql -AX -f $(PLPERL6_TESTS) diff --git a/plparrot.c b/plparrot.c index bf584b4..8d06050 100644 --- a/plparrot.c +++ b/plparrot.c @@ -397,6 +397,9 @@ plperl6u_call_handler(PG_FUNCTION_ARGS) { Datum retval; interp = p6_interp; + if(!interp) { + elog(ERROR,"Invalid Parrot interpreter!"); + } retval = plperl6_call_handler(fcinfo); interp = trusted_interp; return retval; @@ -409,6 +412,9 @@ plperl6_call_handler(PG_FUNCTION_ARGS) TriggerData *tdata; interp = p6_interp; + if(!interp) { + elog(ERROR,"Invalid Parrot interpreter!"); + } PG_TRY(); { if (CALLED_AS_TRIGGER(fcinfo)) { diff --git a/t/sql/plperl6.sql b/t/sql/plperl6.sql new file mode 100644 index 0000000..a406425 --- /dev/null +++ b/t/sql/plperl6.sql @@ -0,0 +1,34 @@ +\unset ECHO +\set QUIET 1 +-- Turn off echo and keep things quiet. +-- Format the output for nice TAP. +\pset format unaligned +\pset tuples_only true +\pset pager +-- Revert all changes on failure. +\set ON_ERROR_ROLLBACK 1 +\set ON_ERROR_STOP true + +-- Load the TAP functions. +BEGIN; +\i pgtap.sql +\i plparrot.sql + +-- Plan the tests. +SELECT plan(3); + +CREATE FUNCTION test_void_plperl6(integer) RETURNS void AS $$ Nil $$ LANGUAGE plperl6; + +CREATE FUNCTION test_int_plperl6(integer) RETURNS int AS $$ 42 $$ LANGUAGE plperl6; + +CREATE FUNCTION test_float_plperl6(integer) RETURNS float AS $$ 5.0 $$ LANGUAGE plperl6; + + +select is(test_int_plperl6(89),42,'Return an integer from PL/Perl6'); +select is(test_void_plperl6(42)::text,''::text,'Return nothing from PL/Perl6'); +select is(test_float_plperl6(2),5.0::float,'Return a float from PL/Perl6'); + +-- Finish the tests and clean up. +SELECT * FROM finish(); + +rollback; diff --git a/t/sql/test.sql b/t/sql/test.sql index 12c12a0..8a41411 100644 --- a/t/sql/test.sql +++ b/t/sql/test.sql @@ -15,7 +15,7 @@ BEGIN; \i plparrot.sql -- Plan the tests. -SELECT plan(33); +SELECT plan(31); CREATE OR REPLACE FUNCTION create_plparrot() RETURNS BOOLEAN @@ -25,12 +25,6 @@ CREATE LANGUAGE plparrot; SELECT true; $$; -CREATE FUNCTION test_void_plperl6(integer) RETURNS void AS $$ Nil $$ LANGUAGE plperl6; - -CREATE FUNCTION test_int_plperl6(integer) RETURNS int AS $$ 42 $$ LANGUAGE plperl6; - -CREATE FUNCTION test_float_plperl6(integer) RETURNS float AS $$ 5.0 $$ LANGUAGE plperl6; - CREATE FUNCTION test_void() RETURNS void AS $$ .return() $$ LANGUAGE plparrot; @@ -266,11 +260,6 @@ select is(test_timestamptz_out('1999-01-08 04:05:06+02'),'1999-01-08 04:05:06+02 select is(test_time_in('04:05:06'),1,'We can pass a time in'); select is(test_time_out('04:05:06'),'04:05:06','We can return a time'); -select is(test_int_plperl6(89),42,'Return an integer from PL/Perl6'); -select is(test_void_plperl6(42)::text,''::text,'Return nothing from PL/Perl6'); -select is(test_float_plperl6(2),5.0::float,'Return a float from PL/Perl6'); - - -- not loading io opcodes, they are deprecated --select isnt(test_open_plparrotu(), 42, 'open opcode is not mocked in plperlu');