mirror of
https://github.com/postgres/postgres.git
synced 2026-01-05 23:38:41 +03:00
The previous text didn't provide any clear explanation of our policy around TAP test portability. The recipe for using perlbrew had some problems, too: it resulted in a non-shared libperl (preventing testing of plperl) and it caused some modules to be updated to current when the point of the recipe is to build an old environment. Discussion: https://postgr.es/m/E1mYY6Z-0006OL-QN@gemulon.postgresql.org
106 lines
4.0 KiB
Plaintext
106 lines
4.0 KiB
Plaintext
Perl-based TAP tests
|
|
====================
|
|
|
|
src/test/perl/ contains shared infrastructure that's used by Perl-based tests
|
|
across the source tree, particularly tests in src/bin and src/test. It's used
|
|
to drive tests for backup and restore, replication, etc - anything that can't
|
|
really be expressed using pg_regress or the isolation test framework.
|
|
|
|
The tests are invoked via perl's 'prove' command, wrapped in PostgreSQL
|
|
makefiles to handle instance setup etc. See the $(prove_check) and
|
|
$(prove_installcheck) targets in Makefile.global. By default every test in the
|
|
t/ subdirectory is run. Individual test(s) can be run instead by passing
|
|
something like PROVE_TESTS="t/001_testname.pl t/002_othertestname.pl" to make.
|
|
|
|
You should prefer to write tests using pg_regress in src/test/regress, or
|
|
isolation tester specs in src/test/isolation, if possible. If not, check to
|
|
see if your new tests make sense under an existing tree in src/test, like
|
|
src/test/ssl, or should be added to one of the suites for an existing utility.
|
|
|
|
Note that all tests and test tools should have perltidy run on them before
|
|
patches are submitted, using perltidy --profile=src/tools/pgindent/perltidyrc
|
|
|
|
By default, to keep the noise low during runs, we do not set any flags via
|
|
PROVE_FLAGS, but this can be done on the 'make' command line if desired, eg:
|
|
|
|
make check-world PROVE_FLAGS='--verbose'
|
|
|
|
Writing tests
|
|
-------------
|
|
|
|
Tests are written using Perl's Test::More with some PostgreSQL-specific
|
|
infrastructure from src/test/perl providing node management, support for
|
|
invoking 'psql' to run queries and get results, etc. You should read the
|
|
documentation for Test::More before trying to write tests.
|
|
|
|
Test scripts in the t/ subdirectory of a suite are executed in alphabetical
|
|
order.
|
|
|
|
Each test script should begin with:
|
|
|
|
use strict;
|
|
use warnings;
|
|
use PostgresNode;
|
|
use TestLib;
|
|
# Replace with the number of tests to execute:
|
|
use Test::More tests => 1;
|
|
|
|
then it will generally need to set up one or more nodes, run commands
|
|
against them and evaluate the results. For example:
|
|
|
|
my $node = PostgresNode->new('primary');
|
|
$node->init;
|
|
$node->start;
|
|
|
|
my $ret = $node->safe_psql('postgres', 'SELECT 1');
|
|
is($ret, '1', 'SELECT 1 returns 1');
|
|
|
|
$node->stop('fast');
|
|
|
|
Test::More::like entails use of the qr// operator. Avoid Perl 5.8.8 bug
|
|
#39185 by not using the "$" regular expression metacharacter in qr// when also
|
|
using the "/m" modifier. Instead of "$", use "\n" or "(?=\n|\z)".
|
|
|
|
Read the Test::More documentation for more on how to write tests:
|
|
|
|
perldoc Test::More
|
|
|
|
For available PostgreSQL-specific test methods and some example tests read the
|
|
perldoc for the test modules, e.g.:
|
|
|
|
perldoc src/test/perl/PostgresNode.pm
|
|
|
|
Portability
|
|
-----------
|
|
|
|
Avoid using any bleeding-edge Perl features. We have buildfarm animals
|
|
running Perl versions as old as 5.8.3, so your tests will be expected
|
|
to pass on that.
|
|
|
|
Also, do not use any non-core Perl modules except IPC::Run. Or, if you
|
|
must do so for a particular test, arrange to skip the test when the needed
|
|
module isn't present. If unsure, you can consult Module::CoreList to find
|
|
out whether a given module is part of the Perl core, and which module
|
|
versions shipped with which Perl releases.
|
|
|
|
One way to test for compatibility with old Perl versions is to use
|
|
perlbrew; see http://perlbrew.pl . After installing that, do
|
|
|
|
export PERLBREW_CONFIGURE_FLAGS='-de -Duseshrplib'
|
|
perlbrew --force install 5.8.3
|
|
perlbrew use 5.8.3
|
|
perlbrew install-cpanm
|
|
cpanm install Test::Simple@0.87_01
|
|
cpanm install IPC::Run@0.79
|
|
cpanm install ExtUtils::MakeMaker@6.50 # downgrade
|
|
|
|
Then re-run Postgres' configure to ensure the correct Perl is used when
|
|
running tests. To verify that the right Perl was found:
|
|
|
|
grep ^PERL= config.log
|
|
|
|
Due to limitations of cpanm, this recipe doesn't exactly duplicate the
|
|
module list of older buildfarm animals. The discrepancies should seldom
|
|
matter, but if you want to be sure, bypass cpanm and instead manually
|
|
install the desired versions of Test::Simple and IPC::Run.
|