|
15 | 15 | my ($stdout, $stderr);
|
16 | 16 | my $result;
|
17 | 17 |
|
| 18 | +# Execute a psql command and check its result patterns. |
| 19 | +sub psql_like |
| 20 | +{ |
| 21 | + local $Test::Builder::Level = $Test::Builder::Level + 1; |
| 22 | + |
| 23 | + my $node = shift; |
| 24 | + my $test_name = shift; |
| 25 | + my $query = shift; |
| 26 | + my $expected_stdout = shift; |
| 27 | + my $expected_stderr = shift; |
| 28 | + |
| 29 | + die "cannot specify both expected stdout and stderr here" |
| 30 | + if (defined($expected_stdout) && defined($expected_stderr)); |
| 31 | + |
| 32 | + # Use the context of a WAL sender, some of the tests rely on that. |
| 33 | + my ($ret, $stdout, $stderr) = $node->psql( |
| 34 | + 'postgres', $query, |
| 35 | + on_error_die => 0, |
| 36 | + replication => 'database'); |
| 37 | + |
| 38 | + if (defined($expected_stdout)) |
| 39 | + { |
| 40 | + is($ret, 0, "$test_name: expected result code"); |
| 41 | + is($stderr, '', "$test_name: no stderr"); |
| 42 | + like($stdout, $expected_stdout, "$test_name: stdout matches"); |
| 43 | + } |
| 44 | + if (defined($expected_stderr)) |
| 45 | + { |
| 46 | + isnt($ret, 0, "$test_name: expected result code"); |
| 47 | + like($stderr, $expected_stderr, "$test_name: stderr matches"); |
| 48 | + } |
| 49 | + |
| 50 | + return; |
| 51 | +} |
| 52 | + |
18 | 53 | # test --help=foo, analogous to program_help_ok()
|
19 | 54 | foreach my $arg (qw(commands variables))
|
20 | 55 | {
|
21 |
| - $result = IPC::Run::run [ 'psql', "--help=$arg" ], '>', \$stdout, '2>', \$stderr; |
| 56 | + $result = IPC::Run::run [ 'psql', "--help=$arg" ], '>', \$stdout, '2>', |
| 57 | + \$stderr; |
22 | 58 | ok($result, "psql --help=$arg exit code 0");
|
23 | 59 | isnt($stdout, '', "psql --help=$arg goes to stdout");
|
24 | 60 | is($stderr, '', "psql --help=$arg nothing to stderr");
|
|
34 | 70 | });
|
35 | 71 | $node->start;
|
36 | 72 |
|
37 |
| -$node->command_like([ 'psql', '-c', '\copyright' ], qr/Copyright/, '\copyright'); |
38 |
| -$node->command_like([ 'psql', '-c', '\help' ], qr/ALTER/, '\help without arguments'); |
39 |
| -$node->command_like([ 'psql', '-c', '\help SELECT' ], qr/SELECT/, '\help'); |
40 |
| - |
| 73 | +psql_like($node, '\copyright', '\copyright', qr/Copyright/, undef); |
| 74 | +psql_like($node, '\help without arguments', '\help', qr/ALTER/, undef); |
| 75 | +psql_like($node, '\help with argument', '\help SELECT', qr/SELECT/, undef); |
41 | 76 |
|
42 | 77 | # Test clean handling of unsupported replication command responses
|
43 |
| -$node->command_fails_like([ 'psql', '-d', 'replication=database', '-c', 'START_REPLICATION 0/0' ], |
44 |
| - qr/^unexpected PQresultStatus: 8$/, 'handling of unexpected PQresultStatus'); |
| 78 | +psql_like( |
| 79 | + $node, |
| 80 | + 'handling of unexpected PQresultStatus', |
| 81 | + 'START_REPLICATION 0/0', |
| 82 | + undef, qr/unexpected PQresultStatus: 8$/); |
0 commit comments