]> granicus.if.org Git - postgresql/commitdiff
Start a separate test suite for plpgsql
authorPeter Eisentraut <peter_e@gmx.net>
Thu, 7 Dec 2017 19:03:29 +0000 (14:03 -0500)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 13 Dec 2017 16:02:29 +0000 (11:02 -0500)
The plpgsql.sql test file in the main regression tests is now by far the
largest after numeric_big, making editing and managing the test cases
very cumbersome.  The other PLs have their own test suites split up into
smaller files by topic.  It would be nice to have that for plpgsql as
well.  So, to get that started, set up test infrastructure in
src/pl/plpgsql/src/ and split out the recently added procedure test
cases into a new file there.  That file now mirrors the test cases added
to the other PLs, making managing those matching tests a bit easier too.

msvc build system changes with help from Michael Paquier

src/pl/plpgsql/src/.gitignore
src/pl/plpgsql/src/Makefile
src/pl/plpgsql/src/expected/plpgsql_call.out [new file with mode: 0644]
src/pl/plpgsql/src/sql/plpgsql_call.sql [new file with mode: 0644]
src/test/regress/expected/plpgsql.out
src/test/regress/sql/plpgsql.sql
src/tools/msvc/vcregress.pl

index 92387fa3cb1635ea212cc21dcb631c326524810c..ff6ac965fddf1db7d78888b2132c2133b6289035 100644 (file)
@@ -1,3 +1,6 @@
 /pl_gram.c
 /pl_gram.h
 /plerrcodes.h
+/log/
+/results/
+/tmp_check/
index 95348179ac336dfd572f5a27955c375546bb42e5..64991c3115ac7c793df87088c61c274c5c28304e 100644 (file)
@@ -24,6 +24,8 @@ OBJS = pl_gram.o pl_handler.o pl_comp.o pl_exec.o \
 
 DATA = plpgsql.control plpgsql--1.0.sql plpgsql--unpackaged--1.0.sql
 
+REGRESS = plpgsql_call
+
 all: all-lib
 
 # Shared library stuff
@@ -65,6 +67,18 @@ pl_gram.c: BISONFLAGS += -d
 plerrcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-plerrcodes.pl
        $(PERL) $(srcdir)/generate-plerrcodes.pl $< > $@
 
+
+check: submake
+       $(pg_regress_check) $(REGRESS_OPTS) $(REGRESS)
+
+installcheck: submake
+       $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)
+
+.PHONY: submake
+submake:
+       $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
+
+
 distprep: pl_gram.h pl_gram.c plerrcodes.h
 
 # pl_gram.c, pl_gram.h and plerrcodes.h are in the distribution tarball,
diff --git a/src/pl/plpgsql/src/expected/plpgsql_call.out b/src/pl/plpgsql/src/expected/plpgsql_call.out
new file mode 100644 (file)
index 0000000..d0f3516
--- /dev/null
@@ -0,0 +1,41 @@
+--
+-- Tests for procedures / CALL syntax
+--
+CREATE PROCEDURE test_proc1()
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    NULL;
+END;
+$$;
+CALL test_proc1();
+-- error: can't return non-NULL
+CREATE PROCEDURE test_proc2()
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN 5;
+END;
+$$;
+CALL test_proc2();
+ERROR:  cannot return a value from a procedure
+CONTEXT:  PL/pgSQL function test_proc2() while casting return value to function's return type
+CREATE TABLE test1 (a int);
+CREATE PROCEDURE test_proc3(x int)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    INSERT INTO test1 VALUES (x);
+END;
+$$;
+CALL test_proc3(55);
+SELECT * FROM test1;
+ a  
+----
+ 55
+(1 row)
+
+DROP PROCEDURE test_proc1;
+DROP PROCEDURE test_proc2;
+DROP PROCEDURE test_proc3;
+DROP TABLE test1;
diff --git a/src/pl/plpgsql/src/sql/plpgsql_call.sql b/src/pl/plpgsql/src/sql/plpgsql_call.sql
new file mode 100644 (file)
index 0000000..38fd220
--- /dev/null
@@ -0,0 +1,47 @@
+--
+-- Tests for procedures / CALL syntax
+--
+
+CREATE PROCEDURE test_proc1()
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    NULL;
+END;
+$$;
+
+CALL test_proc1();
+
+
+-- error: can't return non-NULL
+CREATE PROCEDURE test_proc2()
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN 5;
+END;
+$$;
+
+CALL test_proc2();
+
+
+CREATE TABLE test1 (a int);
+
+CREATE PROCEDURE test_proc3(x int)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    INSERT INTO test1 VALUES (x);
+END;
+$$;
+
+CALL test_proc3(55);
+
+SELECT * FROM test1;
+
+
+DROP PROCEDURE test_proc1;
+DROP PROCEDURE test_proc2;
+DROP PROCEDURE test_proc3;
+
+DROP TABLE test1;
index 26f6e4394f47ace9340b9306a7476f5063026cb9..a2df411132bc0cb3163bc37b115a2e3b79b18e1e 100644 (file)
@@ -6067,44 +6067,3 @@ END; $$ LANGUAGE plpgsql;
 ERROR:  "x" is not a scalar variable
 LINE 3:   GET DIAGNOSTICS x = ROW_COUNT;
                           ^
---
--- Procedures
---
-CREATE PROCEDURE test_proc1()
-LANGUAGE plpgsql
-AS $$
-BEGIN
-    NULL;
-END;
-$$;
-CALL test_proc1();
--- error: can't return non-NULL
-CREATE PROCEDURE test_proc2()
-LANGUAGE plpgsql
-AS $$
-BEGIN
-    RETURN 5;
-END;
-$$;
-CALL test_proc2();
-ERROR:  cannot return a value from a procedure
-CONTEXT:  PL/pgSQL function test_proc2() while casting return value to function's return type
-CREATE TABLE proc_test1 (a int);
-CREATE PROCEDURE test_proc3(x int)
-LANGUAGE plpgsql
-AS $$
-BEGIN
-    INSERT INTO proc_test1 VALUES (x);
-END;
-$$;
-CALL test_proc3(55);
-SELECT * FROM proc_test1;
- a  
-----
- 55
-(1 row)
-
-DROP PROCEDURE test_proc1;
-DROP PROCEDURE test_proc2;
-DROP PROCEDURE test_proc3;
-DROP TABLE proc_test1;
index bb09b2d807195973766b871029888ee1705c2c27..02c89138019161fb513f39cf303843465d8afa4f 100644 (file)
@@ -4843,52 +4843,3 @@ BEGIN
   GET DIAGNOSTICS x = ROW_COUNT;
   RETURN;
 END; $$ LANGUAGE plpgsql;
-
-
---
--- Procedures
---
-
-CREATE PROCEDURE test_proc1()
-LANGUAGE plpgsql
-AS $$
-BEGIN
-    NULL;
-END;
-$$;
-
-CALL test_proc1();
-
-
--- error: can't return non-NULL
-CREATE PROCEDURE test_proc2()
-LANGUAGE plpgsql
-AS $$
-BEGIN
-    RETURN 5;
-END;
-$$;
-
-CALL test_proc2();
-
-
-CREATE TABLE proc_test1 (a int);
-
-CREATE PROCEDURE test_proc3(x int)
-LANGUAGE plpgsql
-AS $$
-BEGIN
-    INSERT INTO proc_test1 VALUES (x);
-END;
-$$;
-
-CALL test_proc3(55);
-
-SELECT * FROM proc_test1;
-
-
-DROP PROCEDURE test_proc1;
-DROP PROCEDURE test_proc2;
-DROP PROCEDURE test_proc3;
-
-DROP TABLE proc_test1;
index 719fe830476015dbbbee3c778dbea2390c21030f..314f2c37d2b6e81ec2a40e0a659da01f08c4b408 100644 (file)
@@ -248,23 +248,32 @@ sub taptest
 
 sub plcheck
 {
-       chdir "../../pl";
+       chdir "$topdir/src/pl";
 
-       foreach my $pl (glob("*"))
+       foreach my $dir (glob("*/src *"))
        {
-               next unless -d "$pl/sql" && -d "$pl/expected";
-               my $lang = $pl eq 'tcl' ? 'pltcl' : $pl;
+               next unless -d "$dir/sql" && -d "$dir/expected";
+               my $lang;
+               if ($dir eq 'plpgsql/src') {
+                       $lang = 'plpgsql';
+               }
+               elsif ($dir eq 'tcl') {
+                       $lang = 'pltcl';
+               }
+               else {
+                       $lang = $dir;
+               }
                if ($lang eq 'plpython')
                {
-                       next unless -d "../../$Config/plpython2";
+                       next unless -d "$topdir/$Config/plpython2";
                        $lang = 'plpythonu';
                }
                else
                {
-                       next unless -d "../../$Config/$lang";
+                       next unless -d "$topdir/$Config/$lang";
                }
                my @lang_args = ("--load-extension=$lang");
-               chdir $pl;
+               chdir $dir;
                my @tests = fetchTests();
                if ($lang eq 'plperl')
                {
@@ -285,16 +294,16 @@ sub plcheck
                  "============================================================\n";
                print "Checking $lang\n";
                my @args = (
-                       "../../../$Config/pg_regress/pg_regress",
-                       "--bindir=../../../$Config/psql",
+                       "$topdir/$Config/pg_regress/pg_regress",
+                       "--bindir=$topdir/$Config/psql",
                        "--dbname=pl_regression", @lang_args, @tests);
                system(@args);
                my $status = $? >> 8;
                exit $status if $status;
-               chdir "..";
+               chdir "$topdir/src/pl";
        }
 
-       chdir "../../..";
+       chdir "$topdir";
 }
 
 sub subdircheck