Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix and test the trustedness of languages; update pgTAP Lite

  • Loading branch information...
commit 996475214096cb1e3243b575b20d4143cc76fe05 1 parent 706b7dc
@leto authored
Showing with 30 additions and 14 deletions.
  1. +19 −0 pgtap.sql
  2. +3 −3 plparrot.sql.in
  3. +3 −1 t/sql/plperl6.sql
  4. +5 −10 t/sql/test.sql
View
19 pgtap.sql
@@ -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;
+
View
6 plparrot.sql.in
@@ -16,7 +16,7 @@ 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;
@@ -24,14 +24,14 @@ 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;
View
4 t/sql/plperl6.sql
@@ -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
@@ -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();
View
15 t/sql/test.sql
@@ -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.
@@ -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()
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.