Getting rid of regression test input/ and output/ files
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2021-12-18T23:53:34Z
Lists: pgsql-hackers
Attachments
- pass-paths-to-tests-as-envvars-wip.patch (text/x-diff) patch
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@DLSUFFIX@' LANGUAGE C; something like CREATE FUNCTION check_primary_key () RETURNS trigger AS :'LIBDIR' '/refint' :'DLSUFFIX' LANGUAGE C; (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 variables: 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 [1] https://www.postgresql.org/message-id/20211217182518.GA2529654%40rfd.leadboat.com
Commits
-
Merge dblink's paths test script into its main test.
- 0e6e7f0806b2 15.0 landed
-
Remove dynamic translation of regression test scripts, step 2.
- dc9c3b0ff214 15.0 landed
-
Remove dynamic translation of regression test scripts, step 1.
- d1029bb5a26c 15.0 landed
-
Add a \getenv command to psql.
- 33d3eeadb21d 15.0 landed