Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfbee60f

Browse files
committed
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() andcommand_fails_like() more closely. In particular, follow theuniversal convention that the test name is the last argument.Discussion:https://www.postgresql.org/message-id/3199e176-424e-1bef-f180-c1548466c2da@enterprisedb.com
1 parent667726f commitfbee60f

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

‎src/bin/psql/t/001_basic.pl

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,46 @@
1212
program_version_ok('psql');
1313
program_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.
1916
subpsql_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+
subpsql_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()
5450
foreachmy$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,'\helpwith argument','\helpSELECT',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

8483
done_testing();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp