Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
# TestLib, low-level routines and actions regression tests.
|
|
|
|
#
|
|
|
|
# This module contains a set of routines dedicated to environment setup for
|
2016-04-02 03:53:10 +02:00
|
|
|
# a PostgreSQL regression test run and includes some low-level routines
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
# aimed at controlling command execution, logging and test functions. This
|
|
|
|
# module should never depend on any other PostgreSQL regression test modules.
|
|
|
|
|
2014-04-15 03:33:46 +02:00
|
|
|
package TestLib;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2015-07-29 18:17:02 +02:00
|
|
|
use Config;
|
2014-04-15 03:33:46 +02:00
|
|
|
use Exporter 'import';
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
use File::Basename;
|
|
|
|
use File::Spec;
|
|
|
|
use File::Temp ();
|
|
|
|
use IPC::Run;
|
|
|
|
use SimpleTee;
|
|
|
|
use Test::More;
|
|
|
|
|
2014-04-15 03:33:46 +02:00
|
|
|
our @EXPORT = qw(
|
2015-07-01 03:15:29 +02:00
|
|
|
slurp_dir
|
2015-07-01 03:15:05 +02:00
|
|
|
slurp_file
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
append_to_file
|
2014-05-06 18:12:18 +02:00
|
|
|
system_or_bail
|
2015-07-09 12:19:10 +02:00
|
|
|
system_log
|
|
|
|
run_log
|
2014-05-06 18:12:18 +02:00
|
|
|
|
|
|
|
command_ok
|
|
|
|
command_fails
|
|
|
|
command_exit_is
|
|
|
|
program_help_ok
|
|
|
|
program_version_ok
|
|
|
|
program_options_handling_ok
|
|
|
|
command_like
|
2016-07-26 16:48:43 +02:00
|
|
|
command_fails_like
|
2015-07-28 21:34:35 +02:00
|
|
|
|
2015-08-03 02:58:18 +02:00
|
|
|
$windows_os
|
2014-04-15 03:33:46 +02:00
|
|
|
);
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
our ($windows_os, $tmp_check, $log_path, $test_logfile);
|
2015-07-09 12:19:10 +02:00
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
BEGIN
|
2014-05-06 18:12:18 +02:00
|
|
|
{
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
|
|
|
# Set to untranslated messages, to be able to compare program output
|
|
|
|
# with expected strings.
|
|
|
|
delete $ENV{LANGUAGE};
|
|
|
|
delete $ENV{LC_ALL};
|
|
|
|
$ENV{LC_MESSAGES} = 'C';
|
|
|
|
|
|
|
|
delete $ENV{PGCONNECT_TIMEOUT};
|
|
|
|
delete $ENV{PGDATA};
|
|
|
|
delete $ENV{PGDATABASE};
|
|
|
|
delete $ENV{PGHOSTADDR};
|
|
|
|
delete $ENV{PGREQUIRESSL};
|
|
|
|
delete $ENV{PGSERVICE};
|
|
|
|
delete $ENV{PGSSLMODE};
|
|
|
|
delete $ENV{PGUSER};
|
|
|
|
delete $ENV{PGPORT};
|
|
|
|
delete $ENV{PGHOST};
|
|
|
|
|
|
|
|
# Must be set early
|
|
|
|
$windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys';
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
INIT
|
|
|
|
{
|
2014-04-15 03:33:46 +02:00
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
# Determine output directories, and create them. The base path is the
|
|
|
|
# TESTDIR environment variable, which is normally set by the invoking
|
|
|
|
# Makefile.
|
|
|
|
$tmp_check = $ENV{TESTDIR} ? "$ENV{TESTDIR}/tmp_check" : "tmp_check";
|
|
|
|
$log_path = "$tmp_check/log";
|
|
|
|
|
|
|
|
mkdir $tmp_check;
|
|
|
|
mkdir $log_path;
|
|
|
|
|
|
|
|
# Open the test log file, whose name depends on the test name.
|
|
|
|
$test_logfile = basename($0);
|
|
|
|
$test_logfile =~ s/\.[^.]+$//;
|
|
|
|
$test_logfile = "$log_path/regress_log_$test_logfile";
|
|
|
|
open TESTLOG, '>', $test_logfile
|
|
|
|
or die "could not open STDOUT to logfile \"$test_logfile\": $!";
|
|
|
|
|
|
|
|
# Hijack STDOUT and STDERR to the log file
|
|
|
|
open(ORIG_STDOUT, ">&STDOUT");
|
|
|
|
open(ORIG_STDERR, ">&STDERR");
|
|
|
|
open(STDOUT, ">&TESTLOG");
|
|
|
|
open(STDERR, ">&TESTLOG");
|
|
|
|
|
|
|
|
# The test output (ok ...) needs to be printed to the original STDOUT so
|
|
|
|
# that the 'prove' program can parse it, and display it to the user in
|
|
|
|
# real time. But also copy it to the log file, to provide more context
|
|
|
|
# in the log.
|
|
|
|
my $builder = Test::More->builder;
|
|
|
|
my $fh = $builder->output;
|
|
|
|
tie *$fh, "SimpleTee", *ORIG_STDOUT, *TESTLOG;
|
|
|
|
$fh = $builder->failure_output;
|
|
|
|
tie *$fh, "SimpleTee", *ORIG_STDERR, *TESTLOG;
|
|
|
|
|
|
|
|
# Enable auto-flushing for all the file handles. Stderr and stdout are
|
|
|
|
# redirected to the same file, and buffering causes the lines to appear
|
|
|
|
# in the log in confusing order.
|
|
|
|
autoflush STDOUT 1;
|
|
|
|
autoflush STDERR 1;
|
|
|
|
autoflush TESTLOG 1;
|
|
|
|
}
|
2014-04-15 03:33:46 +02:00
|
|
|
|
2016-03-01 23:50:13 +01:00
|
|
|
END
|
|
|
|
{
|
2016-06-12 10:19:56 +02:00
|
|
|
|
2016-03-01 23:50:13 +01:00
|
|
|
# Preserve temporary directory for this test on failure
|
2016-03-02 07:06:31 +01:00
|
|
|
$File::Temp::KEEP_ALL = 1 unless all_tests_passing();
|
|
|
|
}
|
|
|
|
|
|
|
|
sub all_tests_passing
|
|
|
|
{
|
|
|
|
my $fail_count = 0;
|
|
|
|
foreach my $status (Test::More->builder->summary)
|
|
|
|
{
|
|
|
|
return 0 unless $status;
|
|
|
|
}
|
|
|
|
return 1;
|
2016-03-01 23:50:13 +01:00
|
|
|
}
|
|
|
|
|
2014-04-15 03:33:46 +02:00
|
|
|
#
|
|
|
|
# Helper functions
|
|
|
|
#
|
2014-05-06 18:12:18 +02:00
|
|
|
sub tempdir
|
|
|
|
{
|
2016-03-02 21:02:36 +01:00
|
|
|
my ($prefix) = @_;
|
|
|
|
$prefix = "tmp_test" unless defined $prefix;
|
2015-05-24 03:35:49 +02:00
|
|
|
return File::Temp::tempdir(
|
2016-03-02 21:02:36 +01:00
|
|
|
$prefix . '_XXXX',
|
|
|
|
DIR => $tmp_check,
|
2015-05-24 03:35:49 +02:00
|
|
|
CLEANUP => 1);
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
|
2014-07-03 03:44:02 +02:00
|
|
|
sub tempdir_short
|
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
|
2014-07-03 03:44:02 +02:00
|
|
|
# Use a separate temp dir outside the build tree for the
|
|
|
|
# Unix-domain socket, to avoid file name length issues.
|
|
|
|
return File::Temp::tempdir(CLEANUP => 1);
|
|
|
|
}
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub system_log
|
2014-05-06 18:12:18 +02:00
|
|
|
{
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
print("# Running: " . join(" ", @_) . "\n");
|
|
|
|
return system(@_);
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub system_or_bail
|
2014-05-06 18:12:18 +02:00
|
|
|
{
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
if (system_log(@_) != 0)
|
2014-05-06 18:12:18 +02:00
|
|
|
{
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
BAIL_OUT("system $_[0] failed");
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub run_log
|
2014-05-06 18:12:18 +02:00
|
|
|
{
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
print("# Running: " . join(" ", @{ $_[0] }) . "\n");
|
2015-12-03 03:16:22 +01:00
|
|
|
return IPC::Run::run(@_);
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 03:15:29 +02:00
|
|
|
sub slurp_dir
|
|
|
|
{
|
|
|
|
my ($dir) = @_;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
opendir(my $dh, $dir)
|
|
|
|
or die "could not opendir \"$dir\": $!";
|
2015-07-01 03:15:29 +02:00
|
|
|
my @direntries = readdir $dh;
|
|
|
|
closedir $dh;
|
|
|
|
return @direntries;
|
|
|
|
}
|
|
|
|
|
2015-07-01 03:15:05 +02:00
|
|
|
sub slurp_file
|
|
|
|
{
|
2015-12-08 22:58:05 +01:00
|
|
|
my ($filename) = @_;
|
2015-07-01 03:15:05 +02:00
|
|
|
local $/;
|
2015-12-08 22:58:05 +01:00
|
|
|
open(my $in, '<', $filename)
|
|
|
|
or die "could not read \"$filename\": $!";
|
|
|
|
my $contents = <$in>;
|
|
|
|
close $in;
|
2015-08-05 22:19:23 +02:00
|
|
|
$contents =~ s/\r//g if $Config{osname} eq 'msys';
|
|
|
|
return $contents;
|
2015-07-01 03:15:05 +02:00
|
|
|
}
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub append_to_file
|
2015-07-09 12:19:10 +02:00
|
|
|
{
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my ($filename, $str) = @_;
|
2015-12-08 22:58:05 +01:00
|
|
|
open my $fh, ">>", $filename
|
|
|
|
or die "could not write \"$filename\": $!";
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
print $fh $str;
|
|
|
|
close $fh;
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Test functions
|
|
|
|
#
|
2014-05-06 18:12:18 +02:00
|
|
|
sub command_ok
|
|
|
|
{
|
2014-04-15 03:33:46 +02:00
|
|
|
my ($cmd, $test_name) = @_;
|
2015-07-09 12:19:10 +02:00
|
|
|
my $result = run_log($cmd);
|
2014-04-15 03:33:46 +02:00
|
|
|
ok($result, $test_name);
|
|
|
|
}
|
|
|
|
|
2014-05-06 18:12:18 +02:00
|
|
|
sub command_fails
|
|
|
|
{
|
2014-04-15 03:33:46 +02:00
|
|
|
my ($cmd, $test_name) = @_;
|
2015-07-09 12:19:10 +02:00
|
|
|
my $result = run_log($cmd);
|
2014-04-15 03:33:46 +02:00
|
|
|
ok(!$result, $test_name);
|
|
|
|
}
|
|
|
|
|
2014-05-06 18:12:18 +02:00
|
|
|
sub command_exit_is
|
|
|
|
{
|
2014-04-15 03:33:46 +02:00
|
|
|
my ($cmd, $expected, $test_name) = @_;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
print("# Running: " . join(" ", @{$cmd}) . "\n");
|
|
|
|
my $h = IPC::Run::start $cmd;
|
2014-04-15 03:33:46 +02:00
|
|
|
$h->finish();
|
2015-07-29 18:17:02 +02:00
|
|
|
|
|
|
|
# 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 (see WEXITSTATUS macro in the standard <sys/wait.h>
|
|
|
|
# header file). IPC::Run's result function always returns exit code >> 8,
|
|
|
|
# assuming the Unix convention, which will always return 0 on Windows as
|
|
|
|
# long as the process was not terminated by an exception. To work around
|
|
|
|
# that, use $h->full_result on Windows instead.
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my $result =
|
|
|
|
($Config{osname} eq "MSWin32")
|
|
|
|
? ($h->full_results)[0]
|
|
|
|
: $h->result(0);
|
2015-07-29 18:17:02 +02:00
|
|
|
is($result, $expected, $test_name);
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
|
2014-05-06 18:12:18 +02:00
|
|
|
sub program_help_ok
|
|
|
|
{
|
2014-04-15 03:33:46 +02:00
|
|
|
my ($cmd) = @_;
|
2014-10-30 00:41:19 +01:00
|
|
|
my ($stdout, $stderr);
|
2015-07-09 12:19:10 +02:00
|
|
|
print("# Running: $cmd --help\n");
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my $result = IPC::Run::run [ $cmd, '--help' ], '>', \$stdout, '2>',
|
|
|
|
\$stderr;
|
2014-10-30 00:41:19 +01:00
|
|
|
ok($result, "$cmd --help exit code 0");
|
|
|
|
isnt($stdout, '', "$cmd --help goes to stdout");
|
|
|
|
is($stderr, '', "$cmd --help nothing to stderr");
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
|
2014-05-06 18:12:18 +02:00
|
|
|
sub program_version_ok
|
|
|
|
{
|
2014-04-15 03:33:46 +02:00
|
|
|
my ($cmd) = @_;
|
2014-10-30 00:41:19 +01:00
|
|
|
my ($stdout, $stderr);
|
2015-07-09 12:19:10 +02:00
|
|
|
print("# Running: $cmd --version\n");
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my $result = IPC::Run::run [ $cmd, '--version' ], '>', \$stdout, '2>',
|
|
|
|
\$stderr;
|
2014-10-30 00:41:19 +01:00
|
|
|
ok($result, "$cmd --version exit code 0");
|
|
|
|
isnt($stdout, '', "$cmd --version goes to stdout");
|
|
|
|
is($stderr, '', "$cmd --version nothing to stderr");
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
|
2014-05-06 18:12:18 +02:00
|
|
|
sub program_options_handling_ok
|
|
|
|
{
|
2014-04-15 03:33:46 +02:00
|
|
|
my ($cmd) = @_;
|
2014-10-30 00:41:19 +01:00
|
|
|
my ($stdout, $stderr);
|
2015-07-09 12:19:10 +02:00
|
|
|
print("# Running: $cmd --not-a-valid-option\n");
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my $result = IPC::Run::run [ $cmd, '--not-a-valid-option' ], '>',
|
|
|
|
\$stdout,
|
|
|
|
'2>', \$stderr;
|
2014-10-30 00:41:19 +01:00
|
|
|
ok(!$result, "$cmd with invalid option nonzero exit code");
|
|
|
|
isnt($stderr, '', "$cmd with invalid option prints error message");
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
|
2014-05-06 18:12:18 +02:00
|
|
|
sub command_like
|
|
|
|
{
|
2014-04-15 03:33:46 +02:00
|
|
|
my ($cmd, $expected_stdout, $test_name) = @_;
|
2014-10-30 00:41:19 +01:00
|
|
|
my ($stdout, $stderr);
|
2015-07-09 12:19:10 +02:00
|
|
|
print("# Running: " . join(" ", @{$cmd}) . "\n");
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr;
|
2016-07-26 17:39:43 +02:00
|
|
|
ok($result, "$test_name: exit code 0");
|
|
|
|
is($stderr, '', "$test_name: no stderr");
|
2014-10-30 00:41:19 +01:00
|
|
|
like($stdout, $expected_stdout, "$test_name: matches");
|
2014-04-15 03:33:46 +02:00
|
|
|
}
|
|
|
|
|
2016-07-26 16:48:43 +02:00
|
|
|
sub command_fails_like
|
|
|
|
{
|
|
|
|
my ($cmd, $expected_stderr, $test_name) = @_;
|
|
|
|
my ($stdout, $stderr);
|
|
|
|
print("# Running: " . join(" ", @{$cmd}) . "\n");
|
|
|
|
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr;
|
|
|
|
ok(!$result, "$test_name: exit code not 0");
|
|
|
|
like($stderr, $expected_stderr, "$test_name: matches");
|
|
|
|
}
|
|
|
|
|
2014-04-15 03:33:46 +02:00
|
|
|
1;
|