From e8dbe137737f94a2eaff86dc1676f9df39c60d00 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 7 Oct 2021 22:12:40 +0200 Subject: [PATCH] psql: More tests --- src/bin/psql/t/001_basic.pl | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/bin/psql/t/001_basic.pl diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl new file mode 100644 index 0000000000..cd899e851e --- /dev/null +++ b/src/bin/psql/t/001_basic.pl @@ -0,0 +1,42 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 25; + +program_help_ok('psql'); +program_version_ok('psql'); +program_options_handling_ok('psql'); + +my ($stdout, $stderr); +my $result; + +# test --help=foo, analogous to program_help_ok() +foreach my $arg (qw(commands variables)) +{ + $result = IPC::Run::run [ 'psql', "--help=$arg" ], '>', \$stdout, '2>', \$stderr; + ok($result, "psql --help=$arg exit code 0"); + isnt($stdout, '', "psql --help=$arg goes to stdout"); + is($stderr, '', "psql --help=$arg nothing to stderr"); +} + +my $node = PostgresNode->new('main'); +$node->init; +$node->append_conf( + 'postgresql.conf', q{ +wal_level = 'logical' +max_replication_slots = 4 +max_wal_senders = 4 +}); +$node->start; + +$node->command_like([ 'psql', '-c', '\copyright' ], qr/Copyright/, '\copyright'); +$node->command_like([ 'psql', '-c', '\help' ], qr/ALTER/, '\help without arguments'); +$node->command_like([ 'psql', '-c', '\help SELECT' ], qr/SELECT/, '\help'); + +$node->command_fails_like([ 'psql', 'replication=database', '-c', 'START_REPLICATION 123/456' ], + qr/^unexpected PQresultStatus: 8$/, 'handling of unexpected PQresultStatus'); -- 2.33.0