[debhelper-devel] [debhelper] 16/30: dh_installdocs.t: Migrate to Test::DH

Niels Thykier nthykier at moszumanska.debian.org
Mon Jul 3 14:40:37 UTC 2017


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository debhelper.

commit 6e6307bb10e8118ea1d5086ff4e3803fcfef1b2a
Author: Niels Thykier <niels at thykier.net>
Date:   Sun Jul 2 15:52:02 2017 +0000

    dh_installdocs.t: Migrate to Test::DH
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 t/dh_installdocs/debian/copyright |   1 +
 t/dh_installdocs/dh_installdocs.t | 119 +++++++++++++++++++-------------------
 2 files changed, 60 insertions(+), 60 deletions(-)

diff --git a/t/dh_installdocs/debian/copyright b/t/dh_installdocs/debian/copyright
new file mode 100644
index 0000000..7e6ffb0
--- /dev/null
+++ b/t/dh_installdocs/debian/copyright
@@ -0,0 +1 @@
+Some test copyright file
diff --git a/t/dh_installdocs/dh_installdocs.t b/t/dh_installdocs/dh_installdocs.t
index e4b2e76..34d5a3b 100755
--- a/t/dh_installdocs/dh_installdocs.t
+++ b/t/dh_installdocs/dh_installdocs.t
@@ -1,83 +1,82 @@
 #!/usr/bin/perl
 use strict;
+use warnings;
 use Test::More;
-use File::Basename ();
 
-# Let the tests be run from anywhere, but current directory
-# is expected to be the one where this test lives in.
-chdir File::Basename::dirname($0) or die "Unable to chdir to ".File::Basename::dirname($0);
 
-my $TOPDIR = "../..";
-my $rootcmd;
+use File::Path qw(remove_tree);
+use File::Basename qw(dirname);
+use lib dirname(dirname(__FILE__));
+use Test::DH;
 
-if ($< == 0) {
-	$rootcmd = '';
-}
-else {
-	system("fakeroot true 2>/dev/null");
-	$rootcmd = $? ? undef : 'fakeroot';
-}
+our @TEST_DH_EXTRA_TEMPLATE_FILES = (qw(
+    debian/changelog
+    debian/control
+    debian/docfile
+    debian/copyright
+));
 
-if (not defined($rootcmd)) {
+if (uid_0_test_is_ok()) {
+	plan(tests => 5);
+} else {
 	plan skip_all => 'fakeroot required';
 }
-else {
-	plan(tests => 18);
-}
 
-# Drop DEB_BUILD_PROFILES and DEB_BUILD_OPTIONS so they don't interfere
-delete($ENV{DEB_BUILD_PROFILES});
-delete($ENV{DEB_BUILD_OPTIONS});
-
-system("rm -rf debian/foo debian/bar debian/baz");
+my $NEEDS_ROOT = { 'needs_root' => 1 };
+my $NEEDS_ROOT_NODOC_PROFILE = {
+	'needs_root' => 1,
+	'env' => {
+		'DEB_BUILD_PROFILES' => 'nodoc',
+	},
+};
 
 my $doc = "debian/docfile";
 
-system("$rootcmd $TOPDIR/dh_installdocs -pbar $doc");
-ok(-e "debian/bar/usr/share/doc/bar/docfile");
-system("rm -rf debian/foo debian/bar debian/baz");
+each_compat_subtest {
+	ok(run_dh_tool($NEEDS_ROOT, 'dh_installdocs', '-pbar', $doc));
+	ok(-e "debian/bar/usr/share/doc/bar/docfile");
+	remove_tree(qw(debian/foo debian/bar debian/baz));
+};
 
-#regression in debhelper 9.20160702 (#830309)
-system("$rootcmd $TOPDIR/dh_installdocs -pbaz --link-doc=foo $doc");
-ok(-l "debian/baz/usr/share/doc/baz");
-ok(readlink("debian/baz/usr/share/doc/baz") eq 'foo');
-ok(-e "debian/baz/usr/share/doc/foo/docfile");
-system("rm -rf debian/foo debian/bar debian/baz");
+each_compat_subtest {
+	#regression in debhelper 9.20160702 (#830309)
+	ok(run_dh_tool($NEEDS_ROOT, 'dh_installdocs', '-pbaz', '--link-doc=foo', $doc));
 
-system("DH_COMPAT=11 $rootcmd $TOPDIR/dh_installdocs -pbaz --link-doc=foo $doc");
-ok(-l "debian/baz/usr/share/doc/baz");
-ok(readlink("debian/baz/usr/share/doc/baz") eq 'foo');
-ok(-e "debian/baz/usr/share/doc/foo/docfile");
-system("rm -rf debian/foo debian/bar debian/baz");
+	ok(-l "debian/baz/usr/share/doc/baz");
+	ok(readlink("debian/baz/usr/share/doc/baz") eq 'foo');
+	ok(-e "debian/baz/usr/share/doc/foo/docfile");
+	remove_tree(qw(debian/foo debian/bar debian/baz));
+};
 
-system("$rootcmd $TOPDIR/dh_installdocs -pfoo --link-doc=bar $doc");
-ok(-l "debian/foo/usr/share/doc/foo");
-ok(readlink("debian/foo/usr/share/doc/foo") eq 'bar');
-ok(-e "debian/foo/usr/share/doc/bar/docfile");
-system("rm -rf debian/foo debian/bar debian/baz");
+each_compat_subtest {
+	ok(run_dh_tool($NEEDS_ROOT, 'dh_installdocs', '-pfoo', '--link-doc=bar', $doc));
 
-system("DH_COMPAT=11 $rootcmd $TOPDIR/dh_installdocs -pfoo --link-doc=bar $doc");
-ok(-l "debian/foo/usr/share/doc/foo");
-ok(readlink("debian/foo/usr/share/doc/foo") eq 'bar');
-ok(-e "debian/foo/usr/share/doc/bar/docfile");
-system("rm -rf debian/foo debian/bar debian/baz");
+	ok(-l "debian/foo/usr/share/doc/foo");
+	ok(readlink("debian/foo/usr/share/doc/foo") eq 'bar');
+	ok(-e "debian/foo/usr/share/doc/bar/docfile");
+	remove_tree(qw(debian/foo debian/bar debian/baz));
+};
 
 # ... and with nodoc
 
-# docs are ignored, but copyright file is still there
-system("DEB_BUILD_PROFILES=nodoc $rootcmd $TOPDIR/dh_installdocs -pbar $doc");
-ok(!-e "debian/bar/usr/share/doc/bar/docfile");
-ok(!-e "debian/bar/usr/share/doc/bar/copyright");
-system("rm -rf debian/foo debian/bar debian/baz");
-
-# docs are ignored, but symlinked doc dir is still there
-system("DEB_BUILD_PROFILES=nodoc DH_COMPAT=11 $rootcmd $TOPDIR/dh_installdocs -pfoo --link-doc=bar $doc");
-ok(-l "debian/foo/usr/share/doc/foo");
-ok(readlink("debian/foo/usr/share/doc/foo") eq 'bar');
-ok(!-e "debian/foo/usr/share/doc/bar/docfile");
-system("rm -rf debian/foo debian/bar debian/baz");
-
-system("$TOPDIR/dh_clean");
+each_compat_subtest {
+	# docs are ignored, but copyright file is still there
+	ok(run_dh_tool($NEEDS_ROOT_NODOC_PROFILE, 'dh_installdocs', $doc));
+	for my $pkg (qw(foo bar baz)) {
+		ok(! -e "debian/$pkg/usr/share/doc/$pkg/docfile");
+		ok(-e "debian/$pkg/usr/share/doc/$pkg/copyright");
+	}
+	remove_tree(qw(debian/foo debian/bar debian/baz));
+};
+
+each_compat_subtest {
+	# docs are ignored, but symlinked doc dir is still there
+	ok(run_dh_tool($NEEDS_ROOT_NODOC_PROFILE, 'dh_installdocs', '-pfoo', '--link-doc=bar',  $doc));
+	ok(-l "debian/foo/usr/share/doc/foo");
+	ok(readlink("debian/foo/usr/share/doc/foo") eq 'bar');
+	ok(! -e "debian/foo/usr/share/doc/bar/docfile");
+	remove_tree(qw(debian/foo debian/bar debian/baz));
+};
 
 # Local Variables:
 # indent-tabs-mode: t

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list