Skip to content

Commit

Permalink
Add TAP tests for client programs
Browse files Browse the repository at this point in the history
Reviewed-by: Pavel Stěhule <[email protected]>
Reviewed-by: Erik Rijkers <[email protected]>
  • Loading branch information
petere committed Apr 15, 2014
1 parent 7b5a9d6 commit 7d0f493
Show file tree
Hide file tree
Showing 39 changed files with 745 additions and 3 deletions.
4 changes: 2 additions & 2 deletions GNUmakefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ check check-tests: all
check check-tests installcheck installcheck-parallel installcheck-tests:
$(MAKE) -C src/test/regress $@

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

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

GNUmakefile: GNUmakefile.in $(top_builddir)/config.status
./config.status $@
Expand Down
47 changes: 47 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ ac_includes_default="\

ac_subst_vars='LTLIBOBJS
vpath_build
PROVE
OSX
XSLTPROC
COLLATEINDEX
Expand Down Expand Up @@ -14350,6 +14351,52 @@ fi
done


#
# Check for test tools
#
for ac_prog in prove
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_PROVE+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$PROVE"; then
ac_cv_prog_PROVE="$PROVE" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_PROVE="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS

fi
fi
PROVE=$ac_cv_prog_PROVE
if test -n "$PROVE"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PROVE" >&5
$as_echo "$PROVE" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


test -n "$PROVE" && break
done


# Thread testing

# We have to run the thread test near the end so we have all our symbols
Expand Down
5 changes: 5 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,11 @@ PGAC_PATH_COLLATEINDEX
AC_CHECK_PROGS(XSLTPROC, xsltproc)
AC_CHECK_PROGS(OSX, [osx sgml2xml sx])

#
# Check for test tools
#
AC_CHECK_PROGS(PROVE, prove)

# Thread testing

# We have to run the thread test near the end so we have all our symbols
Expand Down
3 changes: 2 additions & 1 deletion doc/src/sgml/installation.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ su - postgres
<application>Perl</> 5.8 or later is needed to build from a Git checkout,
or if you changed the input files for any of the build steps that
use Perl scripts. If building on Windows you will need
<application>Perl</> in any case.
<application>Perl</> in any case. <application>Perl</application> is
also required to run some test suites.
</para>
</listitem>
</itemizedlist>
Expand Down
28 changes: 28 additions & 0 deletions doc/src/sgml/regress.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ make installcheck-world
located in <filename>src/test/isolation</>.
</para>
</listitem>
<listitem>
<para>
Tests of client programs under <filename>src/bin</filename>. See
also <xref linkend="regress-tap">.
</para>
</listitem>
</itemizedlist>

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

</sect1>

<sect1 id="regress-tap">
<title>TAP Tests</title>

<para>
The client program tests under <filename>src/bin</filename> use the Perl
TAP tools and are run by <command>prove</command>. You can pass
command-line options to <command>prove</command> by setting
the <command>make</command> variable <varname>PROVE_FLAGS</>, for example:
<programlisting>
make -C src/bin check PROVE_FLAGS='--reverse'
</programlisting>
The default is <literal>--verbose</literal>. See the manual page
of <command>prove</command> for more information.
</para>

<para>
The tests written in Perl require the Perl
module <literal>IPC::Run</literal>, otherwise most tests will be skipped.
This module is available from CPAN or an operating system package.
</para>
</sect1>

<sect1 id="regress-coverage">
<title>Test Coverage Examination</title>

Expand Down
16 changes: 16 additions & 0 deletions src/Makefile.global.in
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,22 @@ XGETTEXT = @XGETTEXT@
GZIP = gzip
BZIP2 = bzip2

# Testing

PROVE = @PROVE@
PG_PROVE_FLAGS = --ext='.pl' -I $(top_srcdir)/src/test/perl/
PROVE_FLAGS = --verbose

define prove_installcheck
PATH="$(bindir):$$PATH" PGPORT='6$(DEF_PGPORT)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS)
endef

define prove_check
$(MKDIR_P) tmp_check/log
$(MAKE) -C $(top_builddir) DESTDIR=$(CURDIR)/tmp_check/install install >$(CURDIR)/tmp_check/log/install.log 2>&1
PATH="$(CURDIR)/tmp_check/install$(bindir):$$PATH" PGPORT='6$(DEF_PGPORT)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS)
endef

# Installation.

install_bin = @install_bin@
Expand Down
2 changes: 2 additions & 0 deletions src/bin/initdb/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/localtime.c

/initdb

/tmp_check/
7 changes: 7 additions & 0 deletions src/bin/initdb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ clean distclean maintainer-clean:

# ensure that changes in datadir propagate into object file
initdb.o: initdb.c $(top_builddir)/src/Makefile.global


check: all
$(prove_check)

installcheck:
$(prove_installcheck)
37 changes: 37 additions & 0 deletions src/bin/initdb/t/001_initdb.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use strict;
use warnings;
use TestLib;
use Test::More tests => 14;

my $tempdir = TestLib::tempdir;

program_help_ok('initdb');
program_version_ok('initdb');
program_options_handling_ok('initdb');

command_ok(['initdb', "$tempdir/data"], 'basic initdb');
command_fails(['initdb', "$tempdir/data"], 'existing data directory');
command_ok(['initdb', '-N', "$tempdir/data2"], 'nosync');
command_ok(['initdb', '-S', "$tempdir/data2"], 'sync only');
command_fails(['initdb', '-S', "$tempdir/data3"], 'sync missing data directory');
mkdir "$tempdir/data4" or BAIL_OUT($!);
command_ok(['initdb', "$tempdir/data4"], 'existing empty data directory');

system_or_bail "rm -rf $tempdir/*";

command_ok(['initdb', "$tempdir/data", '-X', "$tempdir/pgxlog"], 'separate xlog directory');

system_or_bail "rm -rf $tempdir/*";
command_fails(['initdb', "$tempdir/data", '-X', 'pgxlog'], 'relative xlog directory not allowed');

system_or_bail "rm -rf $tempdir/*";
mkdir "$tempdir/pgxlog";
command_ok(['initdb', "$tempdir/data", '-X', "$tempdir/pgxlog"], 'existing empty xlog directory');

system_or_bail "rm -rf $tempdir/*";
mkdir "$tempdir/pgxlog";
mkdir "$tempdir/pgxlog/lost+found";
command_fails(['initdb', "$tempdir/data", '-X', "$tempdir/pgxlog"], 'existing nonempty xlog directory');

system_or_bail "rm -rf $tempdir/*";
command_ok(['initdb', "$tempdir/data", '-T', 'german'], 'select default dictionary');
2 changes: 2 additions & 0 deletions src/bin/pg_basebackup/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/pg_basebackup
/pg_receivexlog
/pg_recvlogical

/tmp_check/
6 changes: 6 additions & 0 deletions src/bin/pg_basebackup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ clean distclean maintainer-clean:
rm -f pg_basebackup$(X) pg_receivexlog$(X) pg_recvlogical$(X) \
pg_basebackup.o pg_receivexlog.o pg_recvlogical.o \
$(OBJS)

check: all
$(prove_check)

installcheck:
$(prove_installcheck)
90 changes: 90 additions & 0 deletions src/bin/pg_basebackup/t/010_pg_basebackup.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use strict;
use warnings;
use Cwd;
use TestLib;
use Test::More tests => 28;

program_help_ok('pg_basebackup');
program_version_ok('pg_basebackup');
program_options_handling_ok('pg_basebackup');

my $tempdir = tempdir;
start_test_server $tempdir;

command_fails(['pg_basebackup'], 'pg_basebackup needs target directory specified');
command_fails(['pg_basebackup', '-D', "$tempdir/backup"], 'pg_basebackup fails because of hba');

open HBA, ">>$tempdir/pgdata/pg_hba.conf";
print HBA "local replication all trust\n";
print HBA "host replication all 127.0.0.1/32 trust\n";
print HBA "host replication all ::1/128 trust\n";
close HBA;
system_or_bail 'pg_ctl', '-s', '-D', "$tempdir/pgdata", 'reload';

command_fails(['pg_basebackup', '-D', "$tempdir/backup"], 'pg_basebackup fails because of WAL configuration');

open CONF, ">>$tempdir/pgdata/postgresql.conf";
print CONF "max_wal_senders = 10\n";
print CONF "wal_level = archive\n";
close CONF;
restart_test_server;

command_ok(['pg_basebackup', '-D', "$tempdir/backup"], 'pg_basebackup runs');
ok(-f "$tempdir/backup/PG_VERSION", 'backup was created');

command_ok(['pg_basebackup', '-D', "$tempdir/backup2", '--xlogdir', "$tempdir/xlog2"], 'separate xlog directory');
ok(-f "$tempdir/backup2/PG_VERSION", 'backup was created');
ok(-d "$tempdir/xlog2/", 'xlog directory was created');

command_ok(['pg_basebackup', '-D', "$tempdir/tarbackup", '-Ft'], 'tar format');
ok(-f "$tempdir/tarbackup/base.tar", 'backup tar was created');

mkdir "$tempdir/tblspc1";
psql 'postgres', "CREATE TABLESPACE tblspc1 LOCATION '$tempdir/tblspc1';";
psql 'postgres', "CREATE TABLE test1 (a int) TABLESPACE tblspc1;";
command_ok(['pg_basebackup', '-D', "$tempdir/tarbackup2", '-Ft'], 'tar format with tablespaces');
ok(-f "$tempdir/tarbackup2/base.tar", 'backup tar was created');
my @tblspc_tars = glob "$tempdir/tarbackup2/[0-9]*.tar";
is(scalar(@tblspc_tars), 1, 'one tablespace tar was created');

command_fails(['pg_basebackup', '-D', "$tempdir/backup1", '-Fp'],
'plain format with tablespaces fails without tablespace mapping');

command_ok(['pg_basebackup', '-D', "$tempdir/backup1", '-Fp',
"-T$tempdir/tblspc1=$tempdir/tbackup/tblspc1"],
'plain format with tablespaces succeeds with tablespace mapping');
ok(-d "$tempdir/tbackup/tblspc1", 'tablespace was relocated');
opendir(my $dh, "$tempdir/pgdata/pg_tblspc") or die;
ok((grep { -l "$tempdir/backup1/pg_tblspc/$_" and readlink "$tempdir/backup1/pg_tblspc/$_" eq "$tempdir/tbackup/tblspc1" } readdir($dh)),
"tablespace symlink was updated");
closedir $dh;

mkdir "$tempdir/tbl=spc2";
psql 'postgres', "DROP TABLE test1;";
psql 'postgres', "DROP TABLESPACE tblspc1;";
psql 'postgres', "CREATE TABLESPACE tblspc2 LOCATION '$tempdir/tbl=spc2';";
command_ok(['pg_basebackup', '-D', "$tempdir/backup3", '-Fp',
"-T$tempdir/tbl\\=spc2=$tempdir/tbackup/tbl\\=spc2"],
'mapping tablespace with = sign in path');
ok(-d "$tempdir/tbackup/tbl=spc2", 'tablespace with = sign was relocated');

psql 'postgres', "DROP TABLESPACE tblspc2;";

command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
"-T=/foo"],
'-T with empty old directory fails');
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
"-T/foo="],
'-T with empty new directory fails');
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
"-T/foo=/bar=/baz"],
'-T with multiple = fails');
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
"-Tfoo=/bar"],
'-T with old directory not absolute fails');
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
"-T/foo=bar"],
'-T with new directory not absolute fails');
command_fails(['pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp',
"-Tfoo"],
'-T with invalid format fails');
8 changes: 8 additions & 0 deletions src/bin/pg_basebackup/t/020_pg_receivexlog.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use strict;
use warnings;
use TestLib;
use Test::More tests => 3;

program_help_ok('pg_receivexlog');
program_version_ok('pg_receivexlog');
program_options_handling_ok('pg_receivexlog');
1 change: 1 addition & 0 deletions src/bin/pg_config/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/pg_config
/tmp_check/
6 changes: 6 additions & 0 deletions src/bin/pg_config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ uninstall:

clean distclean maintainer-clean:
rm -f pg_config$(X) $(OBJS)

check: all
$(prove_check)

installcheck:
$(prove_installcheck)
12 changes: 12 additions & 0 deletions src/bin/pg_config/t/001_pg_config.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use strict;
use warnings;
use TestLib;
use Test::More tests => 7;

program_help_ok('pg_config');
program_version_ok('pg_config');
program_options_handling_ok('pg_config');
command_like(['pg_config', '--bindir'], qr/bin/, 'pg_config single option'); # XXX might be wrong
command_like(['pg_config', '--bindir', '--libdir'], qr/bin.*\n.*lib/, 'pg_config two options');
command_like(['pg_config', '--libdir', '--bindir'], qr/lib.*\n.*bin/, 'pg_config two options different order');
command_like(['pg_config'], qr/.*\n.*\n.*/, 'pg_config without options prints many lines');
1 change: 1 addition & 0 deletions src/bin/pg_controldata/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/pg_controldata
/tmp_check/
6 changes: 6 additions & 0 deletions src/bin/pg_controldata/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ uninstall:

clean distclean maintainer-clean:
rm -f pg_controldata$(X) $(OBJS)

check: all
$(prove_check)

installcheck:
$(prove_installcheck)
14 changes: 14 additions & 0 deletions src/bin/pg_controldata/t/001_pg_controldata.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use strict;
use warnings;
use TestLib;
use Test::More tests => 6;

my $tempdir = TestLib::tempdir;

program_help_ok('pg_controldata');
program_version_ok('pg_controldata');
program_options_handling_ok('pg_controldata');
command_fails(['pg_controldata'], 'pg_controldata without arguments fails');
command_fails(['pg_controldata', 'nonexistent'], 'pg_controldata with nonexistent directory fails');
system_or_bail "initdb -D $tempdir/data -A trust >/dev/null";
command_like(['pg_controldata', "$tempdir/data"], qr/checkpoint/, 'pg_controldata produces output');
1 change: 1 addition & 0 deletions src/bin/pg_ctl/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/pg_ctl
/tmp_check/
6 changes: 6 additions & 0 deletions src/bin/pg_ctl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ uninstall:

clean distclean maintainer-clean:
rm -f pg_ctl$(X) $(OBJS)

check: all
$(prove_check)

installcheck:
$(prove_installcheck)
Loading

0 comments on commit 7d0f493

Please sign in to comment.