Skip to content

Commit d33a812

Browse files
committed
Improve psql tab-completion tests.
Fix up recently-added test cases in 010_tab_completion.pl so that they pass with the rather seriously broken libedit found in Debian 10 (Buster). Also, add a few more test cases to improve code coverage. The total line coverage still looks pretty awful, because we exercise only a few paths of the giant if-else chain in psql_completion(). However, this now covers almost all of the code that isn't in one of those if-blocks. Discussion: https://postgr.es/m/960764.1643751011@sss.pgh.pa.us
1 parent 8e2b6d4 commit d33a812

File tree

1 file changed

+95
-8
lines changed

1 file changed

+95
-8
lines changed

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

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
. "CREATE TABLE mytab123 (f1 int, f2 text);\n"
4545
. "CREATE TABLE mytab246 (f1 int, f2 text);\n"
4646
. "CREATE TABLE \"mixedName\" (f1 int, f2 text);\n"
47-
. "CREATE TYPE enum1 AS ENUM ('foo', 'bar', 'baz', 'BLACK');\n");
47+
. "CREATE TYPE enum1 AS ENUM ('foo', 'bar', 'baz', 'BLACK');\n"
48+
. "CREATE PUBLICATION some_publication;\n");
4849

4950
# Developers would not appreciate this test adding a bunch of junk to
5051
# their ~/.psql_history, so be sure to redirect history into a temp file.
@@ -131,7 +132,8 @@ sub clear_query
131132
{
132133
local $Test::Builder::Level = $Test::Builder::Level + 1;
133134

134-
check_completion("\\r\n", qr/postgres=# /, "\\r works");
135+
check_completion("\\r\n", qr/Query buffer reset.*postgres=# /s,
136+
"\\r works");
135137
return;
136138
}
137139

@@ -188,18 +190,26 @@ sub clear_line
188190
qr/"mytab123" +"mytab246"/,
189191
"offer multiple quoted table choices");
190192

191-
check_completion("2\t", qr/246" /,
193+
# note: broken versions of libedit want to backslash the closing quote;
194+
# not much we can do about that
195+
check_completion("2\t", qr/246\\?" /,
192196
"finish completion of one of multiple quoted table choices");
193197

194-
clear_query();
198+
# note: broken versions of libedit may leave us in a state where psql
199+
# thinks there's an unclosed double quote, so that we have to use
200+
# clear_line not clear_query here
201+
clear_line();
195202

196203
# check handling of mixed-case names
204+
# note: broken versions of libedit want to backslash the closing quote;
205+
# not much we can do about that
197206
check_completion(
198207
"select * from \"mi\t",
199-
qr/"mixedName"/,
208+
qr/"mixedName\\?" /,
200209
"complete a mixed-case name");
201210

202-
clear_query();
211+
# as above, must use clear_line not clear_query here
212+
clear_line();
203213

204214
# check case folding
205215
check_completion(
@@ -214,7 +224,8 @@ sub clear_line
214224
# differently, so just check that the replacement comes out correctly
215225
check_completion("\\DRD\t", qr/drds /, "complete \\DRD<tab> to \\drds");
216226

217-
clear_query();
227+
# broken versions of libedit require clear_line not clear_query here
228+
clear_line();
218229

219230
# check completion of a schema-qualified name
220231
check_completion(
@@ -258,6 +269,15 @@ sub clear_line
258269

259270
clear_query();
260271

272+
# check variant where we're completing a qualified name from a refname
273+
# (this one also checks successful completion in a multiline command)
274+
check_completion(
275+
"comment on constraint tab1_pkey \n on public.\t",
276+
qr/public\.tab1/,
277+
"complete qualified name from object reference");
278+
279+
clear_query();
280+
261281
# check filename completion
262282
check_completion(
263283
"\\lo_import tmp_check/some\t",
@@ -272,7 +292,8 @@ sub clear_line
272292
qr|tmp_check/af\a?ile|,
273293
"filename completion with multiple possibilities");
274294

275-
clear_query();
295+
# broken versions of libedit require clear_line not clear_query here
296+
clear_line();
276297

277298
# COPY requires quoting
278299
# note: broken versions of libedit want to backslash the closing quote;
@@ -342,6 +363,72 @@ sub clear_line
342363
clear_query();
343364
}
344365

366+
# alternate path where keyword comes from SchemaQuery
367+
check_completion(
368+
"DROP TYPE big\t",
369+
qr/DROP TYPE bigint /,
370+
"offer keyword from SchemaQuery");
371+
372+
clear_query();
373+
374+
# check create_command_generator
375+
check_completion(
376+
"CREATE TY\t",
377+
qr/CREATE TYPE /,
378+
"check create_command_generator");
379+
380+
clear_query();
381+
382+
# check words_after_create infrastructure
383+
check_completion(
384+
"CREATE TABLE mytab\t\t",
385+
qr/mytab123 +mytab246/,
386+
"check words_after_create");
387+
388+
clear_query();
389+
390+
# check VersionedQuery infrastructure
391+
check_completion(
392+
"DROP PUBLIC\t \t\t",
393+
qr/DROP PUBLICATION\s+some_publication /,
394+
"check VersionedQuery");
395+
396+
clear_query();
397+
398+
# hits ends_with() and logic for completing in multi-line queries
399+
check_completion("analyze (\n\t\t", qr/VERBOSE/,
400+
"check ANALYZE (VERBOSE ...");
401+
402+
clear_query();
403+
404+
# check completions for GUCs
405+
check_completion(
406+
"set interval\t\t",
407+
qr/intervalstyle TO/,
408+
"complete a GUC name");
409+
check_completion(" iso\t", qr/iso_8601 /, "complete a GUC enum value");
410+
411+
clear_query();
412+
413+
# check completions for psql variables
414+
check_completion("\\set VERB\t", qr/VERBOSITY /,
415+
"complete a psql variable name");
416+
check_completion("def\t", qr/default /, "complete a psql variable value");
417+
418+
clear_query();
419+
420+
check_completion(
421+
"\\echo :VERB\t",
422+
qr/:VERBOSITY /,
423+
"complete an interpolated psql variable name");
424+
425+
clear_query();
426+
427+
# check no-completions code path
428+
check_completion("blarg \t\t", qr//, "check completion failure path");
429+
430+
clear_query();
431+
345432
# send psql an explicit \q to shut it down, else pty won't close properly
346433
$timer->start(5);
347434
$in .= "\\q\n";

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy