plperl tests for currently untested features - Mailing list pgsql-patches
From | Andrew Dunstan |
---|---|
Subject | plperl tests for currently untested features |
Date | |
Msg-id | 4292563C.809@dunslane.net Whole thread Raw |
Responses |
Re: plperl tests for currently untested features
Re: plperl tests for currently untested features |
List | pgsql-patches |
continuing my quest for better testing ... ;-) The current plperl regression tests do not test the trigger or shared data features. The attached new files remedy that: sql/plperl_trigger.sql sql/plperl_shared.sql expected/plperl_trigger.out expected/plperl_shared.out The corresponding patch for GNUmakefile is below Is it worth supplying a more descriptive name to the current plperl.sql test script? cheers andrew Index: GNUmakefile =================================================================== RCS file: /projects/cvsroot/pgsql/src/pl/plperl/GNUmakefile,v retrieving revision 1.20 diff -c -r1.20 GNUmakefile *** GNUmakefile 17 May 2005 18:26:22 -0000 1.20 --- GNUmakefile 23 May 2005 22:08:07 -0000 *************** *** 37,43 **** SHLIB_LINK = $(perl_embed_ldflags) $(BE_DLLLIBS) REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-language=plperl ! REGRESS = plperl include $(top_srcdir)/src/Makefile.shlib --- 37,43 ---- SHLIB_LINK = $(perl_embed_ldflags) $(BE_DLLLIBS) REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-language=plperl ! REGRESS = plperl plperl_trigger plperl_shared include $(top_srcdir)/src/Makefile.shlib -- test the shared hash create function setme(key text, val text) returns void language plperl as $$ my $key = shift; my $val = shift; $_SHARED{$key}= $val; $$; create function getme(key text) returns text language plperl as $$ my $key = shift; return $_SHARED{$key}; $$; select setme('ourkey','ourval'); select getme('ourkey'); -- test plperl triggers CREATE TABLE trigger_test ( i int, v varchar ); CREATE OR REPLACE FUNCTION valid_id() RETURNS trigger AS $$ if (($_TD->{new}{i}>=100) || ($_TD->{new}{i}<=0)) { return "SKIP"; # Skip INSERT/UPDATE command } elsif ($_TD->{new}{v} ne "immortal") { $_TD->{new}{v} .= "(modified by trigger)"; return "MODIFY"; # Modify tuple and proceed INSERT/UPDATE command } else { return; # Proceed INSERT/UPDATE command } $$ LANGUAGE plperl; CREATE TRIGGER "test_valid_id_trig" BEFORE INSERT OR UPDATE ON trigger_test FOR EACH ROW EXECUTE PROCEDURE "valid_id"(); INSERT INTO trigger_test (i, v) VALUES (1,'first line'); INSERT INTO trigger_test (i, v) VALUES (2,'second line'); INSERT INTO trigger_test (i, v) VALUES (3,'third line'); INSERT INTO trigger_test (i, v) VALUES (4,'immortal'); INSERT INTO trigger_test (i, v) VALUES (101,'bad id'); SELECT * FROM trigger_test; UPDATE trigger_test SET i = 5 where i=3; UPDATE trigger_test SET i = 100 where i=1; SELECT * FROM trigger_test; CREATE OR REPLACE FUNCTION immortal() RETURNS trigger AS $$ if ($_TD->{old}{v} eq $_TD->{args}[0]) { return "SKIP"; # Skip DELETE command } else { return; # Proceed DELETE command }; $$ LANGUAGE plperl; CREATE TRIGGER "immortal_trig" BEFORE DELETE ON trigger_test FOR EACH ROW EXECUTE PROCEDURE immortal('immortal'); DELETE FROM trigger_test; SELECT * FROM trigger_test; -- test the shared hash create function setme(key text, val text) returns void language plperl as $$ my $key = shift; my $val = shift; $_SHARED{$key}= $val; $$; create function getme(key text) returns text language plperl as $$ my $key = shift; return $_SHARED{$key}; $$; select setme('ourkey','ourval'); setme ------- (1 row) select getme('ourkey'); getme -------- ourval (1 row) -- test plperl triggers CREATE TABLE trigger_test ( i int, v varchar ); CREATE OR REPLACE FUNCTION valid_id() RETURNS trigger AS $$ if (($_TD->{new}{i}>=100) || ($_TD->{new}{i}<=0)) { return "SKIP"; # Skip INSERT/UPDATE command } elsif ($_TD->{new}{v} ne "immortal") { $_TD->{new}{v} .= "(modified by trigger)"; return "MODIFY"; # Modify tuple and proceed INSERT/UPDATE command } else { return; # Proceed INSERT/UPDATE command } $$ LANGUAGE plperl; CREATE TRIGGER "test_valid_id_trig" BEFORE INSERT OR UPDATE ON trigger_test FOR EACH ROW EXECUTE PROCEDURE "valid_id"(); INSERT INTO trigger_test (i, v) VALUES (1,'first line'); INSERT INTO trigger_test (i, v) VALUES (2,'second line'); INSERT INTO trigger_test (i, v) VALUES (3,'third line'); INSERT INTO trigger_test (i, v) VALUES (4,'immortal'); INSERT INTO trigger_test (i, v) VALUES (101,'bad id'); SELECT * FROM trigger_test; i | v ---+---------------------------------- 1 | first line(modified by trigger) 2 | second line(modified by trigger) 3 | third line(modified by trigger) 4 | immortal (4 rows) UPDATE trigger_test SET i = 5 where i=3; UPDATE trigger_test SET i = 100 where i=1; SELECT * FROM trigger_test; i | v ---+------------------------------------------------------ 1 | first line(modified by trigger) 2 | second line(modified by trigger) 4 | immortal 5 | third line(modified by trigger)(modified by trigger) (4 rows) CREATE OR REPLACE FUNCTION immortal() RETURNS trigger AS $$ if ($_TD->{old}{v} eq $_TD->{args}[0]) { return "SKIP"; # Skip DELETE command } else { return; # Proceed DELETE command }; $$ LANGUAGE plperl; CREATE TRIGGER "immortal_trig" BEFORE DELETE ON trigger_test FOR EACH ROW EXECUTE PROCEDURE immortal('immortal'); DELETE FROM trigger_test; SELECT * FROM trigger_test; i | v ---+---------- 4 | immortal (1 row)
pgsql-patches by date: