pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Subject: Re: psql - add SHOW_ALL_RESULTS option
Date: Tue, 22 Feb 2022 15:31:16 +0100
Message-ID: <3199e176-424e-1bef-f180-c1548466c2da@enterprisedb.com> (raw)
In-Reply-To: <d0eff86e-547a-1217-eb8f-0d2fbc8c83ea@enterprisedb.com>
References: <18c78a01-4a34-9dd4-f78b-6860f1420c8e@enterprisedb.com>
	<alpine.DEB.2.22.394.2107221655020.25741@pseudo>
	<6954328d-96f2-77f7-735f-7ce493a40949@enterprisedb.com>
	<alpine.DEB.2.22.394.2109251058000.3216312@pseudo>
	<alpine.DEB.2.22.394.2110021622530.2817726@pseudo>
	<2570e2ae-fa0f-aac9-f72f-bb59a9983a20@enterprisedb.com>
	<alpine.DEB.2.22.394.2112230703530.2668598@pseudo>
	<46259d13-5f90-1475-3c85-d7a597a2b862@enterprisedb.com>
	<alpine.DEB.2.22.394.2201040851220.3857182@pseudo>
	<alpine.DEB.2.22.394.2201081931170.731324@pseudo>
	<20220113054433.wdjhidtm7gvyhfts@alap3.anarazel.de>
	<alpine.DEB.2.22.394.2201150938470.3378943@pseudo>
	<47bcee2e-3e4c-a0ea-daee-9b3e2d65df05@enterprisedb.com>
	<alpine.DEB.2.22.394.2201231810310.1496591@pseudo>
	<a0fcfc4c-b910-df47-2f64-3f8d7cb01c10@enterprisedb.com>
	<alpine.DEB.2.22.394.2201291530010.399637@pseudo>
	<d0eff86e-547a-1217-eb8f-0d2fbc8c83ea@enterprisedb.com>

I wrote a few more small tests for psql to address uncovered territory 
in SendQuery() especially:

- \timing
- client encoding handling
- notifications

What's still missing is:

- \watch
- pagers

For \watch, I think one would need something like the current cancel 
test (since you need to get the psql pid to send a signal to stop the 
watch).  It would work in principle, but it will require more work to 
refactor the cancel test.

For pagers, I don't know.  I would be pretty easy to write a simple 
script that acts as a pass-through pager and check that it is called. 
There were some discussions earlier in the thread that some version of 
some patch had broken some use of pagers.  Does anyone remember details? 
  Anything worth testing specifically?

Attachments: download all (2 files, .tar.gz)

0001-Improve-some-psql-test-code.patch (text/plain, 3.6K) download From 6e75c1bec73f2128b94131305e6a37b97257f7c3 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter@eisentraut.org> Date: Tue, 22 Feb 2022 13:42:38 +0100 Subject: [PATCH 1/2] Improve some psql test code Split psql_like() into two functions psql_like() and psql_fails_like() and make them mirror the existing command_like() and command_fails_like() more closely. In particular, follow the universal convention that the test name is the last argument. --- src/bin/psql/t/001_basic.pl | 59 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl index ba3dd846ba..f416e0ab5e 100644 --- a/src/bin/psql/t/001_basic.pl +++ b/src/bin/psql/t/001_basic.pl @@ -12,40 +12,36 @@ program_version_ok('psql'); program_options_handling_ok('psql'); -my ($stdout, $stderr); -my $result; - -# Execute a psql command and check its result patterns. +# Execute a psql command and check its output. sub psql_like { local $Test::Builder::Level = $Test::Builder::Level + 1; - my $node = shift; - my $test_name = shift; - my $query = shift; - my $expected_stdout = shift; - my $expected_stderr = shift; + my ($node, $sql, $expected_stdout, $test_name) = @_; + + my ($ret, $stdout, $stderr) = $node->psql('postgres', $sql); + + is($ret, 0, "$test_name: exit code 0"); + is($stderr, '', "$test_name: no stderr"); + like($stdout, $expected_stdout, "$test_name: matches"); + + return; +} + +# Execute a psql command and check that it fails and check the stderr. +sub psql_fails_like +{ + local $Test::Builder::Level = $Test::Builder::Level + 1; - die "cannot specify both expected stdout and stderr here" - if (defined($expected_stdout) && defined($expected_stderr)); + my ($node, $sql, $expected_stderr, $test_name) = @_; # Use the context of a WAL sender, some of the tests rely on that. my ($ret, $stdout, $stderr) = $node->psql( - 'postgres', $query, - on_error_die => 0, + 'postgres', $sql, replication => 'database'); - if (defined($expected_stdout)) - { - is($ret, 0, "$test_name: expected result code"); - is($stderr, '', "$test_name: no stderr"); - like($stdout, $expected_stdout, "$test_name: stdout matches"); - } - if (defined($expected_stderr)) - { - isnt($ret, 0, "$test_name: expected result code"); - like($stderr, $expected_stderr, "$test_name: stderr matches"); - } + isnt($ret, 0, "$test_name: exit code not 0"); + like($stderr, $expected_stderr, "$test_name: matches"); return; } @@ -53,6 +49,9 @@ sub psql_like # test --help=foo, analogous to program_help_ok() foreach my $arg (qw(commands variables)) { + my ($stdout, $stderr); + my $result; + $result = IPC::Run::run [ 'psql', "--help=$arg" ], '>', \$stdout, '2>', \$stderr; ok($result, "psql --help=$arg exit code 0"); @@ -70,15 +69,15 @@ sub psql_like }); $node->start; -psql_like($node, '\copyright', '\copyright', qr/Copyright/, undef); -psql_like($node, '\help without arguments', '\help', qr/ALTER/, undef); -psql_like($node, '\help with argument', '\help SELECT', qr/SELECT/, undef); +psql_like($node, '\copyright', qr/Copyright/, '\copyright'); +psql_like($node, '\help', qr/ALTER/, '\help without arguments'); +psql_like($node, '\help SELECT', qr/SELECT/, '\help with argument'); # Test clean handling of unsupported replication command responses -psql_like( +psql_fails_like( $node, - 'handling of unexpected PQresultStatus', 'START_REPLICATION 0/0', - undef, qr/unexpected PQresultStatus: 8$/); + qr/unexpected PQresultStatus: 8$/, + 'handling of unexpected PQresultStatus'); done_testing(); -- 2.35.1
0002-psql-Additional-tests.patch (text/plain, 1.7K) download From 189e977e47c505230195551833e0a61ec71dced3 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter@eisentraut.org> Date: Tue, 22 Feb 2022 14:20:05 +0100 Subject: [PATCH 2/2] psql: Additional tests Add a few TAP tests for things that happen while a user query is being sent: - \timing - client encoding handling - notifications --- src/bin/psql/t/001_basic.pl | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl index f416e0ab5e..44ecd05add 100644 --- a/src/bin/psql/t/001_basic.pl +++ b/src/bin/psql/t/001_basic.pl @@ -60,7 +60,7 @@ sub psql_fails_like } my $node = PostgreSQL::Test::Cluster->new('main'); -$node->init; +$node->init(extra => [ '--locale=C', '--encoding=UTF8' ]); $node->append_conf( 'postgresql.conf', q{ wal_level = 'logical' @@ -80,4 +80,39 @@ sub psql_fails_like qr/unexpected PQresultStatus: 8$/, 'handling of unexpected PQresultStatus'); +# test \timing +psql_like( + $node, + '\timing on +SELECT 1', + qr/^1$ +^Time: \d+.\d\d\d ms/m, + '\timing'); + +# test that ENCODING variable is set and that it is updated when +# client encoding is changed +psql_like( + $node, + '\echo :ENCODING +set client_encoding = LATIN1; +\echo :ENCODING', + qr/^UTF8$ +^LATIN1$/m, + 'ENCODING variable is set and updated'); + +# test LISTEN/NOTIFY +psql_like( + $node, + 'LISTEN foo; +NOTIFY foo;', + qr/^Asynchronous notification "foo" received from server process with PID \d+\.$/, + 'notification'); + +psql_like( + $node, + "LISTEN foo; +NOTIFY foo, 'bar';", + qr/^Asynchronous notification "foo" with payload "bar" received from server process with PID \d+\.$/, + 'notification with payload'); + done_testing(); -- 2.35.1

view thread (127+ messages)  latest in thread

Message-ID: <3199e176-424e-1bef-f180-c1548466c2da@enterprisedb.com>
Permalink:  ../3199e176-424e-1bef-f180-c1548466c2da@enterprisedb.com/
Also on:    postgresql.org/message-id/3199e176-424e-1bef-f180-c1548466c2da@enterprisedb.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: peter.eisentraut@enterprisedb.com, coelho@cri.ensmp.fr, pgsql-hackers@lists.postgresql.org
  Subject: Re: psql - add SHOW_ALL_RESULTS option
  In-Reply-To: <3199e176-424e-1bef-f180-c1548466c2da@enterprisedb.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox