1212program_version_ok(' psql' );
1313program_options_handling_ok(' psql' );
1414
15- my ($stdout , $stderr );
16- my $result ;
17-
18- # Execute a psql command and check its result patterns.
15+ # Execute a psql command and check its output.
1916sub psql_like
2017{
2118 local $Test::Builder::Level = $Test::Builder::Level + 1;
2219
23- my $node = shift ;
24- my $test_name = shift ;
25- my $query = shift ;
26- my $expected_stdout = shift ;
27- my $expected_stderr = shift ;
20+ my ($node , $sql , $expected_stdout , $test_name ) = @_ ;
21+
22+ my ($ret , $stdout , $stderr ) = $node -> psql(' postgres' , $sql );
23+
24+ is($ret , 0, " $test_name : exit code 0" );
25+ is($stderr , ' ' , " $test_name : no stderr" );
26+ like($stdout , $expected_stdout , " $test_name : matches" );
27+
28+ return ;
29+ }
30+
31+ # Execute a psql command and check that it fails and check the stderr.
32+ sub psql_fails_like
33+ {
34+ local $Test::Builder::Level = $Test::Builder::Level + 1;
2835
29- die " cannot specify both expected stdout and stderr here"
30- if (defined ($expected_stdout ) && defined ($expected_stderr ));
36+ my ($node , $sql , $expected_stderr , $test_name ) = @_ ;
3137
3238 # Use the context of a WAL sender, some of the tests rely on that.
3339 my ($ret , $stdout , $stderr ) = $node -> psql(
34- ' postgres' , $query ,
35- on_error_die => 0,
40+ ' postgres' , $sql ,
3641 replication => ' database' );
3742
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- }
43+ isnt($ret , 0, " $test_name : exit code not 0" );
44+ like($stderr , $expected_stderr , " $test_name : matches" );
4945
5046 return ;
5147}
5248
5349# test --help=foo, analogous to program_help_ok()
5450foreach my $arg (qw( commands variables) )
5551{
52+ my ($stdout , $stderr );
53+ my $result ;
54+
5655 $result = IPC::Run::run [ ' psql' , " --help=$arg " ], ' >' , \$stdout , ' 2>' ,
5756 \$stderr ;
5857 ok($result , " psql --help=$arg exit code 0" );
@@ -70,15 +69,15 @@ sub psql_like
7069} );
7170$node -> start;
7271
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 );
72+ psql_like($node , ' \copyright' , qr / Copyright/ , ' \copyright ' );
73+ psql_like($node , ' \help' , qr / ALTER/ , ' \help without arguments ' );
74+ psql_like($node , ' \help SELECT' , qr / SELECT/ , ' \help with argument ' );
7675
7776# Test clean handling of unsupported replication command responses
78- psql_like (
77+ psql_fails_like (
7978 $node ,
80- ' handling of unexpected PQresultStatus' ,
8179 ' START_REPLICATION 0/0' ,
82- undef , qr / unexpected PQresultStatus: 8$ / );
80+ qr / unexpected PQresultStatus: 8$ / ,
81+ ' handling of unexpected PQresultStatus' );
8382
8483done_testing();
0 commit comments