diff options
Diffstat (limited to 't')
-rwxr-xr-x | t/buildsystems/autoconf/configure | 74 | ||||
-rwxr-xr-x | t/buildsystems/buildsystem_tests | 641 | ||||
-rw-r--r-- | t/buildsystems/debian/changelog | 5 | ||||
-rw-r--r-- | t/buildsystems/debian/compat | 1 | ||||
-rw-r--r-- | t/buildsystems/debian/control | 10 | ||||
-rw-r--r-- | t/buildsystems/parallel.mk | 21 | ||||
-rwxr-xr-x | t/dh-lib | 31 | ||||
-rwxr-xr-x | t/dh_install | 88 | ||||
-rwxr-xr-x | t/dh_link | 45 | ||||
-rw-r--r-- | t/maintscript | 19 | ||||
-rwxr-xr-x | t/override_target | 22 | ||||
-rwxr-xr-x | t/pod | 10 | ||||
-rwxr-xr-x | t/size | 29 | ||||
-rwxr-xr-x | t/syntax | 12 |
14 files changed, 1008 insertions, 0 deletions
diff --git a/t/buildsystems/autoconf/configure b/t/buildsystems/autoconf/configure new file mode 100755 index 00000000..adea14e6 --- /dev/null +++ b/t/buildsystems/autoconf/configure @@ -0,0 +1,74 @@ +#!/usr/bin/perl + +# Emulate autoconf behaviour and do some checks + +use strict; +use warnings; + +my @OPTIONS=qw( + ^--build=.*$ + ^--prefix=/usr$ + ^--includedir=\$\{prefix\}/include$ + ^--mandir=\$\{prefix\}/share/man$ + ^--infodir=\$\{prefix\}/share/info$ + ^--sysconfdir=/etc$ + ^--localstatedir=/var$ + ^--libexecdir=\$\{prefix\}/lib/.*$ + ^--disable-maintainer-mode$ + ^--disable-dependency-tracking$ +); + +# Verify if all command line arguments were passed +my @options = map { { regex => qr/$_/, + str => $_, + found => 0 } } @OPTIONS; +my @extra_args; +ARGV_LOOP: foreach my $arg (@ARGV) { + foreach my $opt (@options) { + if ($arg =~ $opt->{regex}) { + $opt->{found} = 1; + next ARGV_LOOP; + } + } + # Extra / unrecognized argument + push @extra_args, $arg; +} + +my @notfound = grep { ! $_->{found} and $_ } @options; +if (@notfound) { + print STDERR "Error: the following default options were NOT passed\n"; + print STDERR " ", $_->{str}, "\n" foreach (@notfound); + exit 1; +} + +# Create a simple Makefile +open(MAKEFILE, ">", "Makefile"); +print MAKEFILE <<EOF; +CONFIGURE := $0 +all: stamp_configure \$(CONFIGURE) + \@echo Package built > stamp_build + +# Tests if dh_auto_test executes 'check' target if 'test' does not exist +check: \$(CONFIGURE) stamp_build + \@echo Tested > stamp_test + +install: stamp_build + \@echo DESTDIR=\$(DESTDIR) > stamp_install + +# Tests whether dh_auto_clean executes distclean but does not touch +# this target +clean: + echo "This should not have been executed" >&2 && exit 1 + +distclean: + \@rm -f stamp_* Makefile + +.PHONY: all check install clean distclean +EOF +close MAKEFILE; + +open(STAMP, ">", "stamp_configure"); +print STAMP $_, "\n" foreach (@extra_args); +close STAMP; + +exit 0; diff --git a/t/buildsystems/buildsystem_tests b/t/buildsystems/buildsystem_tests new file mode 100755 index 00000000..98b3895e --- /dev/null +++ b/t/buildsystems/buildsystem_tests @@ -0,0 +1,641 @@ +#!/usr/bin/perl + +use Test::More tests => 297; + +use strict; +use warnings; +use IPC::Open2; +use Cwd (); +use File::Temp qw(tempfile tempdir); +use File::Basename (); + +# Let the tests to be run from anywhere but currect 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); + +use_ok( 'Debian::Debhelper::Dh_Lib' ); +use_ok( 'Debian::Debhelper::Buildsystem' ); +use_ok( 'Debian::Debhelper::Dh_Buildsystems' ); + +my $TOPDIR = "../.."; +my @STEPS = qw(configure build test install clean); +my $BS_CLASS = 'Debian::Debhelper::Buildsystem'; + +my ($bs, @bs, %bs); +my ($tmp, @tmp, %tmp); +my ($tmpdir, $builddir, $default_builddir); + +### Common subs #### +sub touch { + my $file=shift; + my $chmod=shift; + open FILE, ">", $file and close FILE or die "Unable to touch $file"; + chmod $chmod, $file if defined $chmod; +} + +sub cleandir { + my $dir=shift; + system ("find", $dir, "-type", "f", "-delete"); +} +sub readlines { + my $h=shift; + my @lines = <$h>; + close $h; + chop @lines; + return \@lines; +} + +sub process_stdout { + my ($cmdline, $stdin) = @_; + my ($reader, $writer); + + my $pid = open2($reader, $writer, $cmdline) or die "Unable to exec $cmdline"; + print $writer $stdin if $stdin; + close $writer; + waitpid($pid, 0); + $? = $? >> 8; # exit status + return readlines($reader); +} + +sub write_debian_rules { + my $contents=shift; + my $backup; + + if (-f "debian/rules") { + (undef, $backup) = tempfile(DIR => ".", OPEN => 0); + rename "debian/rules", $backup; + } + # Write debian/rules if requested + if ($contents) { + open(my $f, ">", "debian/rules"); + print $f $contents;; + close($f); + chmod 0755, "debian/rules"; + } + return $backup; +} + +### Test Buildsystem class API methods +is( $BS_CLASS->canonpath("path/to/the/./nowhere/../../somewhere"), + "path/to/somewhere", "canonpath no1" ); +is( $BS_CLASS->canonpath("path/to/../forward/../../somewhere"), + "somewhere","canonpath no2" ); +is( $BS_CLASS->canonpath("path/to/../../../somewhere"), + "../somewhere","canonpath no3" ); +is( $BS_CLASS->canonpath("./"), ".", "canonpath no4" ); +is( $BS_CLASS->canonpath("/absolute/path/./somewhere/../to/nowhere"), + "/absolute/path/to/nowhere", "canonpath no5" ); +is( $BS_CLASS->_rel2rel("path/my/file", "path/my", "/tmp"), + "file", "_rel2rel no1" ); +is( $BS_CLASS->_rel2rel("path/dir/file", "path/my", "/tmp"), + "../dir/file", "_rel2rel no2" ); +is( $BS_CLASS->_rel2rel("file", "/root/path/my", "/root"), + "/root/file", "_rel2rel abs no3" ); +is( $BS_CLASS->_rel2rel(".", ".", "/tmp"), ".", "_rel2rel no4" ); +is( $BS_CLASS->_rel2rel("path", "path/", "/tmp"), ".", "_rel2rel no5" ); +is( $BS_CLASS->_rel2rel("/absolute/path", "anybase", "/tmp"), + "/absolute/path", "_rel2rel abs no6"); +is( $BS_CLASS->_rel2rel("relative/path", "/absolute/base", "/tmp"), + "/tmp/relative/path", "_rel2rel abs no7"); + +### Test Buildsystem class path API methods under different configurations +sub test_buildsystem_paths_api { + my ($bs, $config, $expected)=@_; + + my $api_is = sub { + my ($got, $name)=@_; + is( $got, $expected->{$name}, "paths API ($config): $name") + }; + + &$api_is( $bs->get_sourcedir(), 'get_sourcedir()' ); + &$api_is( $bs->get_sourcepath("a/b"), 'get_sourcepath(a/b)' ); + &$api_is( $bs->get_builddir(), 'get_builddir()' ); + &$api_is( $bs->get_buildpath(), 'get_buildpath()' ); + &$api_is( $bs->get_buildpath("a/b"), 'get_buildpath(a/b)' ); + &$api_is( $bs->get_source_rel2builddir(), 'get_source_rel2builddir()' ); + &$api_is( $bs->get_source_rel2builddir("a/b"), 'get_source_rel2builddir(a/b)' ); + &$api_is( $bs->get_build_rel2sourcedir(), 'get_build_rel2sourcedir()' ); + &$api_is( $bs->get_build_rel2sourcedir("a/b"), 'get_build_rel2sourcedir(a/b)' ); +} + +# Defaults +$bs = $BS_CLASS->new(); +$default_builddir = $bs->DEFAULT_BUILD_DIRECTORY(); +%tmp = ( + "get_sourcedir()" => ".", + "get_sourcepath(a/b)" => "./a/b", + "get_builddir()" => undef, + "get_buildpath()" => ".", + "get_buildpath(a/b)" => "./a/b", + "get_source_rel2builddir()" => ".", + "get_source_rel2builddir(a/b)" => "./a/b", + "get_build_rel2sourcedir()" => ".", + "get_build_rel2sourcedir(a/b)" => "./a/b", +); +test_buildsystem_paths_api($bs, "no builddir, no sourcedir", \%tmp); + +# builddir=bld/dir +$bs = $BS_CLASS->new(builddir => "bld/dir"); +%tmp = ( + "get_sourcedir()" => ".", + "get_sourcepath(a/b)" => "./a/b", + "get_builddir()" => "bld/dir", + "get_buildpath()" => "bld/dir", + "get_buildpath(a/b)" => "bld/dir/a/b", + "get_source_rel2builddir()" => "../..", + "get_source_rel2builddir(a/b)" => "../../a/b", + "get_build_rel2sourcedir()" => "bld/dir", + "get_build_rel2sourcedir(a/b)" => "bld/dir/a/b", +); +test_buildsystem_paths_api($bs, "builddir=bld/dir, no sourcedir", \%tmp); + +# Default builddir, sourcedir=autoconf +$bs = $BS_CLASS->new(builddir => undef, sourcedir => "autoconf"); +%tmp = ( + "get_sourcedir()" => "autoconf", + "get_sourcepath(a/b)" => "autoconf/a/b", + "get_builddir()" => "$default_builddir", + "get_buildpath()" => "$default_builddir", + "get_buildpath(a/b)" => "$default_builddir/a/b", + "get_source_rel2builddir()" => "../autoconf", + "get_source_rel2builddir(a/b)" => "../autoconf/a/b", + "get_build_rel2sourcedir()" => "../$default_builddir", + "get_build_rel2sourcedir(a/b)" => "../$default_builddir/a/b", +); +test_buildsystem_paths_api($bs, "default builddir, sourcedir=autoconf", \%tmp); + +# sourcedir=autoconf (builddir should be dropped) +$bs = $BS_CLASS->new(builddir => "autoconf", sourcedir => "autoconf"); +%tmp = ( + "get_sourcedir()" => "autoconf", + "get_sourcepath(a/b)" => "autoconf/a/b", + "get_builddir()" => undef, + "get_buildpath()" => "autoconf", + "get_buildpath(a/b)" => "autoconf/a/b", + "get_source_rel2builddir()" => ".", + "get_source_rel2builddir(a/b)" => "./a/b", + "get_build_rel2sourcedir()" => ".", + "get_build_rel2sourcedir(a/b)" => "./a/b", +); +test_buildsystem_paths_api($bs, "no builddir, sourcedir=autoconf", \%tmp); + +# Prefer out of source tree building when +# sourcedir=builddir=autoconf hence builddir should be dropped. +$bs->prefer_out_of_source_building(builddir => "autoconf"); +test_buildsystem_paths_api($bs, "out of source prefered, sourcedir=builddir", \%tmp); + +# builddir=bld/dir, sourcedir=autoconf. Should be the same as sourcedir=autoconf. +$bs = $BS_CLASS->new(builddir => "bld/dir", sourcedir => "autoconf"); +$bs->enforce_in_source_building(); +test_buildsystem_paths_api($bs, "in source enforced, sourcedir=autoconf", \%tmp); + +# builddir=../bld/dir (relative to the curdir) +$bs = $BS_CLASS->new(builddir => "bld/dir/", sourcedir => "autoconf"); +%tmp = ( + "get_sourcedir()" => "autoconf", + "get_sourcepath(a/b)" => "autoconf/a/b", + "get_builddir()" => "bld/dir", + "get_buildpath()" => "bld/dir", + "get_buildpath(a/b)" => "bld/dir/a/b", + "get_source_rel2builddir()" => "../../autoconf", + "get_source_rel2builddir(a/b)" => "../../autoconf/a/b", + "get_build_rel2sourcedir()" => "../bld/dir", + "get_build_rel2sourcedir(a/b)" => "../bld/dir/a/b", +); +test_buildsystem_paths_api($bs, "builddir=../bld/dir, sourcedir=autoconf", \%tmp); + +### Test check_auto_buildable() of each buildsystem +sub test_check_auto_buildable { + my $bs=shift; + my $config=shift; + my $expected=shift; + my @steps=@_ || @STEPS; + + if (! ref $expected) { + my %all_steps; + $all_steps{$_} = $expected foreach (@steps); + $expected = \%all_steps; + } + for my $step (@steps) { + my $e = 0; + if (exists $expected->{$step}) { + $e = $expected->{$step}; + } elsif (exists $expected->{default}) { + $e = $expected->{default}; + } + is( $bs->check_auto_buildable($step), $e, + $bs->NAME() . "($config): check_auto_buildable($step) == $e" ); + } +} + +$tmpdir = tempdir("tmp.XXXXXX"); +$builddir = "$tmpdir/builddir"; +mkdir $builddir; +%tmp = ( + builddir => "$tmpdir/builddir", + sourcedir => $tmpdir +); + +# Test if all buildsystems can be loaded +@bs = load_all_buildsystems([ $INC[0] ], %tmp); +@tmp = map { $_->NAME() } @bs; +ok(@Debian::Debhelper::Dh_Buildsystems::BUILDSYSTEMS >= 1, "some build systems are built in" ); +is_deeply( \@tmp, \@Debian::Debhelper::Dh_Buildsystems::BUILDSYSTEMS, "load_all_buildsystems() loads all built-in buildsystems" ); + +# check_auto_buildable() fails with numeric 0 +for $bs (@bs) { + test_check_auto_buildable($bs, "fails with numeric 0", 0); +} + +%bs = (); +for $bs (@bs) { + $bs{$bs->NAME()} = $bs; +} + +touch "$tmpdir/configure", 0755; +test_check_auto_buildable($bs{autoconf}, "configure", { configure => 1 }); + +touch "$tmpdir/CMakeLists.txt"; +test_check_auto_buildable($bs{cmake}, "CMakeLists.txt", { configure => 1, clean => 1 }); + +touch "$tmpdir/Makefile.PL"; +test_check_auto_buildable($bs{perl_makemaker}, "Makefile.PL", { configure => 1 }); + +# With Makefile +touch "$builddir/Makefile"; +test_check_auto_buildable($bs{makefile}, "Makefile", 1); +test_check_auto_buildable($bs{autoconf}, "configure+Makefile", { configure => 1 }); +test_check_auto_buildable($bs{cmake}, "CMakeLists.txt+Makefile", 1); +touch "$builddir/CMakeCache.txt"; # strong evidence that cmake was run +test_check_auto_buildable($bs{cmake}, "CMakeCache.txt+Makefile", 2); + +# Makefile.PL forces in-source +#(see note in check_auto_buildable() why always 1 here) +unlink "$builddir/Makefile"; +touch "$tmpdir/Makefile"; +test_check_auto_buildable($bs{perl_makemaker}, "Makefile.PL+Makefile", 1); + +# Perl Build.PL - handles always +test_check_auto_buildable($bs{perl_build}, "no Build.PL", 0); +touch "$tmpdir/Build.PL"; +test_check_auto_buildable($bs{perl_build}, "Build.PL", { configure => 1 }); +touch "$tmpdir/Build"; # forced in source +test_check_auto_buildable($bs{perl_build}, "Build.PL+Build", 1); + +# Python Distutils +test_check_auto_buildable($bs{python_distutils}, "no setup.py", 0); +touch "$tmpdir/setup.py"; +test_check_auto_buildable($bs{python_distutils}, "setup.py", 1); + +cleandir($tmpdir); + +### Now test if it can autoselect a proper buildsystem for a typical package +sub test_autoselection { + my $testname=shift; + my $expected=shift; + my %args=@_; + for my $step (@STEPS) { + my $bs = load_buildsystem(undef, $step, @_); + my $e = $expected; + $e = $expected->{$step} if ref $expected; + if (defined $bs) { + is( $bs->NAME(), $e, "autoselection($testname): $step=".((defined $e)?$e:'undef') ); + } + else { + is ( undef, $e, "autoselection($testname): $step=".((defined $e)?$e:'undef') ); + } + &{$args{"code_$step"}}() if exists $args{"code_$step"}; + } +} + +# Auto-select nothing when no supported build system can be found +# (see #557006). +test_autoselection("auto-selects nothing", undef, %tmp); + +# Autoconf +touch "$tmpdir/configure", 0755; +touch "$builddir/Makefile"; +test_autoselection("autoconf", + { configure => "autoconf", build => "makefile", + test => "makefile", install => "makefile", clean => "makefile" }, %tmp); +cleandir $tmpdir; + +# Perl Makemaker (build, test, clean fail with builddir set [not supported]) +touch "$tmpdir/Makefile.PL"; +touch "$tmpdir/Makefile"; +test_autoselection("perl_makemaker", "perl_makemaker", %tmp); +cleandir $tmpdir; + +# Makefile +touch "$builddir/Makefile"; +test_autoselection("makefile", "makefile", %tmp); +cleandir $tmpdir; + +# Python Distutils +touch "$tmpdir/setup.py"; +test_autoselection("python_distutils", "python_distutils", %tmp); +cleandir $tmpdir; + +# Perl Build +touch "$tmpdir/Build.PL"; +touch "$tmpdir/Build"; +test_autoselection("perl_build", "perl_build", %tmp); +cleandir $tmpdir; + +# CMake +touch "$tmpdir/CMakeLists.txt"; +$tmp = sub { + touch "$builddir/Makefile"; +}; +test_autoselection("cmake without CMakeCache.txt", + { configure => "cmake", build => "makefile", + test => "makefile", install => "makefile", clean => "makefile" }, %tmp, + code_configure => $tmp); +cleandir $tmpdir; + +touch "$tmpdir/CMakeLists.txt"; +$tmp = sub { + touch "$builddir/Makefile"; + touch "$builddir/CMakeCache.txt"; +}; +test_autoselection("cmake with CMakeCache.txt", + "cmake", %tmp, code_configure => $tmp); +cleandir $tmpdir; + +touch "$tmpdir/CMakeLists.txt"; +touch "$builddir/Makefile"; +test_autoselection("cmake and existing Makefile", "makefile", %tmp); +cleandir $tmpdir; + +### Test Buildsystem::rmdir_builddir() +sub do_rmdir_builddir { + my $builddir=shift; + my $system; + $system = $BS_CLASS->new(builddir => $builddir, sourcedir => $tmpdir); + $system->mkdir_builddir(); + $system->rmdir_builddir(); +} + +$builddir = "$tmpdir/builddir"; +do_rmdir_builddir($builddir); +ok ( ! -e $builddir, "testing rmdir_builddir() 1: builddir parent '$builddir' deleted" ); +ok ( -d $tmpdir, "testing rmdir_builddir() 1: sourcedir '$tmpdir' remains" ); + +$builddir = "$tmpdir/bld"; +do_rmdir_builddir("$builddir/dir"); +ok ( ! -e $builddir, "testing rmdir_builddir() 2: builddir parent '$builddir' deleted" ); +ok ( -d $tmpdir, "testing rmdir_builddir() 2: sourcedir '$tmpdir' remains" ); + +$builddir = "$tmpdir/bld"; +mkdir "$builddir"; +touch "$builddir/afile"; +mkdir "$builddir/dir"; +touch "$builddir/dir/afile2"; +do_rmdir_builddir("$builddir/dir"); +ok ( ! -e "$builddir/dir", "testing rmdir_builddir() 3: builddir '$builddir/dir' not empty, but deleted" ); +ok ( -d $builddir, "testing rmdir_builddir() 3: builddir parent '$builddir' not empty, remains" ); + +cleandir $tmpdir; + +### Test buildsystems_init() and commandline/env argument handling +sub get_load_bs_source { + my ($system, $step)=@_; + $step = (defined $step) ? "'$step'" : 'undef'; + $system = (defined $system) ? "'$system'" : 'undef'; + +return <<EOF; +use strict; +use warnings; +use Debian::Debhelper::Dh_Buildsystems; + +buildsystems_init(); +my \$bs = load_buildsystem($system, $step); +if (defined \$bs) { + print 'NAME=', \$bs->NAME(), "\\n"; + print \$_, "=", (defined \$bs->{\$_}) ? \$bs->{\$_} : 'undef', "\\n" + foreach (sort keys \%\$bs); +} +EOF +} + +$tmp = Cwd::getcwd(); +# NOTE: disabling parallel building explicitly (it might get automatically +# enabled if run under dpkg-buildpackage -jX) to make output deterministic. +is_deeply( process_stdout("$^X -- - --builddirectory='autoconf/bld dir' --sourcedirectory autoconf --max-parallel=1", + get_load_bs_source(undef, "configure")), + [ 'NAME=autoconf', 'builddir=autoconf/bld dir', "cwd=$tmp", 'makecmd=make', 'parallel=1', 'sourcedir=autoconf' ], + "autoconf autoselection and sourcedir/builddir" ); + +is_deeply( process_stdout("$^X -- - -Sautoconf -D autoconf --max-parallel=1", get_load_bs_source("autoconf", "build")), + [ 'NAME=autoconf', 'builddir=undef', "cwd=$tmp", 'makecmd=make', 'parallel=1', 'sourcedir=autoconf' ], + "forced autoconf and sourcedir" ); + +is_deeply( process_stdout("$^X -- - -B -Sautoconf --max-parallel=1", get_load_bs_source("autoconf", "build")), + [ 'NAME=autoconf', "builddir=$default_builddir", "cwd=$tmp", 'makecmd=make', 'parallel=1', 'sourcedir=.' ], + "forced autoconf and default build directory" ); + +# Build the autoconf test package +sub dh_auto_do_autoconf { + my $sourcedir=shift; + my $builddir=shift; + my %args=@_; + + my (@lines, @extra_args); + my $buildpath = $sourcedir; + my @dh_auto_args = ("-D", $sourcedir); + my $dh_auto_str = "-D $sourcedir"; + if ($builddir) { + push @dh_auto_args, "-B", $builddir; + $dh_auto_str .= " -B $builddir"; + $buildpath = $builddir; + } + + my $do_dh_auto = sub { + my $step=shift; + my @extra_args; + my $extra_str = ""; + if (exists $args{"${step}_args"}) { + push @extra_args, @{$args{"${step}_args"}}; + $extra_str .= " $_" foreach (@extra_args); + } + is ( system("$TOPDIR/dh_auto_$step", @dh_auto_args, "--", @extra_args), 0, + "dh_auto_$step $dh_auto_str$extra_str" ); + return @extra_args; + }; + + @extra_args = &$do_dh_auto('configure'); + ok ( -f "$buildpath/Makefile", "$buildpath/Makefile exists" ); + @lines=(); + if (ok( open(FILE, "$buildpath/stamp_configure"), "$buildpath/stamp_configure exists") ) { + @lines = @{readlines(\*FILE)}; + } + is_deeply( \@lines, \@extra_args, "$buildpath/stamp_configure contains extra args" ); + + &$do_dh_auto('build'); + ok ( -f "$buildpath/stamp_build", "$buildpath/stamp_build exists" ); + &$do_dh_auto('test'); + ok ( -f "$buildpath/stamp_test", "$buildpath/stamp_test exists" ); + &$do_dh_auto('install'); + @lines=(); + if ( ok(open(FILE, "$buildpath/stamp_install"), "$buildpath/stamp_install exists") ) { + @lines = @{readlines(\*FILE)}; + } + is_deeply( \@lines, [ "DESTDIR=".Cwd::getcwd()."/debian/testpackage" ], + "$buildpath/stamp_install contains DESTDIR" ); + &$do_dh_auto('clean'); + if ($builddir) { + ok ( ! -e "$buildpath", "builddir $buildpath was removed" ); + } + else { + ok ( ! -e "$buildpath/Makefile" && ! -e "$buildpath/stamp_configure", "Makefile and stamps gone" ); + } + ok ( -x "$sourcedir/configure", "configure script renamins after clean" ); +} + +dh_auto_do_autoconf('autoconf'); +dh_auto_do_autoconf('autoconf', 'bld/dir', configure_args => [ "--extra-autoconf-configure-arg" ]); +ok ( ! -e 'bld', "bld got deleted too" ); + +#### Test parallel building and related options / routines +@tmp = ( $ENV{MAKEFLAGS}, $ENV{DEB_BUILD_OPTIONS} ); + +# Test clean_jobserver_makeflags. + +$ENV{MAKEFLAGS} = "--jobserver-fds=103,104 -j"; +clean_jobserver_makeflags(); +ok(! exists $ENV{MAKEFLAGS}, "unset makeflags"); + +$ENV{MAKEFLAGS} = "-a --jobserver-fds=103,104 -j -b"; +clean_jobserver_makeflags(); +is($ENV{MAKEFLAGS}, "-a -b", "clean makeflags"); + +$ENV{MAKEFLAGS} = " --jobserver-fds=1,2 -j "; +clean_jobserver_makeflags(); +ok(! exists $ENV{MAKEFLAGS}, "unset makeflags"); + +$ENV{MAKEFLAGS} = "-a -j -b"; +clean_jobserver_makeflags(); +is($ENV{MAKEFLAGS}, "-a -j -b", "clean makeflags does not remove -j"); + +$ENV{MAKEFLAGS} = "-a --jobs -b"; +clean_jobserver_makeflags(); +is($ENV{MAKEFLAGS}, "-a --jobs -b", "clean makeflags does not remove --jobs"); + +$ENV{MAKEFLAGS} = "-j6"; +clean_jobserver_makeflags(); +is($ENV{MAKEFLAGS}, "-j6", "clean makeflags does not remove -j6"); + +$ENV{MAKEFLAGS} = "-a -j6 --jobs=7"; +clean_jobserver_makeflags(); +is($ENV{MAKEFLAGS}, "-a -j6 --jobs=7", "clean makeflags does not remove -j or --jobs"); + +$ENV{MAKEFLAGS} = "-j6 --jobserver-fds=103,104 --jobs=8"; +clean_jobserver_makeflags(); +is($ENV{MAKEFLAGS}, "-j6 --jobs=8", "jobserver options removed"); + +# Test parallel building with makefile build system. +$ENV{MAKEFLAGS} = ""; +$ENV{DEB_BUILD_OPTIONS} = ""; + +sub do_parallel_mk { + my $dh_opts=shift || ""; + my $make_opts=shift || ""; + return process_stdout( + "LANG=C LC_ALL=C LC_MESSAGES=C $TOPDIR/dh_auto_build -Smakefile $dh_opts " . + "-- -s -f parallel.mk $make_opts 2>&1 >/dev/null", ""); +} + +sub test_isnt_parallel { + my ($got, $desc) = @_; + my @makemsgs = grep /^make[\d\[\]]*:/, @$got; + if (@makemsgs) { + like( $makemsgs[0], qr/Error 10/, $desc ); + } + else { + ok( scalar(@makemsgs) > 0, $desc ); + } +} + +sub test_is_parallel { + my ($got, $desc) = @_; + is_deeply( $got, [] , $desc ); + is( $?, 0, "(exit status=0) $desc"); +} + +test_isnt_parallel( do_parallel_mk(), + "No parallel by default" ); +test_isnt_parallel( do_parallel_mk("parallel"), + "No parallel by default with --parallel" ); +test_isnt_parallel( do_parallel_mk("--max-parallel=5"), + "No parallel by default with --max-parallel=5" ); + +$ENV{DEB_BUILD_OPTIONS}="parallel=5"; +test_isnt_parallel( do_parallel_mk(), + "DEB_BUILD_OPTIONS=parallel=5 without parallel options" ); +test_is_parallel( do_parallel_mk("--parallel"), + "DEB_BUILD_OPTIONS=parallel=5 with --parallel" ); +test_is_parallel( do_parallel_mk("--max-parallel=2"), + "DEB_BUILD_OPTIONS=parallel=5 with --max-parallel=2" ); +test_isnt_parallel( do_parallel_mk("--max-parallel=1"), + "DEB_BUILD_OPTIONS=parallel=5 with --max-parallel=1" ); + +$ENV{MAKEFLAGS} = "--jobserver-fds=105,106 -j"; +$ENV{DEB_BUILD_OPTIONS}=""; +test_isnt_parallel( do_parallel_mk(), + "makefile.pm (no parallel): no make warnings about unavailable jobserver" ); +$ENV{DEB_BUILD_OPTIONS}="parallel=5"; +test_is_parallel( do_parallel_mk("--parallel"), + "DEB_BUILD_OPTIONS=parallel=5: no make warnings about unavail parent jobserver" ); + +$ENV{MAKEFLAGS} = "-j2"; +$ENV{DEB_BUILD_OPTIONS}=""; +test_isnt_parallel( do_parallel_mk(), + "MAKEFLAGS=-j2: dh_auto_build ignores MAKEFLAGS" ); +test_isnt_parallel( do_parallel_mk("--max-parallel=1"), + "MAKEFLAGS=-j2 with --max-parallel=1: dh_auto_build enforces -j1" ); + +# Test dh dpkg-buildpackage -jX detection +sub do_rules_for_parallel { + my $cmdline=shift || ""; + my $stdin=shift || ""; + return process_stdout("LANG=C LC_ALL=C LC_MESSAGES=C PATH=$TOPDIR:\$PATH " . + "make -f - $cmdline 2>&1 >/dev/null", $stdin); +} + +doit("ln", "-sf", "parallel.mk", "Makefile"); + +# Test if dh+override+$(MAKE) legacy punctuation hack work as before +$ENV{MAKEFLAGS} = "-j5"; +$ENV{DEB_BUILD_OPTIONS} = "parallel=5"; + +$tmp = write_debian_rules(<<'EOF'); +#!/usr/bin/make -f +override_dh_auto_build: + $(MAKE) +%: + @dh_clean > /dev/null 2>&1 + @+dh --buildsystem=makefile --after=dh_auto_configure --until=dh_auto_build $@ 2>/dev/null + @dh_clean > /dev/null 2>&1 +EOF +test_is_parallel( do_rules_for_parallel("build", "include debian/rules"), + "legacy punctuation hacks: +dh, override with \$(MAKE)" ); +unlink "debian/rules"; + +if (defined $tmp) { + rename($tmp, "debian/rules"); +} +else { + unlink("debian/rules"); +} + +# Clean up after parallel testing +END { + system("rm", "-f", "Makefile"); +} +$ENV{MAKEFLAGS} = $tmp[0] if defined $tmp[0]; +$ENV{DEB_BUILD_OPTIONS} = $tmp[1] if defined $tmp[1]; + +END { + system("rm", "-rf", $tmpdir); + system("$TOPDIR/dh_clean"); +} diff --git a/t/buildsystems/debian/changelog b/t/buildsystems/debian/changelog new file mode 100644 index 00000000..f902d892 --- /dev/null +++ b/t/buildsystems/debian/changelog @@ -0,0 +1,5 @@ +testpackage (1.0-1) unstable; urgency=low + + * Initial release. (Closes: #XXXXXX) + + -- Test <testing@nowhere> Tue, 09 Jun 2009 15:35:32 +0300 diff --git a/t/buildsystems/debian/compat b/t/buildsystems/debian/compat new file mode 100644 index 00000000..7f8f011e --- /dev/null +++ b/t/buildsystems/debian/compat @@ -0,0 +1 @@ +7 diff --git a/t/buildsystems/debian/control b/t/buildsystems/debian/control new file mode 100644 index 00000000..7edd806e --- /dev/null +++ b/t/buildsystems/debian/control @@ -0,0 +1,10 @@ +Source: testsrcpackage +Section: devel +Priority: optional +Maintainer: Test <testing@nowhere> +Standards-Version: 3.8.1 + +Package: testpackage +Architecture: all +Description: short description + Long description diff --git a/t/buildsystems/parallel.mk b/t/buildsystems/parallel.mk new file mode 100644 index 00000000..3e0d201d --- /dev/null +++ b/t/buildsystems/parallel.mk @@ -0,0 +1,21 @@ +all: FIRST SECOND + +TMPFILE ?= $(CURDIR)/parallel.mk.lock + +rmtmpfile: + @rm -f "$(TMPFILE)" + +FIRST: rmtmpfile + @c=0; \ + while [ $$c -le 5 ] && \ + ([ ! -e "$(TMPFILE)" ] || [ "`cat "$(TMPFILE)"`" != "SECOND" ]); do \ + c=$$(($$c+1)); \ + sleep 0.1; \ + done; \ + rm -f "$(TMPFILE)"; \ + if [ $$c -gt 5 ]; then exit 10; else exit 0; fi + +SECOND: rmtmpfile + @echo $@ > "$(TMPFILE)" + +.PHONY: all FIRST SECOND rmtmpfile diff --git a/t/dh-lib b/t/dh-lib new file mode 100755 index 00000000..772b1a1e --- /dev/null +++ b/t/dh-lib @@ -0,0 +1,31 @@ +#!/usr/bin/perl +package Debian::Debhelper::Dh_Lib::Test; +use strict; +use warnings; +use Test::More; + +plan(tests => 10); + +use_ok('Debian::Debhelper::Dh_Lib'); + +sub ok_autoscript_result { + ok(-f 'debian/testpackage.postinst.debhelper'); + open(F, 'debian/testpackage.postinst.debhelper') or die; + my (@c) = <F>; + close(F) or die; + like(join('',@c), qr{update-rc\.d test-script test parms with"quote >/dev/null}); +} + +ok(unlink('debian/testpackage.postinst.debhelper') >= 0); + +ok(autoscript('testpackage', 'postinst', 'postinst-init', + 's/#SCRIPT#/test-script/g; s/#INITPARMS#/test parms with\\"quote/g')); +ok_autoscript_result; + +ok(unlink('debian/testpackage.postinst.debhelper') >= 0); + +ok(autoscript('testpackage', 'postinst', 'postinst-init', + sub { s/#SCRIPT#/test-script/g; s/#INITPARMS#/test parms with"quote/g } )); +ok_autoscript_result; + +ok(unlink('debian/testpackage.postinst.debhelper') >= 0); diff --git a/t/dh_install b/t/dh_install new file mode 100755 index 00000000..447a40a8 --- /dev/null +++ b/t/dh_install @@ -0,0 +1,88 @@ +#!/usr/bin/perl +use Test; +plan(tests => 23); + +system("rm -rf debian/debhelper debian/tmp"); + +# #537140: debian/tmp is explcitly specified despite being searched by +# default in v7+ +system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar"); +system("./dh_install", "debian/tmp/usr/bin/foo"); +ok(-e "debian/debhelper/usr/bin/foo"); +ok(! -e "debian/debhelper/usr/bin/bar"); +system("rm -rf debian/debhelper debian/tmp"); + +# debian/tmp explicitly specified in filenames in older compat level +system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar"); +system("DH_COMPAT=6 ./dh_install debian/tmp/usr/bin/foo"); +ok(-e "debian/debhelper/usr/bin/foo"); +ok(! -e "debian/debhelper/usr/bin/bar"); +system("rm -rf debian/debhelper debian/tmp"); + +# --sourcedir=debian/tmp in older compat level +system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar"); +system("DH_COMPAT=6 ./dh_install --sourcedir=debian/tmp usr/bin/foo"); +ok(-e "debian/debhelper/usr/bin/foo"); +ok(! -e "debian/debhelper/usr/bin/bar"); +system("rm -rf debian/debhelper debian/tmp"); + +# redundant --sourcedir=debian/tmp in v7+ +system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar"); +system("./dh_install --sourcedir=debian/tmp usr/bin/foo"); +ok(-e "debian/debhelper/usr/bin/foo"); +ok(! -e "debian/debhelper/usr/bin/bar"); +system("rm -rf debian/debhelper debian/tmp"); + +# #537017: --sourcedir=debian/tmp/foo is used +system("mkdir -p debian/tmp/foo/usr/bin; touch debian/tmp/foo/usr/bin/foo; touch debian/tmp/foo/usr/bin/bar"); +system("./dh_install", "--sourcedir=debian/tmp/foo", "usr/bin/bar"); +ok(-e "debian/debhelper/usr/bin/bar"); +ok(! -e "debian/debhelper/usr/bin/foo"); +system("rm -rf debian/debhelper debian/tmp"); + +# #535367: installation of entire top-level directory from debian/tmp +system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar"); +system("./dh_install", "usr"); +ok(-e "debian/debhelper/usr/bin/foo"); +ok(-e "debian/debhelper/usr/bin/bar"); +system("rm -rf debian/debhelper debian/tmp"); + +# #534565: fallback use of debian/tmp in v7+ +system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar"); +system("./dh_install", "usr/bin"); +ok(-e "debian/debhelper/usr/bin/foo"); +ok(-e "debian/debhelper/usr/bin/bar"); +system("rm -rf debian/debhelper debian/tmp"); + +# no fallback to debian/tmp before v7 +system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar"); +system("DH_COMPAT=6 ./dh_install usr/bin 2>/dev/null"); +ok(! -e "debian/debhelper/usr/bin/foo"); +ok(! -e "debian/debhelper/usr/bin/bar"); +system("rm -rf debian/debhelper debian/tmp"); + +# #534565: glob expands to dangling symlink -> should install the dangling link +system("mkdir -p debian/tmp/usr/bin; ln -s broken debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar"); +system("./dh_install", "usr/bin/*"); +ok(-l "debian/debhelper/usr/bin/foo"); +ok(! -e "debian/debhelper/usr/bin/foo"); +ok(-e "debian/debhelper/usr/bin/bar"); +ok(! -l "debian/debhelper/usr/bin/bar"); +system("rm -rf debian/debhelper debian/tmp"); + +# regular specification of file not in debian/tmp +system("./dh_install", "dh_install", "usr/bin"); +ok(-e "debian/debhelper/usr/bin/dh_install"); +system("rm -rf debian/debhelper debian/tmp"); + +# specification of file in source directory not in debian/tmp +system("mkdir -p bar/usr/bin; touch bar/usr/bin/foo"); +system("./dh_install", "--sourcedir=bar", "usr/bin/foo"); +ok(-e "debian/debhelper/usr/bin/foo"); +system("rm -rf debian/debhelper bar"); + +# specification of file in subdir, not in debian/tmp +system("mkdir -p bar/usr/bin; touch bar/usr/bin/foo"); +system("./dh_install", "bar/usr/bin/foo"); +ok(-e "debian/debhelper/bar/usr/bin/foo"); +system("rm -rf debian/debhelper bar"); diff --git a/t/dh_link b/t/dh_link new file mode 100755 index 00000000..c6be35be --- /dev/null +++ b/t/dh_link @@ -0,0 +1,45 @@ +#!/usr/bin/perl +use Test; +plan(tests => 13); + +# It used to not make absolute links in this situation, and it should. +# #37774 +system("./dh_link","etc/foo","usr/lib/bar"); +ok(readlink("debian/debhelper/usr/lib/bar"), "/etc/foo"); + +# let's make sure it makes simple relative links ok. +system("./dh_link","usr/bin/foo","usr/bin/bar"); +ok(readlink("debian/debhelper/usr/bin/bar"), "foo"); +system("./dh_link","sbin/foo","sbin/bar"); +ok(readlink("debian/debhelper/sbin/bar"), "foo"); + +# ok, more complex relative links. +system("./dh_link","usr/lib/1","usr/bin/2"); +ok(readlink("debian/debhelper/usr/bin/2"),"../lib/1"); + +# Check conversion of relative symlink to different top-level directory +# into absolute symlink. (#244157) +system("mkdir -p debian/debhelper/usr/lib; mkdir -p debian/debhelper/lib; touch debian/debhelper/lib/libm.so; cd debian/debhelper/usr/lib; ln -sf ../../lib/libm.so"); +system("./dh_link"); +ok(readlink("debian/debhelper/usr/lib/libm.so"), "/lib/libm.so"); + +# Check links to the current directory and below, they used to be +# unnecessarily long (#346405). +system("./dh_link","usr/lib/geant4","usr/lib/geant4/a"); +ok(readlink("debian/debhelper/usr/lib/geant4/a"), "."); +system("./dh_link","usr/lib","usr/lib/geant4/b"); +ok(readlink("debian/debhelper/usr/lib/geant4/b"), ".."); +system("./dh_link","usr","usr/lib/geant4/c"); +ok(readlink("debian/debhelper/usr/lib/geant4/c"), "../.."); +system("./dh_link","/","usr/lib/geant4/d"); +ok(readlink("debian/debhelper/usr/lib/geant4/d"), "/"); + +# Link to self. +system("./dh_link usr/lib/foo usr/lib/foo 2>/dev/null"); +ok(! -l "debian/debhelper/usr/lib/foo"); + +# Make sure the link conversion didn't change any of the previously made +# links. +ok(readlink("debian/debhelper/usr/lib/bar"), "/etc/foo"); +ok(readlink("debian/debhelper/usr/bin/bar"), "foo"); +ok(readlink("debian/debhelper/usr/bin/2"),"../lib/1"); diff --git a/t/maintscript b/t/maintscript new file mode 100644 index 00000000..bf15d445 --- /dev/null +++ b/t/maintscript @@ -0,0 +1,19 @@ +#!/usr/bin/perl +use Test; +plan(tests => 8); + +system("mkdir -p t/tmp/debian"); +system("cp debian/control t/tmp/debian"); +open(OUT, ">", "t/tmp/debian/maintscript") || die "$!"; +print OUT <<EOF; +rm_conffile /etc/1 +mv_conffile /etc/2 /etc/3 1.0-1 +EOF +close OUT; +system("cd t/tmp && DH_COMPAT=7 fakeroot ../../dh_installdeb"); +for my $script (qw{postinst preinst prerm postrm}) { + my @output=`cat t/tmp/debian/debhelper.$script.debhelper`; + ok(grep { m{^dpkg-maintscript-helper rm_conffile /etc/1 -- "\$\@"$} } @output); + ok(grep { m{^dpkg-maintscript-helper mv_conffile /etc/2 /etc/3 1\.0-1 -- "\$\@"$} } @output); +} +system("rm -rf t/tmp"); diff --git a/t/override_target b/t/override_target new file mode 100755 index 00000000..28ceda84 --- /dev/null +++ b/t/override_target @@ -0,0 +1,22 @@ +#!/usr/bin/perl +use Test; +plan(tests => 1); + +# This test is here to detect breakage in +# dh's rules_explicit_target, which parses +# slightly internal make output. +system("mkdir -p t/tmp/debian"); +system("cp debian/control t/tmp/debian"); +open (OUT, ">", "t/tmp/debian/rules") || die "$!"; +print OUT <<EOF; +#!/usr/bin/make -f +%: + PATH=../..:\$\$PATH PERL5LIB=../.. ../../dh \$@ +override_dh_auto_build: + echo "override called" +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); +system("rm -rf t/tmp"); @@ -0,0 +1,10 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; + +eval 'use Test::Pod'; +plan skip_all => 'Test::Pod required' if $@; + +all_pod_files_ok(grep { -x $_ } glob 'dh_*'); @@ -0,0 +1,29 @@ +#!/usr/bin/perl +# This may appear arbitrary, but DO NOT CHANGE IT. +# Debhelper is supposed to consist of small, simple, easy to understand +# programs. Programs growing in size and complexity without bounds is a +# bug. +use Test::More; + +my @progs=grep { -x $_ } glob("dh_*"); + +plan(tests => (@progs + @progs)); + +foreach my $file (@progs) { + + my $lines=0; + my $maxlength=0; + open(IN, $file) || die "open: $!"; + my $cutting=0; + while (<IN>) { + $cutting=1 if /^=/; + $cutting=0 if /^=cut/; + next if $cutting || /^(=|\s*\#)/; + $lines++; + $maxlength=length($_) if length($_) > $maxlength; + } + close IN; + print "# $file has $lines lines, max length is $maxlength\n"; + ok($lines < 200, $file); + ok($maxlength < 160, $file); +} diff --git a/t/syntax b/t/syntax new file mode 100755 index 00000000..92455457 --- /dev/null +++ b/t/syntax @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use Test; + +my @progs=grep { -x $_ } glob("dh_*"), "dh"; +my @libs=(glob("Debian/Debhelper/*.pm"), glob("Debian/Debhelper/*/*.pm")); + +plan(tests => (@progs + @libs)); + +foreach my $file (@progs, @libs) { + print "# Testing $file\n"; + ok(system("perl -c $file >/dev/null 2>&1"), 0); +} |