Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7d0f493

Browse files
committed
Add TAP tests for client programs
Reviewed-by: Pavel Stěhule <pavel.stehule@gmail.com> Reviewed-by: Erik Rijkers <er@xs4all.nl>
1 parent 7b5a9d6 commit 7d0f493

39 files changed

+745
-3
lines changed

GNUmakefile.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ check check-tests: all
6666
check check-tests installcheck installcheck-parallel installcheck-tests:
6767
$(MAKE) -C src/test/regress $@
6868

69-
$(call recurse,check-world,src/test src/pl src/interfaces/ecpg contrib,check)
69+
$(call recurse,check-world,src/test src/pl src/interfaces/ecpg contrib src/bin,check)
7070

71-
$(call recurse,installcheck-world,src/test src/pl src/interfaces/ecpg contrib,installcheck)
71+
$(call recurse,installcheck-world,src/test src/pl src/interfaces/ecpg contrib src/bin,installcheck)
7272

7373
GNUmakefile: GNUmakefile.in $(top_builddir)/config.status
7474
./config.status $@

configure

+47
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ ac_includes_default="\
627627

628628
ac_subst_vars='LTLIBOBJS
629629
vpath_build
630+
PROVE
630631
OSX
631632
XSLTPROC
632633
COLLATEINDEX
@@ -14350,6 +14351,52 @@ fi
1435014351
done
1435114352

1435214353

14354+
#
14355+
# Check for test tools
14356+
#
14357+
for ac_prog in prove
14358+
do
14359+
# Extract the first word of "$ac_prog", so it can be a program name with args.
14360+
set dummy $ac_prog; ac_word=$2
14361+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
14362+
$as_echo_n "checking for $ac_word... " >&6; }
14363+
if ${ac_cv_prog_PROVE+:} false; then :
14364+
$as_echo_n "(cached) " >&6
14365+
else
14366+
if test -n "$PROVE"; then
14367+
ac_cv_prog_PROVE="$PROVE" # Let the user override the test.
14368+
else
14369+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
14370+
for as_dir in $PATH
14371+
do
14372+
IFS=$as_save_IFS
14373+
test -z "$as_dir" && as_dir=.
14374+
for ac_exec_ext in '' $ac_executable_extensions; do
14375+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
14376+
ac_cv_prog_PROVE="$ac_prog"
14377+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
14378+
break 2
14379+
fi
14380+
done
14381+
done
14382+
IFS=$as_save_IFS
14383+
14384+
fi
14385+
fi
14386+
PROVE=$ac_cv_prog_PROVE
14387+
if test -n "$PROVE"; then
14388+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PROVE" >&5
14389+
$as_echo "$PROVE" >&6; }
14390+
else
14391+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
14392+
$as_echo "no" >&6; }
14393+
fi
14394+
14395+
14396+
test -n "$PROVE" && break
14397+
done
14398+
14399+
1435314400
# Thread testing
1435414401

1435514402
# We have to run the thread test near the end so we have all our symbols

configure.in

+5
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,11 @@ PGAC_PATH_COLLATEINDEX
18171817
AC_CHECK_PROGS(XSLTPROC, xsltproc)
18181818
AC_CHECK_PROGS(OSX, [osx sgml2xml sx])
18191819

1820+
#
1821+
# Check for test tools
1822+
#
1823+
AC_CHECK_PROGS(PROVE, prove)
1824+
18201825
# Thread testing
18211826

18221827
# We have to run the thread test near the end so we have all our symbols

doc/src/sgml/installation.sgml

+2-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ su - postgres
333333
<application>Perl</> 5.8 or later is needed to build from a Git checkout,
334334
or if you changed the input files for any of the build steps that
335335
use Perl scripts. If building on Windows you will need
336-
<application>Perl</> in any case.
336+
<application>Perl</> in any case. <application>Perl</application> is
337+
also required to run some test suites.
337338
</para>
338339
</listitem>
339340
</itemizedlist>

doc/src/sgml/regress.sgml

+28
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ make installcheck-world
204204
located in <filename>src/test/isolation</>.
205205
</para>
206206
</listitem>
207+
<listitem>
208+
<para>
209+
Tests of client programs under <filename>src/bin</filename>. See
210+
also <xref linkend="regress-tap">.
211+
</para>
212+
</listitem>
207213
</itemizedlist>
208214

209215
<para>
@@ -660,6 +666,28 @@ float8:out:i.86-.*-openbsd=float8-small-is-zero.out
660666

661667
</sect1>
662668

669+
<sect1 id="regress-tap">
670+
<title>TAP Tests</title>
671+
672+
<para>
673+
The client program tests under <filename>src/bin</filename> use the Perl
674+
TAP tools and are run by <command>prove</command>. You can pass
675+
command-line options to <command>prove</command> by setting
676+
the <command>make</command> variable <varname>PROVE_FLAGS</>, for example:
677+
<programlisting>
678+
make -C src/bin check PROVE_FLAGS='--reverse'
679+
</programlisting>
680+
The default is <literal>--verbose</literal>. See the manual page
681+
of <command>prove</command> for more information.
682+
</para>
683+
684+
<para>
685+
The tests written in Perl require the Perl
686+
module <literal>IPC::Run</literal>, otherwise most tests will be skipped.
687+
This module is available from CPAN or an operating system package.
688+
</para>
689+
</sect1>
690+
663691
<sect1 id="regress-coverage">
664692
<title>Test Coverage Examination</title>
665693

src/Makefile.global.in

+16
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,22 @@ XGETTEXT = @XGETTEXT@
292292
GZIP = gzip
293293
BZIP2 = bzip2
294294

295+
# Testing
296+
297+
PROVE = @PROVE@
298+
PG_PROVE_FLAGS = --ext='.pl' -I $(top_srcdir)/src/test/perl/
299+
PROVE_FLAGS = --verbose
300+
301+
define prove_installcheck
302+
PATH="$(bindir):$$PATH" PGPORT='6$(DEF_PGPORT)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS)
303+
endef
304+
305+
define prove_check
306+
$(MKDIR_P) tmp_check/log
307+
$(MAKE) -C $(top_builddir) DESTDIR=$(CURDIR)/tmp_check/install install >$(CURDIR)/tmp_check/log/install.log 2>&1
308+
PATH="$(CURDIR)/tmp_check/install$(bindir):$$PATH" PGPORT='6$(DEF_PGPORT)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS)
309+
endef
310+
295311
# Installation.
296312

297313
install_bin = @install_bin@

src/bin/initdb/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
/localtime.c
33

44
/initdb
5+
6+
/tmp_check/

src/bin/initdb/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ clean distclean maintainer-clean:
5757

5858
# ensure that changes in datadir propagate into object file
5959
initdb.o: initdb.c $(top_builddir)/src/Makefile.global
60+
61+
62+
check: all
63+
$(prove_check)
64+
65+
installcheck:
66+
$(prove_installcheck)

src/bin/initdb/t/001_initdb.pl

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use strict;
2+
use warnings;
3+
use TestLib;
4+
use Test::More tests => 14;
5+
6+
my $tempdir = TestLib::tempdir;
7+
8+
program_help_ok('initdb');
9+
program_version_ok('initdb');
10+
program_options_handling_ok('initdb');
11+
12+
command_ok(['initdb', "$tempdir/data"], 'basic initdb');
13+
command_fails(['initdb', "$tempdir/data"], 'existing data directory');
14+
command_ok(['initdb', '-N', "$tempdir/data2"], 'nosync');
15+
command_ok(['initdb', '-S', "$tempdir/data2"], 'sync only');
16+
command_fails(['initdb', '-S', "$tempdir/data3"], 'sync missing data directory');
17+
mkdir "$tempdir/data4" or BAIL_OUT($!);
18+
command_ok(['initdb', "$tempdir/data4"], 'existing empty data directory');
19+
20+
system_or_bail "rm -rf $tempdir/*";
21+
22+
command_ok(['initdb', "$tempdir/data", '-X', "$tempdir/pgxlog"], 'separate xlog directory');
23+
24+
system_or_bail "rm -rf $tempdir/*";
25+
command_fails(['initdb', "$tempdir/data", '-X', 'pgxlog'], 'relative xlog directory not allowed');
26+
27+
system_or_bail "rm -rf $tempdir/*";
28+
mkdir "$tempdir/pgxlog";
29+
command_ok(['initdb', "$tempdir/data", '-X', "$tempdir/pgxlog"], 'existing empty xlog directory');
30+
31+
system_or_bail "rm -rf $tempdir/*";
32+
mkdir "$tempdir/pgxlog";
33+
mkdir "$tempdir/pgxlog/lost+found";
34+
command_fails(['initdb', "$tempdir/data", '-X', "$tempdir/pgxlog"], 'existing nonempty xlog directory');
35+
36+
system_or_bail "rm -rf $tempdir/*";
37+
command_ok(['initdb', "$tempdir/data", '-T', 'german'], 'select default dictionary');

src/bin/pg_basebackup/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/pg_basebackup
22
/pg_receivexlog
33
/pg_recvlogical
4+
5+
/tmp_check/

src/bin/pg_basebackup/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ clean distclean maintainer-clean:
4848
rm -f pg_basebackup$(X) pg_receivexlog$(X) pg_recvlogical$(X) \
4949
pg_basebackup.o pg_receivexlog.o pg_recvlogical.o \
5050
$(OBJS)
51+
52+
check: all
53+
$(prove_check)
54+
55+
installcheck:
56+
$(prove_installcheck)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
use strict;
2+
use warnings;
3+
use Cwd;
4+
use TestLib;
5+
use Test::More tests => 28;
6+
7+
program_help_ok('pg_basebackup');
8+
program_version_ok('pg_basebackup');
9+
program_options_handling_ok('pg_basebackup');
10+
11+
my $tempdir = tempdir;
12+
start_test_server $tempdir;
13+
14+
command_fails(['pg_basebackup'], 'pg_basebackup needs target directory specified');
15+
command_fails(['pg_basebackup', '-D', "$tempdir/backup"], 'pg_basebackup fails because of hba');
16+
17+
open HBA, ">>$tempdir/pgdata/pg_hba.conf";
18+
print HBA "local replication all trust\n";
19+
print HBA "host replication all 127.0.0.1/32 trust\n";
20+
print HBA "host replication all ::1/128 trust\n";
21+
close HBA;
22+
system_or_bail 'pg_ctl', '-s', '-D', "$tempdir/pgdata", 'reload';
23+
24+
command_fails(['pg_basebackup', '-D', "$tempdir/backup"], 'pg_basebackup fails because of WAL configuration');
25+
26+
open CONF, ">>$tempdir/pgdata/postgresql.conf";
27+
print CONF "max_wal_senders = 10\n";
28+
print CONF "wal_level = archive\n";
29+
close CONF;
30+
restart_test_server;
31+
32+
command_ok(['pg_basebackup', '-D', "$tempdir/backup"], 'pg_basebackup runs');
33+
ok(-f "$tempdir/backup/PG_VERSION", 'backup was created');
34+
35+
command_ok(['pg_basebackup', '-D', "$tempdir/backup2", '--xlogdir', "$tempdir/xlog2"], 'separate xlog directory');
36+
ok(-f "$tempdir/backup2/PG_VERSION", 'backup was created');
37+
ok(-d "$tempdir/xlog2/", 'xlog directory was created');
38+
39+
command_ok(['pg_basebackup', '-D', "$tempdir/tarbackup", '-Ft'], 'tar format');
40+
ok(-f "$tempdir/tarbackup/base.tar", 'backup tar was created');
41+
42+
mkdir "$tempdir/tblspc1";
43+
psql 'postgres', "CREATE TABLESPACE tblspc1 LOCATION '$tempdir/tblspc1';";
44+
psql 'postgres', "CREATE TABLE test1 (a int) TABLESPACE tblspc1;";
45+
command_ok(['pg_basebackup', '-D', "$tempdir/tarbackup2", '-Ft'], 'tar format with tablespaces');
46+
ok(-f "$tempdir/tarbackup2/base.tar", 'backup tar was created');
47+
my @tblspc_tars = glob "$tempdir/tarbackup2/[0-9]*.tar";
48+
is(scalar(@tblspc_tars), 1, 'one tablespace tar was created');
49+
50+
command_fails(['pg_basebackup', '-D', "$tempdir/backup1", '-Fp'],
51+
'plain format with tablespaces fails without tablespace mapping');
52+
53+
command_ok(['pg_basebackup', '-D', "$tempdir/backup1", '-Fp',
54+
"-T$tempdir/tblspc1=$tempdir/tbackup/tblspc1"],
55+
'plain format with tablespaces succeeds with tablespace mapping');
56+
ok(-d "$tempdir/tbackup/tblspc1", 'tablespace was relocated');
57+
opendir(my $dh, "$tempdir/pgdata/pg_tblspc") or die;
58+
ok((grep { -l "$tempdir/backup1/pg_tblspc/$_" and readlink "$tempdir/backup1/pg_tblspc/$_" eq "$tempdir/tbackup/tblspc1" } readdir($dh)),
59+
"tablespace symlink was updated");
60+
closedir $dh;
61+
62+
mkdir "$tempdir/tbl=spc2";
63+
psql 'postgres', "DROP TABLE test1;";
64+
psql 'postgres', "DROP TABLESPACE tblspc1;";
65+
psql 'postgres', "CREATE TABLESPACE tblspc2 LOCATION '$tempdir/tbl=spc2';";
66+
command_ok(['pg_basebackup', '-D', "$tempdir/backup3", '-Fp',
67+
"-T$tempdir/tbl\\=spc2=$tempdir/tbackup/tbl\\=spc2"],
68+
'mapping tablespace with = sign in path');
69+
ok(-d "$tempdir/tbackup/tbl=spc2", 'tablespace with = sign was relocated');
70+
71+
psql 'postgres', "DROP TABLESPACE tblspc2;";
72+
73+
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
74+
"-T=/foo"],
75+
'-T with empty old directory fails');
76+
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
77+
"-T/foo="],
78+
'-T with empty new directory fails');
79+
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
80+
"-T/foo=/bar=/baz"],
81+
'-T with multiple = fails');
82+
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
83+
"-Tfoo=/bar"],
84+
'-T with old directory not absolute fails');
85+
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
86+
"-T/foo=bar"],
87+
'-T with new directory not absolute fails');
88+
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
89+
"-Tfoo"],
90+
'-T with invalid format fails');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use strict;
2+
use warnings;
3+
use TestLib;
4+
use Test::More tests => 3;
5+
6+
program_help_ok('pg_receivexlog');
7+
program_version_ok('pg_receivexlog');
8+
program_options_handling_ok('pg_receivexlog');

src/bin/pg_config/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/pg_config
2+
/tmp_check/

src/bin/pg_config/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ uninstall:
4747

4848
clean distclean maintainer-clean:
4949
rm -f pg_config$(X) $(OBJS)
50+
51+
check: all
52+
$(prove_check)
53+
54+
installcheck:
55+
$(prove_installcheck)

src/bin/pg_config/t/001_pg_config.pl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use strict;
2+
use warnings;
3+
use TestLib;
4+
use Test::More tests => 7;
5+
6+
program_help_ok('pg_config');
7+
program_version_ok('pg_config');
8+
program_options_handling_ok('pg_config');
9+
command_like(['pg_config', '--bindir'], qr/bin/, 'pg_config single option'); # XXX might be wrong
10+
command_like(['pg_config', '--bindir', '--libdir'], qr/bin.*\n.*lib/, 'pg_config two options');
11+
command_like(['pg_config', '--libdir', '--bindir'], qr/lib.*\n.*bin/, 'pg_config two options different order');
12+
command_like(['pg_config'], qr/.*\n.*\n.*/, 'pg_config without options prints many lines');

src/bin/pg_controldata/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/pg_controldata
2+
/tmp_check/

src/bin/pg_controldata/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ uninstall:
3333

3434
clean distclean maintainer-clean:
3535
rm -f pg_controldata$(X) $(OBJS)
36+
37+
check: all
38+
$(prove_check)
39+
40+
installcheck:
41+
$(prove_installcheck)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use strict;
2+
use warnings;
3+
use TestLib;
4+
use Test::More tests => 6;
5+
6+
my $tempdir = TestLib::tempdir;
7+
8+
program_help_ok('pg_controldata');
9+
program_version_ok('pg_controldata');
10+
program_options_handling_ok('pg_controldata');
11+
command_fails(['pg_controldata'], 'pg_controldata without arguments fails');
12+
command_fails(['pg_controldata', 'nonexistent'], 'pg_controldata with nonexistent directory fails');
13+
system_or_bail "initdb -D $tempdir/data -A trust >/dev/null";
14+
command_like(['pg_controldata', "$tempdir/data"], qr/checkpoint/, 'pg_controldata produces output');

src/bin/pg_ctl/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/pg_ctl
2+
/tmp_check/

src/bin/pg_ctl/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ uninstall:
3636

3737
clean distclean maintainer-clean:
3838
rm -f pg_ctl$(X) $(OBJS)
39+
40+
check: all
41+
$(prove_check)
42+
43+
installcheck:
44+
$(prove_installcheck)

0 commit comments

Comments
 (0)