On Thu, Feb 18, 2010 at 06:27:30PM -0500, Tom Lane wrote:
> David Fetter <da...@fetter.org> writes:
> > While hacking on PL/Parrot, I ran across an issue where when
> > trying to load PL/pgsql, it's done unconditionally and fails.  How
> > do we fix pg_regress to be a little more subtle about this?
> 
> Why exactly would we want it to not fail?  Regression tests are not
> about papering over problems.

OK, I know it's late, but having PL/pgsql on by default has caused an
unforeseen need: --require-language.

Please find enclosed a patch which implements this.

Cheers,
David.
-- 
David Fetter <da...@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fet...@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 991bb17..fbf821d 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -85,6 +85,7 @@ char     *inputdir = ".";
 char      *outputdir = ".";
 char      *psqldir = PGBINDIR;
 static _stringlist *loadlanguage = NULL;
+static _stringlist *requirelanguage = NULL;
 static int     max_connections = 0;
 static char *encoding = NULL;
 static _stringlist *schedulelist = NULL;
@@ -1798,6 +1799,24 @@ create_database(const char *dbname)
                header(_("installing %s"), sl->str);
                psql_command(dbname, "CREATE LANGUAGE \"%s\"", sl->str);
        }
+
+       /*
+        * Make sure any required procedural languages are installed.
+        */
+       for (sl = requirelanguage; sl != NULL; sl = sl->next)
+       {
+               header(_("making sure %s is installed"), sl->str);
+               psql_command(dbname,
+                               "DO LANGUAGE plpgsql $$"
+                               "BEGIN"
+                               "    IF NOT EXISTS"
+                               "        (SELECT 1 FROM pg_catalog.pg_language 
WHERE lanname='%s')"
+                               "    THEN"
+                               "        CREATE LANGUAGE %s;"
+                               "    END IF;"
+                               "END"
+                               "$$", sl->str, sl->str);
+       }
 }
 
 static void
@@ -1860,6 +1879,8 @@ help(void)
        printf(_("  --inputdir=DIR            take input files from DIR 
(default \".\")\n"));
        printf(_("  --load-language=lang      load the named language before 
running the\n"));
        printf(_("                            tests; can appear multiple 
times\n"));
+       printf(_("  --require-language=lang   make sure the named language is 
loaded before\n"));
+       printf(_("                            running the tests; can appear 
multiple times\n"));
        printf(_("  --create-role=ROLE        create the specified role before 
testing\n"));
        printf(_("  --max-connections=N       maximum number of concurrent 
connections\n"));
        printf(_("                            (default is 0 meaning 
unlimited)\n"));
@@ -1920,6 +1941,7 @@ regression_main(int argc, char *argv[], init_function 
ifunc, test_function tfunc
                {"create-role", required_argument, NULL, 18},
                {"temp-config", required_argument, NULL, 19},
                {"use-existing", no_argument, NULL, 20},
+               {"require-language", required_argument, NULL, 21},
                {NULL, 0, NULL, 0}
        };
 
@@ -2013,6 +2035,9 @@ regression_main(int argc, char *argv[], init_function 
ifunc, test_function tfunc
                        case 20:
                                use_existing = true;
                                break;
+                       case 21:
+                               add_stringlist_item(&requirelanguage, optarg);
+                               break;
                        default:
                                /* getopt_long already emitted a complaint */
                                fprintf(stderr, _("\nTry \"%s -h\" for more 
information.\n"),
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to