mirror of https://github.com/postgres/postgres
pg_regress has long had provisions for dynamically substituting path names into regression test scripts and result files, but use of that feature has always been a serious pain in the neck, mainly because updating the result files requires tedious manual editing. Let's get rid of that in favor of passing down the paths in environment variables. In addition to being easier to maintain, this way is capable of dealing with path names that require escaping at runtime, for example paths containing single-quote marks. (There are other stumbling blocks in the way of actually building in a path that looks like that, but removing this one seems like a good thing to do.) The key coding rule that makes that possible is to concatenate pieces of a dynamically-variable string using psql's \set command, and then use the :'variable' notation to quote and escape the string for the next level of interpretation. In hopes of making this change more transparent to "git blame", I've split it into two steps. This commit adds the necessary pg_regress.c support and changes all the *.source files in-place so that they no longer require any dynamic translation. The next commit will just "git mv" them into the regular sql/ and expected/ directories. Discussion: https://postgr.es/m/1655733.1639871614@sss.pgh.pa.uspull/138/head
parent
33d3eeadb2
commit
d1029bb5a2
@ -1,14 +1,23 @@ |
|||||||
-- Initialization that requires path substitution. |
-- Initialization that requires path substitution. |
||||||
|
|
||||||
|
-- directory paths and dlsuffix are passed to us in environment variables |
||||||
|
\getenv abs_srcdir PG_ABS_SRCDIR |
||||||
|
\getenv libdir PG_LIBDIR |
||||||
|
\getenv dlsuffix PG_DLSUFFIX |
||||||
|
|
||||||
|
\set regresslib :libdir '/regress' :dlsuffix |
||||||
|
|
||||||
CREATE FUNCTION setenv(text, text) |
CREATE FUNCTION setenv(text, text) |
||||||
RETURNS void |
RETURNS void |
||||||
AS '@libdir@/regress@DLSUFFIX@', 'regress_setenv' |
AS :'regresslib', 'regress_setenv' |
||||||
LANGUAGE C STRICT; |
LANGUAGE C STRICT; |
||||||
|
|
||||||
CREATE FUNCTION wait_pid(int) |
CREATE FUNCTION wait_pid(int) |
||||||
RETURNS void |
RETURNS void |
||||||
AS '@libdir@/regress@DLSUFFIX@' |
AS :'regresslib' |
||||||
LANGUAGE C STRICT; |
LANGUAGE C STRICT; |
||||||
|
|
||||||
|
\set path :abs_srcdir '/' |
||||||
|
\set fnbody 'SELECT setenv(''PGSERVICEFILE'', ' :'path' ' || $1)' |
||||||
CREATE FUNCTION set_pgservicefile(text) RETURNS void LANGUAGE SQL |
CREATE FUNCTION set_pgservicefile(text) RETURNS void LANGUAGE SQL |
||||||
AS $$SELECT setenv('PGSERVICEFILE', '@abs_srcdir@/' || $1)$$; |
AS :'fnbody'; |
||||||
|
@ -1,11 +1,18 @@ |
|||||||
-- Initialization that requires path substitution. |
-- Initialization that requires path substitution. |
||||||
|
-- directory paths and dlsuffix are passed to us in environment variables |
||||||
|
\getenv abs_srcdir PG_ABS_SRCDIR |
||||||
|
\getenv libdir PG_LIBDIR |
||||||
|
\getenv dlsuffix PG_DLSUFFIX |
||||||
|
\set regresslib :libdir '/regress' :dlsuffix |
||||||
CREATE FUNCTION setenv(text, text) |
CREATE FUNCTION setenv(text, text) |
||||||
RETURNS void |
RETURNS void |
||||||
AS '@libdir@/regress@DLSUFFIX@', 'regress_setenv' |
AS :'regresslib', 'regress_setenv' |
||||||
LANGUAGE C STRICT; |
LANGUAGE C STRICT; |
||||||
CREATE FUNCTION wait_pid(int) |
CREATE FUNCTION wait_pid(int) |
||||||
RETURNS void |
RETURNS void |
||||||
AS '@libdir@/regress@DLSUFFIX@' |
AS :'regresslib' |
||||||
LANGUAGE C STRICT; |
LANGUAGE C STRICT; |
||||||
|
\set path :abs_srcdir '/' |
||||||
|
\set fnbody 'SELECT setenv(''PGSERVICEFILE'', ' :'path' ' || $1)' |
||||||
CREATE FUNCTION set_pgservicefile(text) RETURNS void LANGUAGE SQL |
CREATE FUNCTION set_pgservicefile(text) RETURNS void LANGUAGE SQL |
||||||
AS $$SELECT setenv('PGSERVICEFILE', '@abs_srcdir@/' || $1)$$; |
AS :'fnbody'; |
||||||
|
@ -1,26 +1,30 @@ |
|||||||
-- |
-- |
||||||
-- CREATE_FUNCTION_1 |
-- CREATE_FUNCTION_1 |
||||||
-- |
-- |
||||||
|
-- directory path and dlsuffix are passed to us in environment variables |
||||||
|
\getenv libdir PG_LIBDIR |
||||||
|
\getenv dlsuffix PG_DLSUFFIX |
||||||
|
\set regresslib :libdir '/regress' :dlsuffix |
||||||
-- Create C functions needed by create_type.sql |
-- Create C functions needed by create_type.sql |
||||||
CREATE FUNCTION widget_in(cstring) |
CREATE FUNCTION widget_in(cstring) |
||||||
RETURNS widget |
RETURNS widget |
||||||
AS '@libdir@/regress@DLSUFFIX@' |
AS :'regresslib' |
||||||
LANGUAGE C STRICT IMMUTABLE; |
LANGUAGE C STRICT IMMUTABLE; |
||||||
NOTICE: type "widget" is not yet defined |
NOTICE: type "widget" is not yet defined |
||||||
DETAIL: Creating a shell type definition. |
DETAIL: Creating a shell type definition. |
||||||
CREATE FUNCTION widget_out(widget) |
CREATE FUNCTION widget_out(widget) |
||||||
RETURNS cstring |
RETURNS cstring |
||||||
AS '@libdir@/regress@DLSUFFIX@' |
AS :'regresslib' |
||||||
LANGUAGE C STRICT IMMUTABLE; |
LANGUAGE C STRICT IMMUTABLE; |
||||||
NOTICE: argument type widget is only a shell |
NOTICE: argument type widget is only a shell |
||||||
CREATE FUNCTION int44in(cstring) |
CREATE FUNCTION int44in(cstring) |
||||||
RETURNS city_budget |
RETURNS city_budget |
||||||
AS '@libdir@/regress@DLSUFFIX@' |
AS :'regresslib' |
||||||
LANGUAGE C STRICT IMMUTABLE; |
LANGUAGE C STRICT IMMUTABLE; |
||||||
NOTICE: type "city_budget" is not yet defined |
NOTICE: type "city_budget" is not yet defined |
||||||
DETAIL: Creating a shell type definition. |
DETAIL: Creating a shell type definition. |
||||||
CREATE FUNCTION int44out(city_budget) |
CREATE FUNCTION int44out(city_budget) |
||||||
RETURNS cstring |
RETURNS cstring |
||||||
AS '@libdir@/regress@DLSUFFIX@' |
AS :'regresslib' |
||||||
LANGUAGE C STRICT IMMUTABLE; |
LANGUAGE C STRICT IMMUTABLE; |
||||||
NOTICE: argument type city_budget is only a shell |
NOTICE: argument type city_budget is only a shell |
||||||
|
Loading…
Reference in new issue