Make psql/t/030_pager.pl more robust. master github/master
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 30 Jan 2026 20:11:44 +0000 (15:11 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 30 Jan 2026 20:11:44 +0000 (15:11 -0500)
Similarly to the preceding commit, 030_pager.pl was assuming
that patterns it looks for in interactive psql output would
appear by themselves on a line, but that assumption tends to
fall over in builds made --without-readline: the output we
get might have a psql prompt immediately followed by the
expected line of output.

For several of these tests, just checking for the pattern
followed by newline seems sufficient, because we could not
get a false match against the command echo, nor against the
unreplaced command output if the pager fails to be invoked
when expected.  However, that's fairly scary for the test
that was relying on information_schema.referential_constraints:
"\d+" could easily appear at the end of a line in that view.
Let's get rid of that hazard by making a custom test view
instead of using information_schema.referential_constraints.

This test script is new in v19, so no need for back-patch.

Reported-by: Oleg Tselebrovskiy <o.tselebrovskiy@postgrespro.ru>
Author: Oleg Tselebrovskiy <o.tselebrovskiy@postgrespro.ru>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Soumya S Murali <soumyamurali.work@gmail.com>
Discussion: https://postgr.es/m/db6fdb35a8665ad3c18be01181d44b31@postgrespro.ru

src/bin/psql/t/030_pager.pl

index cf81fb1603c2ec22ceb39ddd3bee0db195e8da1a..a35f2b2629359a9b10e0482555b9e5cdc098e44f 100644 (file)
@@ -40,6 +40,36 @@ my $node = PostgreSQL::Test::Cluster->new('main');
 $node->init;
 $node->start;
 
+# create a view we'll use below
+$node->safe_psql(
+   'postgres', 'create view public.view_030_pager as select
+1 as a,
+2 as b,
+3 as c,
+4 as d,
+5 as e,
+6 as f,
+7 as g,
+8 as h,
+9 as i,
+10 as j,
+11 as k,
+12 as l,
+13 as m,
+14 as n,
+15 as o,
+16 as p,
+17 as q,
+18 as r,
+19 as s,
+20 as t,
+21 as u,
+22 as v,
+23 as w,
+24 as x,
+25 as y,
+26 as z');
+
 # fire up an interactive psql session
 my $h = $node->interactive_psql('postgres');
 
@@ -77,25 +107,28 @@ sub do_command
 #
 # Note that interactive_psql starts psql with --no-align --tuples-only,
 # and that the output string will include psql's prompts and command echo.
+# So we have to test for patterns that can't match the command itself,
+# and we can't assume the match will extend across a whole line (there
+# might be a prompt ahead of it in the output).
 
 do_command(
    "SELECT 'test' AS t FROM generate_series(1,23);\n",
-   qr/^test\r?$/m,
+   qr/test\r?$/m,
    "execute SELECT query that needs no pagination");
 
 do_command(
    "SELECT 'test' AS t FROM generate_series(1,24);\n",
-   qr/^ *24\r?$/m,
+   qr/24\r?$/m,
    "execute SELECT query that needs pagination");
 
 do_command(
    "\\pset expanded\nSELECT generate_series(1,20) as g;\n",
-   qr/^ *39\r?$/m,
+   qr/39\r?$/m,
    "execute SELECT query that needs pagination in expanded mode");
 
 do_command(
-   "\\pset tuples_only off\n\\d+ information_schema.referential_constraints\n",
-   qr/^ *\d+\r?$/m,
+   "\\pset tuples_only off\n\\d+ public.view_030_pager\n",
+   qr/55\r?$/m,
    "execute command with footer that needs pagination");
 
 # send psql an explicit \q to shut it down, else pty won't close properly