Getting rid of regression test input/ and output/ files

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Getting rid of regression test input/ and output/ files
Date: 2021-12-18 23:53:34
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I did some desultory investigation of the idea proposed at [1]
that we should refactor the regression test scripts to try to
reduce their interdependencies. I soon realized that one of
the stumbling blocks to this is that we've tended to concentrate
data-loading COPY commands, as well as C function creation
commands, into a few files to reduce the notational cruft of
substituting path names and the like into the test scripts.
That is, we don't want to have even more scripts that have to be
translated from input/foo.source and output/foo.source into
runnable scripts and test results.

This led me to wonder why we couldn't get rid of that entire
mechanism in favor of some less-painful way of getting that
information into the scripts. If we had the desired values in
psql variables, we could do what we need easily, for example
instead of

CREATE FUNCTION check_primary_key ()
RETURNS trigger
AS '@libdir@/refint(at)DLSUFFIX@'

something like

CREATE FUNCTION check_primary_key ()
RETURNS trigger

(The extra line breaks are needed to convince SQL that the
adjacent string literals should be concatenated. We couldn't
have done this so easily before psql had the :'variable'
notation, but that came in in 9.0.)

I see two ways we could get the info from pg_regress into psql

1. Add "-v VARIABLE=VALUE" switches to the psql invocations.
This requires no new psql capability, but it does introduce
the problem of getting correct shell quoting of the values.
I think we'd need to either duplicate appendShellString in
pg_regress.c, or start linking both libpq and libpgfeutils.a
into pg_regress to be able to use appendShellString itself.
In the past we've not wanted to link libpq into pg_regress
(though I admit I've forgotten the argument for not doing so).

2. Export the values from pg_regress as environment variables,
and then add a way for the test scripts to read those variables.
I was a bit surprised to realize that we didn't have any way
to do that already --- psql has \setenv, so why did we never
invent \getenv?

On the whole I prefer #2, as it seems cleaner and it adds some
actually useful-to-end-users psql functionality.

Attached is a really incomplete, quick-n-dirty POC showing that
this can be made to work. If there aren't objections or better
ideas, I'll see about fleshing this out.

regards, tom lane


Attachment Content-Type Size
pass-paths-to-tests-as-envvars-wip.patch text/x-diff 5.7 KB


Browse pgsql-hackers by date

  From Date Subject
Next Message Maciek Sakrejda 2021-12-19 00:31:42 Re: should we document an example to set multiple libraries in shared_preload_libraries?
Previous Message Justin Pryzby 2021-12-18 22:10:42 Re: [PATCH] psql: \dn+ to show size of each schema (and \dA+ for AMs)