Re: pgsql: Add basic TAP tests for psql's tab-completion logic. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: pgsql: Add basic TAP tests for psql's tab-completion logic.
Date
Msg-id 25739.1578161968@sss.pgh.pa.us
Whole thread Raw
In response to Re: pgsql: Add basic TAP tests for psql's tab-completion logic.  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: pgsql: Add basic TAP tests for psql's tab-completion logic.
List pgsql-hackers
I wrote:
> Meh.  I must be too tired to get the regexp syntax right.

Looking closer, I see that your actual output included *both*
spaces and escape sequences between the table names, so it
needs to be more like the attached.

Also, I apparently misread the control sequences.  What they
look like in the light of morning is

\e[0m        Character Attributes = Normal (no bold, color, etc)
\e[K        Erase in Line to Right

So now I'm thinking again that there must be something about
your colorized setup that triggers use of at least the first one.
But why didn't clearing the relevant environment variables
change anything?

            regards, tom lane

diff --git a/src/bin/psql/t/010_tab_completion.pl b/src/bin/psql/t/010_tab_completion.pl
index 96221f8..ed9e9e1 100644
--- a/src/bin/psql/t/010_tab_completion.pl
+++ b/src/bin/psql/t/010_tab_completion.pl
@@ -38,6 +38,12 @@ $node->safe_psql('postgres',
 my $historyfile = "${TestLib::log_path}/010_psql_history.txt";
 $ENV{PSQL_HISTORY} = $historyfile;

+# Ensure that readline/libedit puts out xterm escapes, not something else.
+$ENV{TERM} = 'xterm';
+
+# regexp to match one xterm escape sequence (CSI style only, for now)
+my $escseq = "(\e\\[[0-9;]*[A-Za-z])";
+
 # fire up an interactive psql session
 my $in  = '';
 my $out = '';
@@ -101,8 +107,12 @@ 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
-check_completion("\t\t", "mytab123 +mytab246",
+# 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",
     "offer multiple table choices");

 check_completion("2\t", "246 ",

pgsql-hackers by date:

Previous
From: Dean Rasheed
Date:
Subject: Re: Errors when update a view with conditional-INSTEAD rules
Next
From: Alexey Kondratov
Date:
Subject: Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace onthe fly