From 7d92cbfd0607fbf35902408e3a82bf2ca60bf71f Mon Sep 17 00:00:00 2001
From: Michael Paquier <mpaquier@otacoo.com>
Date: Sat, 25 Oct 2014 08:14:37 +0000
Subject: [PATCH 2/2] Add TAP tests for pg_resetxlog

Those checks are related to extra arguments, the use of option -D with
a data directory as well as the generation of output for this utility.
---
 src/bin/pg_resetxlog/.gitignore            |  1 +
 src/bin/pg_resetxlog/Makefile              |  6 ++++++
 src/bin/pg_resetxlog/t/001_pg_resetxlog.pl | 24 ++++++++++++++++++++++++
 3 files changed, 31 insertions(+)
 create mode 100644 src/bin/pg_resetxlog/t/001_pg_resetxlog.pl

diff --git a/src/bin/pg_resetxlog/.gitignore b/src/bin/pg_resetxlog/.gitignore
index 6b84208..68d8890 100644
--- a/src/bin/pg_resetxlog/.gitignore
+++ b/src/bin/pg_resetxlog/.gitignore
@@ -1 +1,2 @@
 /pg_resetxlog
+/tmp_check/
diff --git a/src/bin/pg_resetxlog/Makefile b/src/bin/pg_resetxlog/Makefile
index 6610690..5ebf8f4 100644
--- a/src/bin/pg_resetxlog/Makefile
+++ b/src/bin/pg_resetxlog/Makefile
@@ -33,3 +33,9 @@ uninstall:
 
 clean distclean maintainer-clean:
 	rm -f pg_resetxlog$(X) $(OBJS)
+
+check: all
+	$(prove_check)
+
+installcheck:
+	$(prove_installcheck)
diff --git a/src/bin/pg_resetxlog/t/001_pg_resetxlog.pl b/src/bin/pg_resetxlog/t/001_pg_resetxlog.pl
new file mode 100644
index 0000000..4e6e0a7
--- /dev/null
+++ b/src/bin/pg_resetxlog/t/001_pg_resetxlog.pl
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+use TestLib;
+use Test::More tests => 10;
+
+my $tempdir = TestLib::tempdir;
+
+program_help_ok('pg_resetxlog');
+program_version_ok('pg_resetxlog');
+program_options_handling_ok('pg_resetxlog');
+command_fails(['pg_resetxlog'], 'pg_resetxlog without arguments fails');
+command_fails([ 'pg_resetxlog', 'nonexistent' ],
+	'pg_resetxlog with nonexistent directory fails');
+command_fails([ 'pg_resetxlog', 'arg1', 'arg2', 'arg3' ],
+	'pg_resetxlog with too many arguments fails');
+command_fails([ 'pg_resetxlog', '-D' ],
+	'pg_resetxlog -D with no directory defined fails');
+command_fails([ 'pg_resetxlog', '-D', 'arg1', 'arg2', 'arg3' ],
+	'pg_resetxlog -D with too many arguments fails');
+system_or_bail "initdb -D '$tempdir'/data -A trust >/dev/null";
+command_like([ 'pg_resetxlog', "$tempdir/data" ],
+	qr/Transaction/, 'pg_resetxlog produces output');
+command_like([ 'pg_resetxlog', "-D", "$tempdir/data" ],
+	qr/Transaction/, 'pg_resetxlog produces output');
-- 
2.1.2

