Avoid reading ~/.inputrc in tab-completion test, and revert other changes.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 5 Jan 2020 02:33:34 +0000 (21:33 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 5 Jan 2020 02:33:34 +0000 (21:33 -0500)
The true explanation for Peter Geoghegan's trouble report turns out
to be that he has a ~/.inputrc that affects readline's behavior
enough to break this test.  Prevent readline from reading that file.

Also, the best way to prevent TERM from affecting the results seems
to be to unset it altogether, not to set it to "xterm".  The latter
choice licenses readline to emit xterm escape sequences, and there's
a lot of variation in exactly what it will emit.

Revert changes that attempted to account exactly for xterm escape
sequences.  We shouldn't need that with TERM unset, and it was not
looking like a maintainable solution anyway.

Discussion: https://postgr.es/m/23181.1578167938@sss.pgh.pa.us

src/bin/psql/t/010_tab_completion.pl

index 0f1d596b2bff4db1b9001a564dd14999a2a2dd8f..9cfd7ec79c755f46b9f270284cd5c4e10e2bdd62 100644 (file)
@@ -38,11 +38,17 @@ $node->safe_psql('postgres',
 my $historyfile = "${TestLib::log_path}/010_psql_history.txt";
 $ENV{PSQL_HISTORY} = $historyfile;
 
-# Debug investigation
-note "TERM is set to '" . ($ENV{TERM} || "<undef>") . "'";
-
-# regexp to match one xterm escape sequence (CSI style only, for now)
-my $escseq = "(\e\\[[0-9;]*[A-Za-z])";
+# Another pitfall for developers is that they might have a ~/.inputrc
+# file that changes readline's behavior enough to affect this 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};
 
 # fire up an interactive psql session
 my $in  = '';
@@ -107,12 +113,8 @@ check_completion(
        "select \\* from my\a?tab",
        "complete my<tab> to mytab when there are multiple choices");
 
-# some versions of readline/libedit require two tabs here, some only need one.
-# also, some might issue escape sequences to reposition the cursor, clear the
-# line, etc, instead of just printing some spaces.
-check_completion(
-       "\t\t",
-       "mytab$escseq*123( |$escseq)+mytab$escseq*246",
+# some versions of readline/libedit require two tabs here, some only need one
+check_completion("\t\t", "mytab123 +mytab246",
        "offer multiple table choices");
 
 check_completion("2\t", "246 ",