aboutsummaryrefslogtreecommitdiff
path: root/src/test/perl/PostgreSQL/Test
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-12-23 11:50:33 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-12-23 11:50:33 -0500
commitda44ff312ea3b2868b8fab68944017cb56427709 (patch)
tree3434d3e1bf0faec241030e9a44c54ee93c45e13a /src/test/perl/PostgreSQL/Test
parent3e2e0d5ad7fcb89d18a71cbfc885ef184e1b6f2e (diff)
downloadpostgresql-da44ff312ea3b2868b8fab68944017cb56427709.tar.gz
postgresql-da44ff312ea3b2868b8fab68944017cb56427709.zip
Set readline-relevant ENV vars in interactive_psql(), not caller.
Commit 664d75753 pulled 010_tab_completion.pl's infrastructure for invoking an interactive psql session out into a generally-useful test function, but it didn't move enough stuff. We need to set up various environment variables that readline will look at, both to ensure stability of test results and to prevent test actions from cluttering the calling user's ~/.psql_history. Expecting calling scripts to remember to do that is too failure-prone: the other existing caller 001_password.pl did not do it. Hence, remove those initialization steps from 010_tab_completion.pl and put them into interactive_psql(). Since interactive_psql was already making a local ENV hash, this has no effect on calling scripts. Discussion: https://postgr.es/m/794610.1703182896@sss.pgh.pa.us
Diffstat (limited to 'src/test/perl/PostgreSQL/Test')
-rw-r--r--src/test/perl/PostgreSQL/Test/Cluster.pm28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm
index f43e54282f2..b0777e2724d 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -2128,14 +2128,17 @@ Errors occurring later are the caller's problem.
Be sure to "quit" the returned object when done with it.
-The only extra parameter currently accepted is
-
=over
=item extra_params => ['--single-transaction']
If given, it must be an array reference containing additional parameters to B<psql>.
+=item history_file => B<path>
+
+Cause the interactive B<psql> session to write its command history to B<path>.
+If not given, the history is sent to B</dev/null>.
+
=back
This requires IO::Pty in addition to IPC::Run.
@@ -2148,6 +2151,27 @@ sub interactive_psql
local %ENV = $self->_get_env();
+ # Since the invoked psql will believe it's interactive, it will use
+ # readline/libedit if available. We need to adjust some environment
+ # settings to prevent unwanted side-effects.
+
+ # Developers would not appreciate tests adding a bunch of junk to
+ # their ~/.psql_history, so redirect readline history somewhere else.
+ # If the calling script doesn't specify anything, just bit-bucket it.
+ $ENV{PSQL_HISTORY} = $params{history_file} || '/dev/null';
+
+ # Another pitfall for developers is that they might have a ~/.inputrc
+ # file that changes readline's behavior enough to affect the test.
+ # So ignore any such file.
+ $ENV{INPUTRC} = '/dev/null';
+
+ # Unset TERM so that readline/libedit won't use any terminal-dependent
+ # escape sequences; that leads to way too many cross-version variations
+ # in the output.
+ delete $ENV{TERM};
+ # Some versions of readline inspect LS_COLORS, so for luck unset that too.
+ delete $ENV{LS_COLORS};
+
my @psql_params = (
$self->installed_command('psql'),
'-XAt', '-d', $self->connstr($dbname));