• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..08-Nov-2021-

MakefileH A D08-Nov-20211.1 KiB3417

PostgresNode.pmH A D08-Nov-202143.5 KiB1,808815

READMEH A D08-Nov-20212.3 KiB6646

RecursiveCopy.pmH A D08-Nov-20213.8 KiB15567

SimpleTee.pmH A D08-Nov-2021606 3219

TestLib.pmH A D08-Nov-20219.4 KiB407291

README

1Perl-based TAP tests
2====================
3
4src/test/perl/ contains shared infrastructure that's used by Perl-based tests
5across the source tree, particularly tests in src/bin and src/test. It's used
6to drive tests for backup and restore, replication, etc - anything that can't
7really be expressed using pg_regress or the isolation test framework.
8
9You should prefer to write tests using pg_regress in src/test/regress, or
10isolation tester specs in src/test/isolation, if possible. If not, check to
11see if your new tests make sense under an existing tree in src/test, like
12src/test/ssl, or should be added to one of the suites for an existing utility.
13
14Note that all tests and test tools should have perltidy run on them before
15patches are submitted, using perltidy --profile=src/tools/pgindent/perltidyrc
16
17By default, to keep the noise low during runs, we do not set any flags via
18PROVE_FLAGS, but this can be done on the 'make' command line if desired, eg:
19
20make check-world PROVE_FLAGS='--verbose'
21
22Writing tests
23-------------
24
25Tests are written using Perl's Test::More with some PostgreSQL-specific
26infrastructure from src/test/perl providing node management, support for
27invoking 'psql' to run queries and get results, etc. You should read the
28documentation for Test::More before trying to write tests.
29
30Test scripts in the t/ subdirectory of a suite are executed in alphabetical
31order.
32
33Each test script should begin with:
34
35    use strict;
36    use warnings;
37    use PostgresNode;
38    use TestLib;
39    # Replace with the number of tests to execute:
40    use Test::More tests => 1;
41
42then it will generally need to set up one or more nodes, run commands
43against them and evaluate the results. For example:
44
45    my $node = PostgresNode->get_new_node('master');
46    $node->init;
47    $node->start;
48
49    my $ret = $node->safe_psql('postgres', 'SELECT 1');
50    is($ret, '1', 'SELECT 1 returns 1');
51
52    $node->stop('fast');
53
54Test::More::like entails use of the qr// operator.  Avoid Perl 5.8.8 bug
55#39185 by not using the "$" regular expression metacharacter in qr// when also
56using the "/m" modifier.  Instead of "$", use "\n" or "(?=\n|\z)".
57
58Read the Test::More documentation for more on how to write tests:
59
60    perldoc Test::More
61
62For available PostgreSQL-specific test methods and some example tests read the
63perldoc for the test modules, e.g.:
64
65    perldoc src/test/perl/PostgresNode.pm
66