diff options
Diffstat (limited to 't')
26 files changed, 894 insertions, 133 deletions
diff --git a/t/Dh_Lib/00-use.t b/t/Dh_Lib/00-use.t new file mode 100755 index 00000000..dc8a966c --- /dev/null +++ b/t/Dh_Lib/00-use.t @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Cwd; +use Test::More tests => 2; + +use File::Temp qw(tempdir); +use File::Basename qw(dirname); +use lib dirname(dirname(__FILE__)); + +my $test_dir = tempdir(CLEANUP => 1); + +chdir($test_dir); + +# Packages that need to be able to (at least) load without requring +# d/control or d/compat. + +use_ok('Debian::Debhelper::Dh_Lib', '!dirname'); +use_ok('Debian::Debhelper::Buildsystem'); diff --git a/t/Dh_Lib/path.t b/t/Dh_Lib/path.t new file mode 100755 index 00000000..e5f90616 --- /dev/null +++ b/t/Dh_Lib/path.t @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; + +use Cwd qw(abs_path); +use File::Basename qw(dirname); +use File::Temp qw(tempdir); + +BEGIN { + my $dir = dirname(abs_path(__FILE__)); + unshift(@INC, dirname($dir)); + chdir($dir) or error("chdir($dir) failed: $!"); +}; + +use Test::DH; +use Debian::Debhelper::Dh_Lib qw(!dirname); + +plan(tests => 3); + +ok(!is_empty_dir(__FILE__), "is_empty_dir(file) is false"); +ok(!is_empty_dir(dirname(__FILE__)), "is_empty_dir(non-empty) is false"); + +my $tempdir = tempdir(CLEANUP => 1); +ok(is_empty_dir($tempdir), "is_empty_dir(new-temp-dir) is true"); diff --git a/t/Test/DH.pm b/t/Test/DH.pm index b9275cbe..20e6e9f6 100644 --- a/t/Test/DH.pm +++ b/t/Test/DH.pm @@ -26,6 +26,8 @@ $ENV{PATH} = "$ROOT_DIR:$ENV{PATH}" if $ENV{PATH} !~ m{\Q$ROOT_DIR\E/?:}; $ENV{PERL5LIB} = join(':', "${ROOT_DIR}/lib", (grep { defined } $ENV{PERL5LIB})) if not $ENV{PERL5LIB} or $ENV{PERL5LIB} !~ m{\Q$ROOT_DIR\E(?:/lib)?/?:}; $ENV{DH_AUTOSCRIPTDIR} = "$ROOT_DIR/autoscripts"; +# Nothing in the tests requires root. +$ENV{DEB_RULES_REQUIRES_ROOT} = 'no'; # Drop DEB_BUILD_PROFILES and DEB_BUILD_OPTIONS so they don't interfere delete($ENV{DEB_BUILD_PROFILES}); @@ -37,7 +39,7 @@ our @EXPORT = qw( each_compat_up_to_and_incl_subtest each_compat_subtest each_compat_from_and_above_subtest run_dh_tool uid_0_test_is_ok create_empty_file readlines - error + error find_script non_deprecated_compat_levels ); our ($TEST_DH_COMPAT, $ROOT_OK, $ROOT_CMD); @@ -198,4 +200,30 @@ sub readlines { return \@lines; } +# In *inst order (find_script will shuffle them around for *rm order) +my @SNIPPET_FILE_TEMPLATES = ( + 'debian/#PACKAGE#.#SCRIPT#.debhelper', + 'debian/.debhelper/generated/#PACKAGE#/#SCRIPT#.service', +); + +sub find_script { + my ($package, $script) = @_; + my @files; + for my $template (@SNIPPET_FILE_TEMPLATES) { + my $file = ($template =~ s/#PACKAGE#/$package/r); + $file =~ s/#SCRIPT#/$script/; + push(@files, $file) if -f $file; + } + if ($script eq 'postrm' or $script eq 'prerm') { + @files = reverse(@files); + } + return @files; +} + +sub non_deprecated_compat_levels() { + my $start = Debian::Debhelper::Dh_Lib::LOWEST_NON_DEPRECATED_COMPAT_LEVEL; + my $end = Debian::Debhelper::Dh_Lib::MAX_COMPAT_LEVEL; + return ($start..$end); +} + 1; diff --git a/t/buildsystems/03-bs-auto-buildable.t b/t/buildsystems/03-bs-auto-buildable.t index c1229dc9..df4405b2 100755 --- a/t/buildsystems/03-bs-auto-buildable.t +++ b/t/buildsystems/03-bs-auto-buildable.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 182; +use Test::More tests => 187; use File::Temp qw(tempdir); use File::Basename qw(dirname); @@ -90,7 +90,7 @@ sub run_auto_buildable_tests { rm_files("${sourcedir}/configure"); create_empty_file("${sourcedir}/CMakeLists.txt"); - test_check_auto_buildable($bs{cmake}, "CMakeLists.txt", { configure => 1, clean => 1 }); + test_check_auto_buildable($bs{'cmake+makefile'}, "CMakeLists.txt", { configure => 1, clean => 1 }); rm_files("${sourcedir}/CMakeLists.txt"); create_empty_file("${sourcedir}/Makefile.PL"); @@ -98,7 +98,7 @@ sub run_auto_buildable_tests { rm_files("${sourcedir}/Makefile.PL"); create_empty_file("${sourcedir}/meson.build"); - test_check_auto_buildable($bs{meson}, "meson.build", { configure => 1, clean => 1 }); + test_check_auto_buildable($bs{'meson+ninja'}, "meson.build", { configure => 1, clean => 1 }); # Leave meson.build create_empty_file("${builddir}/build.ninja"); @@ -106,7 +106,7 @@ sub run_auto_buildable_tests { # Leave ninja.build # Meson + ninja - test_check_auto_buildable($bs{meson}, "meson.build+build.ninja", { configure => 1, build => 1, clean => 1, install => 1, test => 1 }); + test_check_auto_buildable($bs{'meson+ninja'}, "meson.build+build.ninja", { configure => 1, build => 1, clean => 1, install => 1, test => 1 }); rm_files("${sourcedir}/meson.build", "${builddir}/build.ninja"); # With Makefile @@ -120,9 +120,9 @@ sub run_auto_buildable_tests { # ... +cmake create_empty_file("${sourcedir}/CMakeLists.txt"); - test_check_auto_buildable($bs{cmake}, "CMakeLists.txt+Makefile", 1); + test_check_auto_buildable($bs{'cmake+makefile'}, "CMakeLists.txt+Makefile", 1); create_empty_file("$builddir/CMakeCache.txt"); # strong evidence that cmake was run - test_check_auto_buildable($bs{cmake}, "CMakeCache.txt+Makefile", 2); + test_check_auto_buildable($bs{'cmake+makefile'}, "CMakeCache.txt+Makefile", 2); rm_files("${builddir}/Makefile", "${sourcedir}/CMakeLists.txt"); # Makefile.PL forces in-source @@ -189,7 +189,7 @@ sub run_autoselection_tests { # CMake create_empty_file("${sourcedir}/CMakeLists.txt"); test_autoselection("cmake without CMakeCache.txt", - { configure => "cmake", build => "makefile", + { configure => "cmake+makefile", build => "makefile", test => "makefile", install => "makefile", clean => "makefile" }, @@ -201,7 +201,7 @@ sub run_autoselection_tests { create_empty_file("${sourcedir}/CMakeLists.txt"); test_autoselection("cmake with CMakeCache.txt", - "cmake", + "cmake+makefile", %options, code_configure => sub { create_empty_file("$builddir/Makefile"); diff --git a/t/buildsystems/autoconf/configure b/t/buildsystems/autoconf/configure index 73715c8d..07e416ce 100755 --- a/t/buildsystems/autoconf/configure +++ b/t/buildsystems/autoconf/configure @@ -13,17 +13,24 @@ my @OPTIONS=qw( ^--infodir=\$\{prefix\}/share/info$ ^--sysconfdir=/etc$ ^--localstatedir=/var$ - ^--libexecdir=\$\{prefix\}/lib/.*$ ^--libdir=\$\{prefix\}/lib/.*$ ^--disable-silent-rules$ ^--disable-maintainer-mode$ ^--disable-dependency-tracking$ ); +# Not always passed (e.g. --libexecdir is skipped in compat 12) +my @OPTIONAL_ARGUMENTS = qw( + ^--libexecdir=\$\{prefix\}/lib/.*$ +); + # Verify if all command line arguments were passed my @options = map { { regex => qr/$_/, str => $_, found => 0 } } @OPTIONS; +push(@options, map { { regex => qr/$_/, + str => $_, + found => 1 } } @OPTIONAL_ARGUMENTS); my @extra_args; ARGV_LOOP: foreach my $arg (@ARGV) { foreach my $opt (@options) { diff --git a/t/buildsystems/buildsystem_tests.t b/t/buildsystems/buildsystem_tests.t index 4f1cc53d..fdda3029 100755 --- a/t/buildsystems/buildsystem_tests.t +++ b/t/buildsystems/buildsystem_tests.t @@ -252,6 +252,7 @@ $ENV{DEB_BUILD_OPTIONS} = "parallel=5"; $tmp = write_debian_rules(<<'EOF'); #!/usr/bin/make -f +export DEB_RULES_REQUIRES_ROOT:=no override_dh_auto_build: $(MAKE) %: diff --git a/t/debhelper-compat/debian/control b/t/debhelper-compat/debian/control new file mode 100644 index 00000000..1f18f4db --- /dev/null +++ b/t/debhelper-compat/debian/control @@ -0,0 +1,12 @@ +Source: foo +Section: misc +Priority: optional +Build-Depends: BUILD_DEPENDS +Maintainer: Test <testing@nowhere> +Rules-Requires-Root: no +Standards-Version: 3.9.8 + +Package: foo +Architecture: all +Description: package foo + Package foo diff --git a/t/debhelper-compat/syntax.t b/t/debhelper-compat/syntax.t new file mode 100755 index 00000000..9c0987d6 --- /dev/null +++ b/t/debhelper-compat/syntax.t @@ -0,0 +1,82 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Test::More; + +use File::Basename qw(dirname); +use File::Temp qw(tempdir); +use lib dirname(dirname(__FILE__)); +use Test::DH; + +use Debian::Debhelper::Dh_Lib qw(!dirname); + +my $TEST_DIR = dirname(__FILE__); + +sub test_build_depends { + my ($level, $build_depends) = @_; + my $dir = tempdir(CLEANUP => 1); + if (not mkdir("$dir/debian", 0777)) { + error("mkdir $dir/debian failed: $!"); + } + open my $in, '<', "$TEST_DIR/debian/control" or + error("open $TEST_DIR/debian/control failed: $!"); + open my $out, '>', "$dir/debian/control" or + error("open $dir/debian/control failed: $!"); + while (<$in>) { + s/BUILD_DEPENDS/$build_depends/; + print $out $_ or + error("write to $dir/debian/control failed: $!"); + } + close($out) or + error("close $dir/debian/control failed: $!"); + close($in); + + my $start_dir = Test::DH::cwd(); + chdir($dir) or error("chdir($dir): $!"); + + plan(tests => 5); + + local $ENV{DH_INTERNAL_TESTSUITE_SILENT_WARNINGS} = 1; + Debian::Debhelper::Dh_Lib::resetpackages; + Debian::Debhelper::Dh_Lib::resetcompat; + my @pkgs = getpackages; + ok(scalar @pkgs == 1); + ok($pkgs[0] eq 'foo'); + + ok(compat($level)); + ok(compat($level + 1)); + ok(!compat($level - 1)); + + chdir($start_dir) or + error("chdir($start_dir): $!"); +} + +my @levels = non_deprecated_compat_levels; +plan(tests => scalar @levels); + +for my $level (@levels) { + subtest "compat $level" => sub { + plan(tests => 7); + subtest 'only' => sub { + test_build_depends($level, "debhelper-compat (= $level)"); + }; + subtest 'first' => sub { + test_build_depends($level, "debhelper-compat (= $level), bar"); + }; + subtest 'second' => sub { + test_build_depends($level, "bar, debhelper-compat (= $level)"); + }; + subtest 'first-nl' => sub { + test_build_depends($level, "debhelper-compat (= $level),\n bar"); + }; + subtest 'second-nl' => sub { + test_build_depends($level, "bar,\n debhelper-compat (= $level)"); + }; + subtest 'nl-first' => sub { + test_build_depends($level, "\n debhelper-compat (= $level),\n bar"); + }; + subtest 'nl-second' => sub { + test_build_depends($level, "\n bar,\n debhelper-compat (= $level)"); + }; + }; +} diff --git a/t/dh-sequencer.t b/t/dh-sequencer.t new file mode 100755 index 00000000..dd5c264a --- /dev/null +++ b/t/dh-sequencer.t @@ -0,0 +1,173 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; + +use Debian::Debhelper::SequencerUtil; + +# Shorten variants of the sequences. +my @bd = (qw{ + dh_testdir + dh_auto_configure + dh_auto_build + dh_auto_test +}); +my @i = (qw{ + dh_testroot + dh_prep + dh_auto_install + + dh_install + dh_missing +}); +my @ba=qw{ + dh_strip + dh_makeshlibs + dh_shlibdeps +}; +my @b=qw{ + dh_installdeb + dh_gencontrol + dh_builddeb +}; + +my %sequences = ( + 'build-indep' => [@bd], + 'build-arch' => [@bd], + 'build' => [to_rules_target("build-arch"), to_rules_target("build-indep")], + + 'install-indep' => [to_rules_target("build-indep"), @i], + 'install-arch' => [to_rules_target("build-arch"), @i], + 'install' => [to_rules_target("build"), to_rules_target("install-arch"), to_rules_target("install-indep")], + + 'binary-indep' => [to_rules_target("install-indep"), @b], + 'binary-arch' => [to_rules_target("install-arch"), @ba, @b], + 'binary' => [to_rules_target("install"), to_rules_target("binary-arch"), to_rules_target("binary-indep")], +); + +my %sequences_unpacked = ( + 'build-indep' => [@bd], + 'build-arch' => [@bd], + 'build' => [@bd], + + 'install-indep' => [@bd, @i], + 'install-arch' => [@bd, @i], + 'install' => [@bd, @i], + + 'binary-indep' => [@bd, @i, @b], + 'binary-arch' => [@bd, @i, @ba, @b], + 'binary' => [@bd, @i, @ba, @b], +); + +plan tests => 11 + 3 * scalar(keys(%sequences)); + +# We will horse around with %EXPLICIT_TARGETS in this test; it should +# definitely not attempt to read d/rules or the test will be break. +$Debian::Debhelper::SequencerUtil::RULES_PARSED = 1; + + +is_deeply( + [unpack_sequence(\%sequences, 'build')], + [[], $sequences_unpacked{'build'}], + 'Inlined build sequence matches build-indep/build-arch'); + +is_deeply( + [unpack_sequence(\%sequences, 'install')], + [[], $sequences_unpacked{'install'}], + 'Inlined install sequence matches build-indep/build-arch + install commands'); + +is_deeply( + [unpack_sequence(\%sequences, 'binary-arch')], + [[], $sequences_unpacked{'binary-arch'}], + 'Inlined binary-arch sequence has all the commands'); + +is_deeply( + [unpack_sequence(\%sequences, 'binary-indep')], + [[], $sequences_unpacked{'binary-indep'}], + 'Inlined binary-indep sequence has all the commands except @bd'); + +is_deeply( + [unpack_sequence(\%sequences, 'binary')], + [[], $sequences_unpacked{'binary'}], + 'Inlined binary sequence has all the commands'); + + +is_deeply( + [unpack_sequence(\%sequences, 'binary', 0, { 'build' => 1, 'build-arch' => 1, 'build-indep' => 1})], + [[], [@i, @ba, @b]], + 'Inlined binary sequence with build-* done has @i, @ba and @b'); + +{ + local $Debian::Debhelper::SequencerUtil::EXPLICIT_TARGETS{'build'} = 1; + + is_deeply( + [unpack_sequence(\%sequences, 'binary')], + [[to_rules_target('build')], [@i, @ba, @b]], + 'Inlined binary sequence has all the commands but build target is opaque'); + + is_deeply( + [unpack_sequence(\%sequences, 'binary', 0, { 'build' => 1, 'build-arch' => 1, 'build-indep' => 1})], + [[], [@i, @ba, @b]], + 'Inlined binary sequence has all the commands with build-* done and not build-target'); + + is_deeply( + [unpack_sequence(\%sequences, 'build')], + [[], $sequences_unpacked{'build'}], + 'build sequence is inlineable'); + + + # Compat <= 8 ignores explicit targets! + for my $seq_name (sort(keys(%sequences))) { + is_deeply( + [unpack_sequence(\%sequences, $seq_name, 1)], + [[], $sequences_unpacked{$seq_name}], + "Compat <= 8 ignores explicit build target in sequence ${seq_name}"); + } +} + +{ + local $Debian::Debhelper::SequencerUtil::EXPLICIT_TARGETS{'install-arch'} = 1; + + is_deeply( + [unpack_sequence(\%sequences, 'binary')], + # @bd_minimal, @bd and @i should be "-i"-only, @ba + @b should be both. + # Unfortunately, unpack_sequence cannot show that. + [[to_rules_target('install-arch')], [@bd, @i, @ba, @b]], + 'Inlined binary sequence has all the commands'); + + # Compat <= 8 ignores explicit targets! + for my $seq_name (sort(keys(%sequences))) { + is_deeply( + [unpack_sequence(\%sequences, $seq_name, 1)], + [[], $sequences_unpacked{$seq_name}], + "Compat <= 8 ignores explicit install-arch target in sequence ${seq_name}"); + } +} + +{ + local $Debian::Debhelper::SequencerUtil::EXPLICIT_TARGETS{'install-arch'} = 1; + local $Debian::Debhelper::SequencerUtil::EXPLICIT_TARGETS{'build'} = 1; + + my $actual = [unpack_sequence(\%sequences, 'binary')]; + # @i should be "-i"-only, @ba + @b should be both. + # Unfortunately, unpack_sequence cannot show that. + my $expected = [[to_rules_target('build'), to_rules_target('install-arch')], [@i, @ba, @b]]; + # Permit some fuzz on the order between build and install-arch + if ($actual->[0][0] eq to_rules_target('install-arch')) { + $expected->[0][0] = to_rules_target('install-arch'); + $expected->[0][1] = to_rules_target('build'); + } + is_deeply( + $actual, + $expected, + 'Inlined binary sequence has all the commands'); + + # Compat <= 8 ignores explicit targets! + for my $seq_name (sort(keys(%sequences))) { + is_deeply( + [unpack_sequence(\%sequences, $seq_name, 1)], + [[], $sequences_unpacked{$seq_name}], + "Compat <= 8 ignores explicit build + install-arch targets in sequence ${seq_name}"); + } +} diff --git a/t/dh_compress.t b/t/dh_compress.t index b2055f0c..1eb61567 100755 --- a/t/dh_compress.t +++ b/t/dh_compress.t @@ -13,7 +13,7 @@ use Debian::Debhelper::Dh_Lib qw(!dirname); my $PREFIX = 'debian/debhelper/usr/share/doc/debhelper'; -plan tests => 1; +plan tests => 2; each_compat_subtest { # we are testing compressing doc txt files @@ -82,27 +82,28 @@ each_compat_subtest { rm_test_dir(); }; +each_compat_from_and_above_subtest(12, sub { + make_path("${PREFIX}/examples"); + create_file_of_size("${PREFIX}/examples/foo.py", 5120); + ok(run_dh_tool('dh_compress')); + ok(-f "${PREFIX}/examples/foo.py", "${PREFIX}/examples/foo.py is not compressed"); + ok(! -f "${PREFIX}/examples/foo.py.gz", "${PREFIX}/examples/foo.py is not compressed"); +}); + +sub create_file_of_size { + my ($filename, $size) = @_; + open(my $fh, '>', $filename) or error("open($filename) failed: $!"); + print {$fh} 'X' x $size; + close($fh) or error("close($filename) failed: $!"); +} sub mk_test_dir { rm_test_dir(); - make_path('debian/debhelper/usr/share/doc/debhelper'); - - my $fh; - - # write 2k to foo.txt - open $fh, '>', 'debian/debhelper/usr/share/doc/debhelper/foo.txt' - or die "Could not write to debian/debhelper/usr/share/doc/debhelper/foo.txt: $!"; - print $fh 'X' x 2048; - close $fh - or die "Could not write to debian/debhelper/usr/share/doc/debhelper/bar.txt: $!"; + make_path($PREFIX); - # write 5k to bar.txt - open $fh, '>', 'debian/debhelper/usr/share/doc/debhelper/bar.txt' - or die "Could not write to debian/debhelper/usr/share/doc/debhelper/bar.txt: $!"; - print $fh 'X' x 5120; - close $fh - or die "Could not write to debian/debhelper/usr/share/doc/debhelper/bar.txt: $!"; + create_file_of_size("${PREFIX}/foo.txt", 2048); + create_file_of_size("${PREFIX}/bar.txt", 5120); } sub rm_test_dir { diff --git a/t/dh_installdocs/debian/control b/t/dh_installdocs/debian/control index 48d4de2f..7e9a2282 100644 --- a/t/dh_installdocs/debian/control +++ b/t/dh_installdocs/debian/control @@ -2,6 +2,7 @@ Source: foo Section: misc Priority: optional Maintainer: Test <testing@nowhere> +Rules-Requires-Root: no Standards-Version: 3.9.8 Package: foo diff --git a/t/dh_installdocs/dh_installdocs.t b/t/dh_installdocs/dh_installdocs.t index 86746cfc..64f12546 100755 --- a/t/dh_installdocs/dh_installdocs.t +++ b/t/dh_installdocs/dh_installdocs.t @@ -16,15 +16,10 @@ our @TEST_DH_EXTRA_TEMPLATE_FILES = (qw( debian/copyright )); -if (uid_0_test_is_ok()) { - plan(tests => 5); -} else { - plan skip_all => 'fakeroot required'; -} - -my $NEEDS_ROOT = { 'needs_root' => 1 }; -my $NEEDS_ROOT_NODOC_PROFILE = { - 'needs_root' => 1, +plan(tests => 5); + + +my $NODOC_PROFILE = { 'env' => { 'DEB_BUILD_PROFILES' => 'nodoc', }, @@ -33,14 +28,14 @@ my $NEEDS_ROOT_NODOC_PROFILE = { my $doc = "debian/docfile"; each_compat_subtest { - ok(run_dh_tool($NEEDS_ROOT, 'dh_installdocs', '-pbar', $doc)); + ok(run_dh_tool('dh_installdocs', '-pbar', $doc)); ok(-e "debian/bar/usr/share/doc/bar/docfile"); remove_tree(qw(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)); + ok(run_dh_tool('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'); @@ -49,7 +44,7 @@ each_compat_subtest { }; each_compat_subtest { - ok(run_dh_tool($NEEDS_ROOT, 'dh_installdocs', '-pfoo', '--link-doc=bar', $doc)); + ok(run_dh_tool('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'); @@ -61,7 +56,7 @@ each_compat_subtest { each_compat_subtest { # docs are ignored, but copyright file is still there - ok(run_dh_tool($NEEDS_ROOT_NODOC_PROFILE, 'dh_installdocs', $doc)); + ok(run_dh_tool($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"); @@ -71,7 +66,7 @@ each_compat_subtest { 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(run_dh_tool($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"); diff --git a/t/dh_installinit/dh_installinit.t b/t/dh_installinit/dh_installinit.t index 20860f19..b20caa58 100755 --- a/t/dh_installinit/dh_installinit.t +++ b/t/dh_installinit/dh_installinit.t @@ -14,17 +14,13 @@ our @TEST_DH_EXTRA_TEMPLATE_FILES = (qw( debian/foo.service )); -if (uid_0_test_is_ok()) { - plan(tests => 2); -} else { - plan skip_all => 'fakeroot required'; -} +plan(tests => 2); each_compat_up_to_and_incl_subtest(10, sub { make_path(qw(debian/foo debian/bar debian/baz)); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installinit')); + ok(run_dh_tool('dh_installinit')); ok(-e "debian/foo/lib/systemd/system/foo.service"); - ok(-e "debian/foo.postinst.debhelper"); + ok(find_script('foo', 'postinst')); ok(run_dh_tool('dh_clean')); }); @@ -32,15 +28,15 @@ each_compat_up_to_and_incl_subtest(10, sub { each_compat_from_and_above_subtest(11, sub { make_path(qw(debian/foo debian/bar debian/baz)); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installinit')); + ok(run_dh_tool('dh_installinit')); ok(! -e "debian/foo/lib/systemd/system/foo.service"); - ok(! -e "debian/foo.postinst.debhelper"); + ok(!find_script('foo', 'postinst')); ok(run_dh_tool('dh_clean')); make_path(qw(debian/foo/lib/systemd/system/ debian/bar debian/baz)); install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installinit')); - ok(! -e "debian/foo.postinst.debhelper"); + ok(run_dh_tool('dh_installinit')); + ok(!find_script('foo', 'postinst')); ok(run_dh_tool('dh_clean')); }); diff --git a/t/dh_installsystemd/debian/foo.init b/t/dh_installsystemd/debian/foo.init new file mode 100644 index 00000000..2b77921a --- /dev/null +++ b/t/dh_installsystemd/debian/foo.init @@ -0,0 +1,4 @@ +#!/bin/sh + +some script + diff --git a/t/dh_installsystemd/dh_installsystemd.t b/t/dh_installsystemd/dh_installsystemd.t index 70133b97..7029c615 100755 --- a/t/dh_installsystemd/dh_installsystemd.t +++ b/t/dh_installsystemd/dh_installsystemd.t @@ -8,17 +8,17 @@ use Test::DH; use File::Path qw(remove_tree make_path); use Debian::Debhelper::Dh_Lib qw(!dirname); -our @TEST_DH_EXTRA_TEMPLATE_FILES = (qw( - debian/changelog - debian/control - debian/foo.service - debian/foo2.service -)); +plan(tests => 2); -if (uid_0_test_is_ok()) { - plan(tests => 2); -} else { - plan skip_all => 'fakeroot required'; +sub write_file { + my ($path, $content) = @_; + + my $dir = dirname($path); + install_dir($dir); + + open(my $fd, '>>', $path) or error("open($path) failed: $!"); + print {$fd} $content . '\n'; + close($fd) or error("close($path) failed: $!"); } sub unit_is_enabled { @@ -26,31 +26,84 @@ sub unit_is_enabled { my @output; my $matches; $num_masks = $num_masks // $num_enables; - @output=`cat debian/$package.postinst.debhelper`; - $matches = grep { m{^if deb-systemd-helper .* was-enabled .*'\Q$unit\E\.service'} } @output; + my @postinst_snippets = find_script($package, 'postinst'); + @output=`cat @postinst_snippets` if @postinst_snippets; + # Match exactly one tab; the "dont-enable" script has an "enable" + # line for re-enabling the service if the admin had it enabled. + # But we do not want to include that in our count. + $matches = grep { m{^\tif deb-systemd-helper .* was-enabled .*'\Q$unit\E\.service'} } @output; ok($matches == $num_enables) or diag("$unit appears to have been enabled $matches times (expected $num_enables)"); - @output=`cat debian/$package.postrm.debhelper`; + my @postrm_snippets = find_script($package, 'postrm'); + @output=`cat @postrm_snippets` if @postrm_snippets; $matches = grep { m{deb-systemd-helper mask.*'\Q$unit\E\.service'} } @output; ok($matches == $num_masks) or diag("$unit appears to have been masked $matches times (expected $num_masks)"); } + sub unit_is_started { my ($package, $unit, $num_starts, $num_stops) = @_; my @output; my $matches; $num_stops = $num_stops // $num_starts; - @output=`cat debian/$package.postinst.debhelper`; + my @postinst_snippets = find_script($package, 'postinst'); + @output=`cat @postinst_snippets` if @postinst_snippets; $matches = grep { m{deb-systemd-invoke \$_dh_action .*'\Q$unit\E.service'} } @output; ok($matches == $num_starts) or diag("$unit appears to have been started $matches times (expected $num_starts)"); - @output=`cat debian/$package.prerm.debhelper`; + my @prerm_snippets = find_script($package, 'prerm'); + @output=`cat @prerm_snippets` if @prerm_snippets; $matches = grep { m{deb-systemd-invoke stop .*'\Q$unit\E.service'} } @output; ok($matches == $num_stops) or diag("$unit appears to have been stopped $matches times (expected $num_stops)"); } -# Units are installed and enabled -each_compat_from_and_above_subtest(11, sub { - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd')); - ok(-e "debian/foo/lib/systemd/system/foo.service"); - ok(-e "debian/foo.postinst.debhelper"); + +# +# Test a simple source package defining a single binary package +# +our $TEST_DH_FIXTURE_DIR = 'simple'; +our @TEST_DH_EXTRA_TEMPLATE_FILES = (qw( + debian/changelog + debian/control + debian/foo.service +)); + +each_compat_subtest { + ok(run_dh_tool('dh_installsystemd')); + ok(-e 'debian/foo/lib/systemd/system/foo.service'); + ok(find_script('foo', 'postinst')); + unit_is_enabled('foo', 'foo', 1); + unit_is_started('foo', 'foo', 1); + ok(run_dh_tool('dh_clean')); + + ok(run_dh_tool('dh_installsystemd', '--no-start')); + ok(-e 'debian/foo/lib/systemd/system/foo.service'); + ok(find_script('foo', 'postinst')); + unit_is_enabled('foo', 'foo', 1); + unit_is_started('foo', 'foo', 0, 1); + ok(run_dh_tool('dh_clean')); + + ok(run_dh_tool('dh_installsystemd', '--no-start', 'foo.service')); + ok(-e 'debian/foo/lib/systemd/system/foo.service'); + ok(find_script('foo', 'postinst')); + unit_is_enabled('foo', 'foo', 1); + unit_is_started('foo', 'foo', 0, 1); + ok(run_dh_tool('dh_clean')); +}; + + +# +# Test a more complex source package defining three binary packages +# +$TEST_DH_FIXTURE_DIR = '.'; +@TEST_DH_EXTRA_TEMPLATE_FILES = (qw( + debian/changelog + debian/control + debian/foo.service + debian/foo2.service +)); + +each_compat_subtest { + ok(run_dh_tool( 'dh_installsystemd')); + ok(-e 'debian/foo/lib/systemd/system/foo.service'); + ok(find_script('foo', 'postinst')); unit_is_enabled('foo', 'foo', 1); unit_is_started('foo', 'foo', 1); unit_is_enabled('foo', 'foo2', 0); @@ -59,9 +112,9 @@ each_compat_from_and_above_subtest(11, sub { make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd')); - ok(-e "debian/foo/lib/systemd/system/foo.service"); - ok(-e "debian/foo.postinst.debhelper"); + ok(run_dh_tool('dh_installsystemd')); + ok(-e 'debian/foo/lib/systemd/system/foo.service'); + ok(find_script('foo', 'postinst')); unit_is_enabled('foo', 'foo', 1); unit_is_started('foo', 'foo', 1); unit_is_enabled('foo', 'foo2', 1); @@ -70,9 +123,9 @@ each_compat_from_and_above_subtest(11, sub { make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--no-start')); - ok(-e "debian/foo/lib/systemd/system/foo.service"); - ok(-e "debian/foo.postinst.debhelper"); + ok(run_dh_tool('dh_installsystemd', '--no-start')); + ok(-e 'debian/foo/lib/systemd/system/foo.service'); + ok(find_script('foo', 'postinst')); unit_is_enabled('foo', 'foo', 1); unit_is_started('foo', 'foo', 0, 1); # present units are stopped on remove even if no start unit_is_enabled('foo', 'foo2', 1); @@ -81,10 +134,10 @@ each_compat_from_and_above_subtest(11, sub { make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--no-start', 'debian/foo.service')); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '-p', 'foo', 'foo2.service')); - ok(-e "debian/foo/lib/systemd/system/foo.service"); - ok(-e "debian/foo.postinst.debhelper"); + ok(run_dh_tool('dh_installsystemd', '-p', 'foo', '--no-start', 'foo.service')); + ok(run_dh_tool('dh_installsystemd', '-p', 'foo', 'foo2.service')); + ok(-e 'debian/foo/lib/systemd/system/foo.service'); + ok(find_script('foo', 'postinst')); unit_is_enabled('foo', 'foo', 1); unit_is_started('foo', 'foo', 0, 1); unit_is_enabled('foo', 'foo2', 1); @@ -93,10 +146,10 @@ each_compat_from_and_above_subtest(11, sub { make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--no-enable', 'debian/foo.service')); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '-p', 'foo', 'foo2.service')); - ok(-e "debian/foo/lib/systemd/system/foo.service"); - ok(-e "debian/foo.postinst.debhelper"); + ok(run_dh_tool('dh_installsystemd', '-p', 'foo', '--no-enable', 'foo.service')); + ok(run_dh_tool('dh_installsystemd', '-p', 'foo', 'foo2.service')); + ok(-e 'debian/foo/lib/systemd/system/foo.service'); + ok(find_script('foo', 'postinst')); unit_is_enabled('foo', 'foo', 0, 1); # Disabled units are still masked on removal unit_is_started('foo', 'foo', 1, 1); unit_is_enabled('foo', 'foo2', 1); @@ -104,15 +157,17 @@ each_compat_from_and_above_subtest(11, sub { ok(run_dh_tool('dh_clean')); make_path('debian/foo/lib/systemd/system/'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--no-restart-after-upgrade')); - my $matches = grep { m{deb-systemd-invoke start .*foo.service} } `cat debian/foo.postinst.debhelper`; + ok(run_dh_tool('dh_installsystemd', '--no-restart-after-upgrade')); + my @foo_postinst = find_script('foo', 'postinst'); + ok(@foo_postinst); + my $matches = @foo_postinst ? grep { m{deb-systemd-invoke start .*foo.service} } `cat @foo_postinst` : -1; ok($matches == 1); ok(run_dh_tool('dh_clean')); # Quoting #764730 make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo\x2dfuse.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd')); + ok(run_dh_tool('dh_installsystemd')); unit_is_enabled('foo', 'foo\x2dfuse', 1); unit_is_started('foo', 'foo\x2dfuse', 1); ok(run_dh_tool('dh_clean')); @@ -120,30 +175,40 @@ each_compat_from_and_above_subtest(11, sub { # --name flag #870768 make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--name=foo')); + ok(run_dh_tool('dh_installsystemd', '--name=foo')); unit_is_enabled('foo', 'foo', 1); unit_is_started('foo', 'foo', 1); unit_is_enabled('foo', 'foo2', 0); unit_is_started('foo', 'foo2', 0); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd', '--name=foo2')); + ok(run_dh_tool('dh_installsystemd', '--name=foo2')); unit_is_enabled('foo', 'foo', 1); unit_is_started('foo', 'foo', 1); unit_is_enabled('foo', 'foo2', 1); unit_is_started('foo', 'foo2', 1); ok(run_dh_tool('dh_clean')); -}); - -each_compat_up_to_and_incl_subtest(10, sub { - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd')); - ok(! -e "debian/foo/lib/systemd/system/foo.service"); - ok(! -e "debian/foo.postinst.debhelper"); + make_path('debian/foo/lib/systemd/system/'); + install_file('debian/foo.service', 'debian/foo/lib/systemd/system/target.service'); + make_symlink_raw_target('target.service', 'debian/foo/lib/systemd/system/source.service'); + ok(run_dh_tool('dh_installsystemd')); + unit_is_enabled('foo', 'foo', 1); + # Alias= realized by symlinks are not enabled in maintaner scripts + unit_is_enabled('foo', 'source', 0); + unit_is_enabled('foo', 'target', 1); ok(run_dh_tool('dh_clean')); - make_path(qw(debian/foo/lib/systemd/system/)); - install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd')); - ok(! -e "debian/foo.postinst.debhelper"); + make_path('debian/foo/lib/systemd/system/'); + make_path('debian/foo/etc/init.d/'); + install_file('debian/foo.service', 'debian/foo/lib/systemd/system/target.service'); + make_symlink_raw_target('target.service', 'debian/foo/lib/systemd/system/source.service'); + write_file('debian/foo/etc/init.d/source', '# something'); + ok(run_dh_tool('dh_installsystemd')); + unit_is_enabled('foo', 'foo', 1); + # Alias= realized by symlinks are not enabled in maintaner scripts + unit_is_enabled('foo', 'source', 0); + unit_is_enabled('foo', 'target', 1); + # The presence of a sysvinit script for the alias unit inhibits start of both + unit_is_started('foo', 'source', 0); + unit_is_started('foo', 'target', 0); ok(run_dh_tool('dh_clean')); -}); - +}; diff --git a/t/dh_installsystemd/dh_installsystemd_tmpfiles.t b/t/dh_installsystemd/dh_installsystemd_tmpfiles.t new file mode 100755 index 00000000..a2739812 --- /dev/null +++ b/t/dh_installsystemd/dh_installsystemd_tmpfiles.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl +use strict; +use Test::More; + +use File::Basename qw(dirname); +use lib dirname(dirname(__FILE__)); +use Test::DH; +use File::Path qw(remove_tree make_path); +use Debian::Debhelper::Dh_Lib qw(!dirname); + +our @TEST_DH_EXTRA_TEMPLATE_FILES = (qw( + debian/changelog + debian/control + debian/foo.service + debian/foo.init +)); + +plan(tests => 1); + +# Units are installed and enabled +each_compat_from_and_above_subtest(11, sub { + make_path('debian/foo/usr/lib/tmpfiles.d'); + create_empty_file('debian/foo/usr/lib/tmpfiles.d/foo.conf'); + ok(run_dh_tool('dh_installinit')); + ok(run_dh_tool('dh_installsystemd')); + ok(-e "debian/foo/etc/init.d/foo"); + ok(-e "debian/foo/lib/systemd/system/foo.service"); + my @postinst = find_script('foo', 'postinst'); + # We should have too snippets (one for the tmpfiles and one for the services). + is(scalar(@postinst), 2); + if (scalar(@postinst) == 2) { + open(my $fd, '<', $postinst[0]) or error("open($postinst[0]) failed: $!"); + my $early_snippet = readlines($fd); + close($fd); + open($fd, '<', $postinst[1]) or error("open($postinst[1]) failed: $!"); + my $late_snippet = readlines($fd); + close($fd); + ok(! grep { m/(?:invoke|update)-rc.d|deb-systemd-invoke/ } @{$early_snippet}); + ok(grep { m/(?:invoke|update)-rc.d|deb-systemd-invoke/ } @{$late_snippet}); + ok(grep { m/systemd-tmpfiles/ } @{$early_snippet}); + ok(! grep { m/systemd-tmpfiles/ } @{$late_snippet}); + } + ok(run_dh_tool('dh_clean')); + +}); diff --git a/t/dh_installsystemd/dh_systemd.t b/t/dh_installsystemd/dh_systemd.t index dee70965..d8ed5288 100755 --- a/t/dh_installsystemd/dh_systemd.t +++ b/t/dh_installsystemd/dh_systemd.t @@ -15,11 +15,7 @@ our @TEST_DH_EXTRA_TEMPLATE_FILES = (qw( debian/foo2.service )); -if (uid_0_test_is_ok()) { - plan(tests => 1); -} else { - plan skip_all => 'fakeroot required'; -} +plan(tests => 1); sub unit_is_enabled { my ($package, $unit, $num_enables, $num_masks) = @_; @@ -27,7 +23,10 @@ sub unit_is_enabled { my $matches; $num_masks = $num_masks // $num_enables; @output=`cat debian/$package.postinst.debhelper`; - $matches = grep { m{^if deb-systemd-helper .* was-enabled .*'\Q$unit\E\.service'} } @output; + # Match exactly one tab; the "dont-enable" script has an "enable" + # line for re-enabling the service if the admin had it enabled. + # But we do not want to include that in our count. + $matches = grep { m{^\tif deb-systemd-helper .* was-enabled .*'\Q$unit\E\.service'} } @output; ok($matches == $num_enables) or diag("$unit appears to have been enabled $matches times (expected $num_enables)"); @output=`cat debian/$package.postrm.debhelper`; $matches = grep { m{deb-systemd-helper mask.*'\Q$unit\E\.service'} } @output; @@ -48,8 +47,8 @@ sub unit_is_started { # Units are installed and enabled each_compat_up_to_and_incl_subtest(10, sub { - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable')); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start')); + ok(run_dh_tool('dh_systemd_enable')); + ok(run_dh_tool('dh_systemd_start')); ok(-e "debian/foo/lib/systemd/system/foo.service"); ok(-e "debian/foo.postinst.debhelper"); unit_is_enabled('foo', 'foo', 1); @@ -60,8 +59,8 @@ each_compat_up_to_and_incl_subtest(10, sub { make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable')); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start')); + ok(run_dh_tool('dh_systemd_enable')); + ok(run_dh_tool('dh_systemd_start')); ok(-e "debian/foo/lib/systemd/system/foo.service"); ok(-e "debian/foo.postinst.debhelper"); unit_is_enabled('foo', 'foo', 1); @@ -72,8 +71,8 @@ each_compat_up_to_and_incl_subtest(10, sub { make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable')); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start', '--no-start')); + ok(run_dh_tool('dh_systemd_enable')); + ok(run_dh_tool('dh_systemd_start', '--no-start')); ok(-e "debian/foo/lib/systemd/system/foo.service"); ok(-e "debian/foo.postinst.debhelper"); unit_is_enabled('foo', 'foo', 1); @@ -84,9 +83,9 @@ each_compat_up_to_and_incl_subtest(10, sub { make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable')); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start', '--no-start', 'debian/foo.service')); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start', '-p', 'foo', 'foo2.service')); + ok(run_dh_tool('dh_systemd_enable')); + ok(run_dh_tool('dh_systemd_start', '--no-start', 'debian/foo.service')); + ok(run_dh_tool('dh_systemd_start', '-p', 'foo', 'foo2.service')); ok(-e "debian/foo/lib/systemd/system/foo.service"); ok(-e "debian/foo.postinst.debhelper"); unit_is_enabled('foo', 'foo', 1); @@ -97,9 +96,9 @@ each_compat_up_to_and_incl_subtest(10, sub { make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable', '--no-enable', 'debian/foo.service')); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable', '-p', 'foo', 'foo2.service')); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start')); + ok(run_dh_tool('dh_systemd_enable', '--no-enable', 'debian/foo.service')); + ok(run_dh_tool('dh_systemd_enable', '-p', 'foo', 'foo2.service')); + ok(run_dh_tool('dh_systemd_start')); ok(-e "debian/foo/lib/systemd/system/foo.service"); ok(-e "debian/foo.postinst.debhelper"); unit_is_enabled('foo', 'foo', 0, 1); # Disabled units are still masked on removal @@ -110,7 +109,7 @@ each_compat_up_to_and_incl_subtest(10, sub { make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start', '--no-restart-after-upgrade')); + ok(run_dh_tool('dh_systemd_start', '--no-restart-after-upgrade')); my $matches = grep { m{deb-systemd-invoke start .*foo.service} } `cat debian/foo.postinst.debhelper`; ok($matches == 1); ok(run_dh_tool('dh_clean')); @@ -118,8 +117,8 @@ each_compat_up_to_and_incl_subtest(10, sub { # Quoting #764730 make_path('debian/foo/lib/systemd/system/'); install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo\x2dfuse.service'); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable')); - ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start')); + ok(run_dh_tool('dh_systemd_enable')); + ok(run_dh_tool('dh_systemd_start')); unit_is_enabled('foo', 'foo\x2dfuse', 1); unit_is_started('foo', 'foo\x2dfuse', 1); ok(run_dh_tool('dh_clean')); diff --git a/t/dh_installsystemd/simple/debian/changelog b/t/dh_installsystemd/simple/debian/changelog new file mode 100644 index 00000000..5b1a8fee --- /dev/null +++ b/t/dh_installsystemd/simple/debian/changelog @@ -0,0 +1,5 @@ +foo (1.0-1) unstable; urgency=low + + * Initial release. (Closes: #XXXXXX) + + -- Test <test@example.org> Mon, 11 Jul 2016 18:10:59 +0200 diff --git a/t/dh_installsystemd/simple/debian/control b/t/dh_installsystemd/simple/debian/control new file mode 100644 index 00000000..4f4238eb --- /dev/null +++ b/t/dh_installsystemd/simple/debian/control @@ -0,0 +1,10 @@ +Source: foo +Section: misc +Priority: optional +Maintainer: Test <testing@nowhere> +Standards-Version: 3.9.8 + +Package: foo +Architecture: all +Description: package foo + Package foo diff --git a/t/dh_installsystemd/simple/debian/foo.service b/t/dh_installsystemd/simple/debian/foo.service new file mode 100644 index 00000000..2b48a781 --- /dev/null +++ b/t/dh_installsystemd/simple/debian/foo.service @@ -0,0 +1,8 @@ +[Unit] +Description=A unit + +[Service] +ExecStart=/bin/true + +[Install] +WantedBy=multi-user.target diff --git a/t/dh_link/03-894229.t b/t/dh_link/03-894229.t new file mode 100755 index 00000000..238e6c41 --- /dev/null +++ b/t/dh_link/03-894229.t @@ -0,0 +1,55 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; +plan(tests => 1); + +use File::Path qw(remove_tree); +use File::Basename qw(dirname); +use lib dirname(dirname(__FILE__)); +use Debian::Debhelper::Dh_Lib qw(!dirname); +use Test::DH; + + +sub test_tricky { + my ($link_name, $denoted_dest, $expected_link_target) = @_; + my $tmpdir = 'debian/debhelper'; + my $link_path = "${tmpdir}/${link_name}"; + + make_symlink($link_name, $denoted_dest, $tmpdir); + if (ok(-l $link_path, 'Link made in correct directory')) { + my $target = readlink($link_path); + is($target, $expected_link_target, 'Link points correctly') + or diag("Expected ${expected_link_target}, actual ${target}"); + rm_files($link_path); + } + return; +} + +sub test_invalid { + my ($link_name, $denoted_dest) = @_; + eval { + make_symlink($link_name, $denoted_dest); + }; + like($@, qr{^(?:\S*:\s*)?Invalid destination/link name}); +} + +each_compat_subtest { + + remove_tree('debian/debhelper/a/b/c'); + + install_dir('debian/debhelper/a/b/c'); + + test_invalid('../../wow', 'a'); + # This is a can be made valid but at the moment we do not support + # it. + test_invalid('a/b/../link21', 'a'); + + + test_tricky('//a/b/link03', 'a/b/c', 'c'); + test_tricky('./a/link18', 'a', '.'); + test_tricky('a/./b/link19', 'a/b', '.'); +}; + diff --git a/t/dh_missing/04-not-installed-glob.t b/t/dh_missing/04-not-installed-glob.t new file mode 100755 index 00000000..b46eca3a --- /dev/null +++ b/t/dh_missing/04-not-installed-glob.t @@ -0,0 +1,37 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Test::More; + +use File::Basename qw(dirname); +use lib dirname(dirname(__FILE__)); +use Test::DH; +use Debian::Debhelper::Dh_Lib qw(!dirname); + +our $TEST_DH_FIXTURE_DIR = 'template'; +our @TEST_DH_EXTRA_TEMPLATE_FILES = (qw( + debian/changelog + debian/control + debian/foo.install + file-for-foo + Makefile +)); + +plan(tests => 1); + +each_compat_subtest { + rm_files('debian/not-installed'); + open(my $fd, '>', 'debian/not-installed') or error("open(d/not-installed): $!"); + # Non-glob match + print {$fd} "usr/bin/file-for-foo\n"; + # Glob match (note that it must not match the above) + print {$fd} "usr/bin/file-for-foo-*\n"; + # Non-matches (silently ignored) + print {$fd} "usr/bin/does-not-exist\n"; + print {$fd} "usr/bin/does-not-exist-*\n"; + close($fd) or error("close(d/not-installed: $!"); + ok(run_dh_tool('dh_clean')); + is(system('make', 'installmore'), 0); + ok(run_dh_tool('dh_missing', '--fail-missing')); +}; + diff --git a/t/dh_usrlocal/01-basic.t b/t/dh_usrlocal/01-basic.t new file mode 100755 index 00000000..2cd3f842 --- /dev/null +++ b/t/dh_usrlocal/01-basic.t @@ -0,0 +1,157 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; +plan(tests => 1); + +use File::Path qw(remove_tree); +use File::Basename qw(dirname); +use lib dirname(dirname(__FILE__)); +use Test::DH; +use Debian::Debhelper::Dh_Lib qw(!dirname); + +sub extract_generated_lines { + my ($file) = @_; + my (@lines, $marker); + return if not -f $file; + open(my $fd, '<', $file) or error("open($file) failed: $!"); + while (my $line = <$fd>) { + chomp($line); + if (defined($marker)) { + last if $line eq $marker; + push(@lines, $line); + next; + } + if ($line =~ m{\s*<<\s*(\S+)\s*$}) { + $marker = $1; + } + } + close($fd); + return @lines; +} + + +sub perform_test { + my ($install_dirs, $expected_dirs_postinst, $expected_dirs_prerm) = @_; + my (@postinst, @prerm); + my @scripts = qw( + debian/debhelper.postinst.debhelper + debian/debhelper.prerm.debhelper + ); + + rm_files(@scripts); + remove_tree('debian/debhelper'); + install_dir(map { "debian/debhelper/$_" } @{$install_dirs}); + + ok(run_dh_tool('dh_usrlocal')); + + @postinst = extract_generated_lines("debian/debhelper.postinst.debhelper"); + @prerm = extract_generated_lines("debian/debhelper.prerm.debhelper"); + + is_deeply(\@postinst, + [map { "$_ default" } @{$expected_dirs_postinst}], + "Correct postinst" + ) or do { diag("postinst: $_") for @postinst; }; + is_deeply(\@prerm, + $expected_dirs_prerm, + "Correct prerm" + ) or do { diag("prerm: $_") for @prerm; }; +} + +each_compat_subtest { + + perform_test( + ['/usr/local/bar', '/usr/local/foo'], + ['/usr/local/bar', '/usr/local/foo'], + [] + ); + + perform_test( + [ + '/usr/local/foo/bar', + '/usr/local/foo/baz', + ], + [ + '/usr/local/foo', + '/usr/local/foo/bar', + '/usr/local/foo/baz', + ], + [ + '/usr/local/foo/bar', + '/usr/local/foo/baz', + ] + ); + + perform_test( + [qw( + /usr/local/a/a/a + /usr/local/a/a/b + /usr/local/a/b/a + /usr/local/a/b/b + /usr/local/b/a/a + /usr/local/b/a/b + /usr/local/b/b/a + /usr/local/b/b/b + )], + [qw( + /usr/local/a + /usr/local/a/a + /usr/local/a/a/a + /usr/local/a/a/b + /usr/local/a/b + /usr/local/a/b/a + /usr/local/a/b/b + /usr/local/b + /usr/local/b/a + /usr/local/b/a/a + /usr/local/b/a/b + /usr/local/b/b + /usr/local/b/b/a + /usr/local/b/b/b + )], + [qw( + /usr/local/a/a/a + /usr/local/a/a/b + /usr/local/a/a + /usr/local/a/b/a + /usr/local/a/b/b + /usr/local/a/b + /usr/local/b/a/a + /usr/local/b/a/b + /usr/local/b/a + /usr/local/b/b/a + /usr/local/b/b/b + /usr/local/b/b + )] + ); + + perform_test( + [ + '/usr/local/foo/dir/somewhere', + '/usr/local/bar/another-dir/elsewhere', + '/usr/local/baz/foo+bar/thing', + ], + [ + '/usr/local/bar', + '/usr/local/bar/another-dir', + '/usr/local/bar/another-dir/elsewhere', + '/usr/local/baz', + '/usr/local/baz/foo+bar', + '/usr/local/baz/foo+bar/thing', + '/usr/local/foo', + '/usr/local/foo/dir', + '/usr/local/foo/dir/somewhere', + ], + [ + '/usr/local/bar/another-dir/elsewhere', + '/usr/local/bar/another-dir', + '/usr/local/baz/foo+bar/thing', + '/usr/local/baz/foo+bar', + '/usr/local/foo/dir/somewhere', + '/usr/local/foo/dir', + ] + ); +}; + diff --git a/t/maintscript.t b/t/maintscript.t index a69c99c7..cec4fab8 100755 --- a/t/maintscript.t +++ b/t/maintscript.t @@ -9,11 +9,7 @@ use lib dirname(__FILE__); use Test::DH; use Debian::Debhelper::Dh_Lib qw(!dirname); -if (uid_0_test_is_ok()) { - plan(tests => 1); -} else { - plan skip_all => 'fakeroot required'; -} +plan(tests => 2); each_compat_up_to_and_incl_subtest(10, sub { my @scripts = qw{postinst preinst prerm postrm}; @@ -29,7 +25,7 @@ mv_conffile /etc/2 /etc/3 1.0-1 EOF close($fd) or die("close($file): $!\n"); - run_dh_tool( { 'needs_root' => 1 }, 'dh_installdeb'); + run_dh_tool('dh_installdeb'); for my $script (@scripts) { my @output=`cat debian/debhelper.$script.debhelper`; @@ -38,3 +34,37 @@ EOF } }); +sub test_maintscript_syntax { + my ($contents) = @_; + my @scripts = map { ("debian/debhelper.${_}.debhelper", "debian/$_") } qw{postinst preinst prerm postrm}; + my $file = 'debian/maintscript'; + + + open(my $fd, ">", $file) or die("open($file): $!"); + print {$fd} <<EOF; +${contents} +EOF + close($fd) or die("close($file): $!\n"); + + my $res = run_dh_tool( { 'quiet' => 1 }, 'dh_installdeb'); + + remove_tree('debian/debhelper', 'debian/tmp', 'debian/.debhelper'); + rm_files(@scripts); + + return $res; +} + +# Negative tests +each_compat_from_and_above_subtest(12, sub { + ok(!test_maintscript_syntax('rm_conffile foo 1.0~'), "rm_conffile absolute path check"); + ok(!test_maintscript_syntax('rm_conffile /foo 1.0\~'), "rm_conffile version check"); + ok(!test_maintscript_syntax('rm_conffile /foo 1.0~ some_pkg'), "rm_conffile package name check"); + ok(!test_maintscript_syntax('rm_conffile /foo 1.0~ some-pkg --'), "rm_conffile separator check"); + + ok(!test_maintscript_syntax('mv_conffile foo /bar 1.0~'), "mv_conffile absolute (current) path check"); + ok(!test_maintscript_syntax('mv_conffile /foo bar 1.0~'), "mv_conffile absolute (current) path check"); + ok(!test_maintscript_syntax('mv_conffile /foo /bar 1.0\~'), "mv_conffile version check"); + ok(!test_maintscript_syntax('mv_conffile /foo /bar 1.0~ some_pkg'), "mv_conffile package name check"); + ok(!test_maintscript_syntax('mv_conffile /foo /bar 1.0~ some-pkg -- '), "mv_conffile separator check "); +}); + diff --git a/t/override_target.t b/t/override_target.t index bf7323b9..235f904c 100755 --- a/t/override_target.t +++ b/t/override_target.t @@ -1,5 +1,7 @@ #!/usr/bin/perl -use Test; +use strict; +use warnings; +use Test::More; plan(tests => 1); # This test is here to detect breakage in @@ -22,5 +24,7 @@ EOF close OUT; system("chmod +x t/tmp/debian/rules"); my @output=`cd t/tmp && debian/rules build 2>&1`; -ok(grep { m/override called/ } @output); +ok(grep { m/override called/ } @output) or do { + diag($_) for @output; +}; system("rm -rf t/tmp"); @@ -21,7 +21,7 @@ foreach my $file (@progs) { while (<$fd>) { $cutting=1 if /^=/; $cutting=0 if /^=cut/; - next if $cutting || /^(?:=|\s*(?:\#.*)?$)/; + next if $cutting || /^(?:=|\s*(?:\#.*|[}]\s*)?$)/; $lines++; $maxlength=length($_) if length($_) > $maxlength; } |