aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/t/001_basic.pl59
1 files changed, 29 insertions, 30 deletions
diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl
index ba3dd846bad..f416e0ab5e8 100644
--- a/src/bin/psql/t/001_basic.pl
+++ b/src/bin/psql/t/001_basic.pl
@@ -12,40 +12,36 @@ program_help_ok('psql');
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 @@ max_wal_senders = 4
});
$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();