diff options
| author | Tom Lane | 2017-09-08 13:32:50 +0000 |
|---|---|---|
| committer | Tom Lane | 2017-09-08 13:32:50 +0000 |
| commit | ed8a7c6fcf92b6b57ed8003bbd4a4eb92a6039bc (patch) | |
| tree | 7b4a3b9e7c149b66136c29e41c62262451859d38 /src/test | |
| parent | f0a0c17c1b126882a37ec6bf42ab45a963794c3e (diff) | |
Add much-more-extensive TAP tests for pgbench.
Fabien Coelho, reviewed by Nikolay Shaplov and myself
Discussion: https://postgr.es/m/alpine.DEB.2.20.1704171422500.4025@lancre
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/perl/PostgresNode.pm | 31 | ||||
| -rw-r--r-- | src/test/perl/TestLib.pm | 38 |
2 files changed, 62 insertions, 7 deletions
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index 3a81c1c60b7..edcac6fb9f6 100644 --- a/src/test/perl/PostgresNode.pm +++ b/src/test/perl/PostgresNode.pm @@ -155,8 +155,9 @@ sub new _logfile => "$TestLib::log_path/${testname}_${name}.log" }; bless $self, $class; - mkdir $self->{_basedir} or - BAIL_OUT("could not create data directory \"$self->{_basedir}\": $!"); + mkdir $self->{_basedir} + or + BAIL_OUT("could not create data directory \"$self->{_basedir}\": $!"); $self->dump_info; return $self; @@ -934,8 +935,7 @@ sub get_new_node # Retain the errno on die() if set, else assume a generic errno of 1. # This will instruct the END handler on how to handle artifacts left # behind from tests. -$SIG{__DIE__} = sub -{ +$SIG{__DIE__} = sub { if ($!) { $died = $!; @@ -965,7 +965,7 @@ END # clean basedir on clean test invocation $node->clean_node - if TestLib::all_tests_passing() && !defined $died && !$exit_code; + if TestLib::all_tests_passing() && !defined $died && !$exit_code; } $? = $exit_code; @@ -1325,9 +1325,9 @@ sub command_ok =pod -=item $node->command_fails(...) - TestLib::command_fails with our PGPORT +=item $node->command_fails(...) -See command_ok(...) +TestLib::command_fails with our PGPORT. See command_ok(...) =cut @@ -1359,6 +1359,23 @@ sub command_like =pod +=item $node->command_checks_all(...) + +TestLib::command_checks_all with our PGPORT. See command_ok(...) + +=cut + +sub command_checks_all +{ + my $self = shift; + + local $ENV{PGPORT} = $self->port; + + TestLib::command_checks_all(@_); +} + +=pod + =item $node->issues_sql_like(cmd, expected_sql, test_name) Run a command on the node, then verify that $expected_sql appears in the diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index 6dba21c0736..0e73c991306 100644 --- a/src/test/perl/TestLib.pm +++ b/src/test/perl/TestLib.pm @@ -39,6 +39,7 @@ our @EXPORT = qw( command_like command_like_safe command_fails_like + command_checks_all $windows_os ); @@ -330,4 +331,41 @@ sub command_fails_like like($stderr, $expected_stderr, "$test_name: matches"); } +# Run a command and check its status and outputs. +# The 5 arguments are: +# - cmd: ref to list for command, options and arguments to run +# - ret: expected exit status +# - out: ref to list of re to be checked against stdout (all must match) +# - err: ref to list of re to be checked against stderr (all must match) +# - test_name: name of test +sub command_checks_all +{ + my ($cmd, $ret, $out, $err, $test_name) = @_; + + # run command + my ($stdout, $stderr); + print("# Running: " . join(" ", @{$cmd}) . "\n"); + IPC::Run::run($cmd, '>', \$stdout, '2>', \$stderr); + + # On Windows, the exit status of the process is returned directly as the + # process's exit code, while on Unix, it's returned in the high bits + # of the exit code. + my $status = $windows_os ? $? : $? >> 8; + + # check status + ok($ret == $status, "$test_name status (got $status vs expected $ret)"); + + # check stdout + for my $re (@$out) + { + like($stdout, $re, "$test_name stdout /$re/"); + } + + # check stderr + for my $re (@$err) + { + like($stderr, $re, "$test_name stderr /$re/"); + } +} + 1; |
