Source: debhelper
Version: 9.20160709
Severity: wishlist
Tags: patch

On 2016-07-09 11:54 +0000, Niels Thykier wrote:

> Sven Joachim:
>
>> It seems to me that dh_installdocs really needs a testsuite
>> for all the possible cases though.
>> 
>> Cheers,
>>        Sven
>> 
>
> Indeed, I have been missing that for several debhelper tools.  It would
> need some infrastructure in place and probably have to be optional to
> keep build-depends minimal.

Here is a patch which adds a few build-time tests for dh_installdocs.
It catches the problems observed in #830309, but does not do much more.
Still, at least it's a start.

Cheers,
       Sven

>From 096142e8db595389d7ec1ff4da26448d3453fa77 Mon Sep 17 00:00:00 2001
From: Sven Joachim <[email protected]>
Date: Mon, 11 Jul 2016 18:12:54 +0200
Subject: [PATCH] Add some tests for for dh_installdocs

This is a small test suite for dh_installdocs, motivated by the problems
found in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=830309.  It
catches both the bug introduced in commit 71007f72da682dd9d7f932d81ca
and the regression caused by commit 863ef397c939340e863be1e96c822934a.

The tests verify that the correct /usr/share/doc symlinks and
directories are set up with and without the --link-doc option, in both
compat level 9 and 11.

Since dh_installdocs runs chown(1), the tests are skipped if run by an
ordinary user and fakeroot is unavailable.
---
 Makefile                          |  2 +-
 t/dh_installdocs/debian/changelog |  5 +++
 t/dh_installdocs/debian/compat    |  1 +
 t/dh_installdocs/debian/control   | 20 ++++++++++
 t/dh_installdocs/debian/docfile   |  1 +
 t/dh_installdocs/dh_installdocs.t | 78 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 t/dh_installdocs/debian/changelog
 create mode 100644 t/dh_installdocs/debian/compat
 create mode 100644 t/dh_installdocs/debian/control
 create mode 100644 t/dh_installdocs/debian/docfile
 create mode 100755 t/dh_installdocs/dh_installdocs.t

diff --git a/Makefile b/Makefile
index 9c2e9f9..e27779b 100644
--- a/Makefile
+++ b/Makefile
@@ -101,6 +101,6 @@ install:
 	install -m 0644 Debian/Debhelper/Buildsystem/*.pm $(DESTDIR)$(PERLLIBDIR)/Buildsystem
 
 test: version
-	./run perl -MTest::Harness -e 'runtests grep { ! /CVS/ && ! /\.svn/ && -f && -x } @ARGV' t/* t/buildsystems/*
+	./run perl -MTest::Harness -e 'runtests grep { ! /CVS/ && ! /\.svn/ && -f && -x } @ARGV' t/* t/*/*
 	# clean up log etc
 	./run dh_clean
diff --git a/t/dh_installdocs/debian/changelog b/t/dh_installdocs/debian/changelog
new file mode 100644
index 0000000..5850f0e
--- /dev/null
+++ b/t/dh_installdocs/debian/changelog
@@ -0,0 +1,5 @@
+foo (1.0-1) unstable; urgency=low
+
+  * Initial release. (Closes: #XXXXXX)
+
+ -- Test <testing@nowhere>  Mon, 11 Jul 2016 18:10:59 +0200
diff --git a/t/dh_installdocs/debian/compat b/t/dh_installdocs/debian/compat
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/t/dh_installdocs/debian/compat
@@ -0,0 +1 @@
+9
diff --git a/t/dh_installdocs/debian/control b/t/dh_installdocs/debian/control
new file mode 100644
index 0000000..48d4de2
--- /dev/null
+++ b/t/dh_installdocs/debian/control
@@ -0,0 +1,20 @@
+Source: foo
+Section: misc
+Priority: optional
+Maintainer: Test <testing@nowhere>
+Standards-Version: 3.9.8
+
+Package: foo
+Architecture: all
+Description: package foo
+ Package foo
+
+Package: bar
+Architecture: all
+Description: package bar
+ Package bar
+
+Package: baz
+Architecture: all
+Description: package baz
+ Package baz
diff --git a/t/dh_installdocs/debian/docfile b/t/dh_installdocs/debian/docfile
new file mode 100644
index 0000000..2719eec
--- /dev/null
+++ b/t/dh_installdocs/debian/docfile
@@ -0,0 +1 @@
+This file must not be empty, or dh_installdocs won't install it.
diff --git a/t/dh_installdocs/dh_installdocs.t b/t/dh_installdocs/dh_installdocs.t
new file mode 100755
index 0000000..2c7b381
--- /dev/null
+++ b/t/dh_installdocs/dh_installdocs.t
@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+use strict;
+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;
+
+if ($< == 0) {
+	$rootcmd = '';
+}
+else {
+	system("fakeroot true 2>/dev/null");
+	$rootcmd = $? ? undef : 'fakeroot';
+}
+
+if (not defined($rootcmd)) {
+	plan skip_all => 'fakeroot required';
+}
+else {
+	plan(tests => 17);
+}
+
+system("rm -rf debian/foo debian/bar debian/baz");
+
+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");
+
+#regression in debhelper 9.20160709 (#830309)
+system("DH_COMPAT=11 $rootcmd $TOPDIR/dh_installdocs -pbar $doc");
+ok(-e "debian/bar/usr/share/doc/foo/docfile");
+system("rm -rf 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");
+
+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");
+
+system("DH_COMPAT=11 $rootcmd $TOPDIR/dh_installdocs -pbaz --link-doc=bar $doc");
+ok(-l "debian/baz/usr/share/doc/baz");
+ok(readlink("debian/baz/usr/share/doc/baz") eq 'bar');
+ok(-e "debian/baz/usr/share/doc/foo/docfile");
+system("rm -rf 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");
+
+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");
+
+system("$TOPDIR/dh_clean");
+
+# Local Variables:
+# indent-tabs-mode: t
+# tab-width: 4
+# cperl-indent-level: 4
+# End:
-- 
2.8.1

Reply via email to