Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix and test the trustedness of languages; update pgTAP Lite
  • Loading branch information
leto committed Aug 5, 2010
1 parent 706b7dc commit 9964752
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
19 changes: 19 additions & 0 deletions pgtap.sql
Expand Up @@ -1514,3 +1514,22 @@ CREATE OR REPLACE FUNCTION isa_ok( anyelement, regtype )
RETURNS TEXT AS $$
SELECT isa_ok($1, $2, 'the value');
$$ LANGUAGE sql;

CREATE OR REPLACE FUNCTION _is_trusted( NAME )
RETURNS BOOLEAN AS $$
SELECT lanpltrusted FROM pg_catalog.pg_language WHERE lanname = $1;
$$ LANGUAGE SQL;

-- language_is_trusted( language, description )
CREATE OR REPLACE FUNCTION language_is_trusted( NAME, TEXT )
RETURNS TEXT AS $$
DECLARE
is_trusted boolean := _is_trusted($1);
BEGIN
IF is_trusted IS NULL THEN
RETURN fail( $2 ) || E'\n' || diag( ' Procedural language ' || quote_ident($1) || ' does not exist') ;
END IF;
RETURN ok( is_trusted, $2 );
END;
$$ LANGUAGE plpgsql;

6 changes: 3 additions & 3 deletions plparrot.sql.in
Expand Up @@ -16,22 +16,22 @@ RETURNS language_handler AS 'MODULE_PATHNAME' LANGUAGE C;

-- language
DROP LANGUAGE IF EXISTS plparrot CASCADE;
CREATE LANGUAGE plparrot HANDLER plparrot_call_handler;
CREATE trusted LANGUAGE plparrot HANDLER plparrot_call_handler;

-- language
DROP LANGUAGE IF EXISTS plparrotu CASCADE;
CREATE LANGUAGE plparrotu HANDLER plparrotu_call_handler;

-- plpir is an alias for plparrot
DROP LANGUAGE IF EXISTS plpir CASCADE;
CREATE LANGUAGE plpir HANDLER plparrot_call_handler;
CREATE trusted LANGUAGE plpir HANDLER plparrot_call_handler;

-- plpiru is an alias for plparrotu
DROP LANGUAGE IF EXISTS plpiru CASCADE;
CREATE LANGUAGE plpiru HANDLER plparrotu_call_handler;

DROP LANGUAGE IF EXISTS plperl6 CASCADE;
CREATE LANGUAGE plperl6 HANDLER plperl6_call_handler;
CREATE trusted LANGUAGE plperl6 HANDLER plperl6_call_handler;

DROP LANGUAGE IF EXISTS plperl6u CASCADE;
CREATE LANGUAGE plperl6u HANDLER plperl6u_call_handler;
4 changes: 3 additions & 1 deletion t/sql/plperl6.sql
Expand Up @@ -15,7 +15,7 @@ BEGIN;
\i plparrot.sql

-- Plan the tests.
SELECT plan(12);
SELECT plan(13);

CREATE OR REPLACE FUNCTION test_void_plperl6(integer) RETURNS void LANGUAGE plperl6 AS $$
Nil
Expand Down Expand Up @@ -79,6 +79,8 @@ select is(test_2arguments_plperl6(4,9),2,'PL/Perl sees multiple arguments');

select is(test_named_pointy(10,20,30), 6000, 'Pointy blocks with named parameters work');

SELECT language_is_trusted( 'plperl6', 'PL/Perl6 should be trusted' );

-- Finish the tests and clean up.
SELECT * FROM finish();

Expand Down
15 changes: 5 additions & 10 deletions t/sql/test.sql
Expand Up @@ -7,6 +7,7 @@
\pset pager
-- Revert all changes on failure.
\set ON_ERROR_ROLLBACK 1

\set ON_ERROR_STOP true

-- Load the TAP functions.
Expand All @@ -15,16 +16,7 @@ BEGIN;
\i plparrot.sql

-- Plan the tests.
SELECT plan(31);

CREATE OR REPLACE FUNCTION create_plparrot()
RETURNS BOOLEAN
LANGUAGE SQL
AS $$
DROP LANGUAGE IF EXISTS plparrot CASCADE;
CREATE LANGUAGE plparrot;
SELECT true;
$$;
SELECT plan(33);

CREATE OR REPLACE FUNCTION test_void() RETURNS void AS $$
.return()
Expand Down Expand Up @@ -264,6 +256,9 @@ select is(test_time_out('04:05:06'),'04:05:06','We can return a time');
-- not loading io opcodes, they are deprecated
--select isnt(test_open_plparrotu(), 42, 'open opcode is not mocked in plperlu');

SELECT language_is_trusted( 'plparrot', 'PL/Parrot should be trusted' );
SELECT language_is_trusted( 'plpir', 'PL/PIR should be trusted' );

-- Finish the tests and clean up.
SELECT * FROM finish();

Expand Down

0 comments on commit 9964752

Please sign in to comment.