[debhelper-devel] [debhelper] 23/30: t: Split buildsystem_tests in to smaller bits
Niels Thykier
nthykier at moszumanska.debian.org
Mon Jul 3 14:40:38 UTC 2017
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository debhelper.
commit 61d0579dd5f19220422a6ab71fff1c3b8f545b87
Author: Niels Thykier <niels at thykier.net>
Date: Sun Jul 2 19:02:38 2017 +0000
t: Split buildsystem_tests in to smaller bits
Signed-off-by: Niels Thykier <niels at thykier.net>
---
t/Test/DH.pm | 10 +-
t/buildsystems/01-build-system-basic-api.t | 49 ++++
t/buildsystems/03-bs-auto-buildable.t | 221 +++++++++++++++++
t/buildsystems/04-dh_auto_do_autoconf.t | 93 ++++++++
t/buildsystems/05-load-build-system.t | 60 +++++
t/buildsystems/06-buildsystem-mkdir-rmdir.t | 56 +++++
t/buildsystems/buildsystem_tests.t | 352 +---------------------------
t/buildsystems/load-bs.pl | 21 ++
8 files changed, 513 insertions(+), 349 deletions(-)
diff --git a/t/Test/DH.pm b/t/Test/DH.pm
index 7b6bdd4..080a669 100644
--- a/t/Test/DH.pm
+++ b/t/Test/DH.pm
@@ -36,7 +36,7 @@ use Debian::Debhelper::Dh_Lib;
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
+ uid_0_test_is_ok create_empty_file readlines
);
our ($TEST_DH_COMPAT, $ROOT_OK, $ROOT_CMD);
@@ -189,4 +189,12 @@ sub create_empty_file {
return 1;
}
+sub readlines {
+ my ($h) = @_;
+ my @lines = <$h>;
+ close $h;
+ chop @lines;
+ return \@lines;
+}
+
1;
diff --git a/t/buildsystems/01-build-system-basic-api.t b/t/buildsystems/01-build-system-basic-api.t
new file mode 100755
index 0000000..c7cb970
--- /dev/null
+++ b/t/buildsystems/01-build-system-basic-api.t
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 12;
+
+use File::Basename qw(dirname);
+use lib dirname(dirname(__FILE__));
+use Test::DH;
+use Debian::Debhelper::Dh_Lib;
+use Debian::Debhelper::Buildsystem;
+
+my $BS_CLASS = 'Debian::Debhelper::Buildsystem';
+
+
+build_system_path_apis();
+
+# Bulk tests
+sub build_system_path_apis {
+ ### 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");
+}
+
+
+# Local Variables:
+# indent-tabs-mode: t
+# tab-width: 4
+# cperl-indent-level: 4
+# End:
diff --git a/t/buildsystems/03-bs-auto-buildable.t b/t/buildsystems/03-bs-auto-buildable.t
new file mode 100755
index 0000000..f836914
--- /dev/null
+++ b/t/buildsystems/03-bs-auto-buildable.t
@@ -0,0 +1,221 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 182;
+
+use File::Temp qw(tempdir);
+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;
+use Debian::Debhelper::Dh_Buildsystems;
+
+my @STEPS = qw(configure build test install clean);
+
+### Test check_auto_buildable() of each buildsystem
+sub test_check_auto_buildable {
+ my ($bs, $config, $expected) = @_;
+
+ 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" );
+ }
+}
+
+sub test_autoselection {
+ my ($testname, $expected, %args) = @_;
+ for my $step (@STEPS) {
+ my $bs = load_buildsystem({'enable-thirdparty' => 0}, $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"};
+ }
+}
+
+my $TEMP_DIR = tempdir('tmp.XXXXXXX', CLEANUP => 1);
+my $sourcedir = "${TEMP_DIR}/source";
+my $builddir = "${TEMP_DIR}/build";
+my %options = (
+ 'builddir' => $builddir,
+ 'sourcedir' => $sourcedir,
+);
+make_path($sourcedir, $builddir);
+my @bs = load_all_buildsystems([ $Test::DH::ROOT_DIR ], %options);
+my %bs;
+my @names = map { $_->NAME() } @bs;
+
+ok(@Debian::Debhelper::Dh_Buildsystems::BUILDSYSTEMS >= 1, "some build systems are built in" );
+is_deeply( \@names, \@Debian::Debhelper::Dh_Buildsystems::BUILDSYSTEMS, "load_all_buildsystems() loads all built-in buildsystems" );
+
+# check_auto_buildable() fails with numeric 0
+for my $bs (@bs) {
+ test_check_auto_buildable($bs, "fails with numeric 0", 0);
+ $bs{$bs->NAME()} = $bs;
+}
+
+run_auto_buildable_tests();
+
+remove_tree($sourcedir, $builddir);
+make_path($sourcedir, $builddir);
+
+run_autoselection_tests();
+
+
+#### Bulk of test code ####
+
+sub run_auto_buildable_tests {
+ create_empty_file("${sourcedir}/configure", 0755);
+ test_check_auto_buildable($bs{autoconf}, "configure", { configure => 1, clean => 1 });
+ rm_files("${sourcedir}/configure");
+
+ create_empty_file("${sourcedir}/CMakeLists.txt");
+ test_check_auto_buildable($bs{cmake}, "CMakeLists.txt", { configure => 1, clean => 1 });
+ rm_files("${sourcedir}/CMakeLists.txt");
+
+ create_empty_file("${sourcedir}/Makefile.PL");
+ test_check_auto_buildable($bs{perl_makemaker}, "Makefile.PL", { configure => 1 });
+ rm_files("${sourcedir}/Makefile.PL");
+
+ create_empty_file("${sourcedir}/meson.build");
+ test_check_auto_buildable($bs{meson}, "meson.build", { configure => 1, clean => 1 });
+ # Leave meson.build
+
+ create_empty_file("${builddir}/build.ninja");
+ test_check_auto_buildable($bs{ninja}, "build.ninja", { configure => 1, build => 1, clean => 1, install => 1, test => 1 });
+ # 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 });
+ rm_files("${sourcedir}/meson.build", "${builddir}/build.ninja");
+
+ # With Makefile
+ create_empty_file("$builddir/Makefile");
+ test_check_auto_buildable($bs{makefile}, "Makefile", 1);
+
+ # ... +autoconf
+ create_empty_file("${sourcedir}/configure", 0755);
+ test_check_auto_buildable($bs{autoconf}, "configure+Makefile", { configure => 1, test => 1, build => 1, install => 1, clean => 1 });
+ rm_files("${sourcedir}/configure");
+
+ # ... +cmake
+ create_empty_file("${sourcedir}/CMakeLists.txt");
+ test_check_auto_buildable($bs{cmake}, "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);
+ rm_files("${builddir}/Makefile", "${sourcedir}/CMakeLists.txt");
+
+ # Makefile.PL forces in-source
+ #(see note in check_auto_buildable() why always 1 here)
+ create_empty_file("${sourcedir}/Makefile.PL");
+ create_empty_file("${sourcedir}/Makefile");
+ test_check_auto_buildable($bs{perl_makemaker}, "Makefile.PL+Makefile", 1);
+ rm_files("${sourcedir}/Makefile.PL", "${sourcedir}/Makefile");
+
+ # Perl Build.PL - handles always
+ test_check_auto_buildable($bs{perl_build}, "no Build.PL", 0);
+ create_empty_file("${sourcedir}/Build.PL");
+ test_check_auto_buildable($bs{perl_build}, "Build.PL", { configure => 1 });
+ create_empty_file("${sourcedir}/Build"); # forced in source
+ test_check_auto_buildable($bs{perl_build}, "Build.PL+Build", 1);
+ rm_files("${sourcedir}/Build.PL", "${sourcedir}/Build");
+
+ # Python Distutils
+ test_check_auto_buildable($bs{python_distutils}, "no setup.py", 0);
+ create_empty_file("${sourcedir}/setup.py");
+ test_check_auto_buildable($bs{python_distutils}, "setup.py", 1);
+ rm_files("${sourcedir}/setup.py");
+}
+
+sub run_autoselection_tests {
+ # Auto-select nothing when no supported build system can be found
+ # (see #557006).
+ test_autoselection("auto-selects nothing", undef, %options);
+
+ # Autoconf
+ create_empty_file("${sourcedir}/configure", 0755);
+ create_empty_file("${builddir}/Makefile");
+ test_autoselection("autoconf",
+ { configure => "autoconf", build => "autoconf",
+ test => "autoconf", install => "autoconf",
+ clean => "autoconf"
+ }, %options);
+ rm_files("${sourcedir}/configure", "${builddir}/Makefile");
+
+
+ # Perl Makemaker (build, test, clean fail with builddir set [not supported])
+ create_empty_file("${sourcedir}/Makefile.PL");
+ create_empty_file("${sourcedir}/Makefile");
+ test_autoselection("perl_makemaker", "perl_makemaker", %options);
+ rm_files("${sourcedir}/Makefile.PL", "${sourcedir}/Makefile");
+
+
+ # Makefile
+ create_empty_file("$builddir/Makefile");
+ test_autoselection("makefile", "makefile", %options);
+ rm_files("$builddir/Makefile");
+
+ # Python Distutils
+ create_empty_file("${sourcedir}/setup.py");
+ test_autoselection("python_distutils", "python_distutils", %options);
+ rm_files("${sourcedir}/setup.py");
+
+ # Perl Build
+ create_empty_file("${sourcedir}/Build.PL");
+ create_empty_file("${sourcedir}/Build");
+ test_autoselection("perl_build", "perl_build", %options);
+ rm_files("${sourcedir}/Build.PL", "${sourcedir}/Build");
+
+ # CMake
+ create_empty_file("${sourcedir}/CMakeLists.txt");
+ test_autoselection("cmake without CMakeCache.txt",
+ { configure => "cmake", build => "makefile",
+ test => "makefile", install => "makefile",
+ clean => "makefile"
+ },
+ %options,
+ code_configure => sub {
+ create_empty_file("$builddir/Makefile");
+ });
+ rm_files("${sourcedir}/CMakeLists.txt", "$builddir/Makefile");
+
+ create_empty_file("${sourcedir}/CMakeLists.txt");
+ test_autoselection("cmake with CMakeCache.txt",
+ "cmake",
+ %options,
+ code_configure => sub {
+ create_empty_file("$builddir/Makefile");
+ create_empty_file("$builddir/CMakeCache.txt");
+ });
+ rm_files("${sourcedir}/CMakeLists.txt", "$builddir/Makefile", "$builddir/CMakeCache.txt");
+
+ create_empty_file("${sourcedir}/CMakeLists.txt");
+ create_empty_file("$builddir/Makefile");
+ test_autoselection("cmake and existing Makefile", "makefile", %options);
+ rm_files("${sourcedir}/CMakeLists.txt", "$builddir/Makefile");
+
+};
+
+# Local Variables:
+# indent-tabs-mode: t
+# tab-width: 4
+# cperl-indent-level: 4
+# End:
diff --git a/t/buildsystems/04-dh_auto_do_autoconf.t b/t/buildsystems/04-dh_auto_do_autoconf.t
new file mode 100755
index 0000000..aecf871
--- /dev/null
+++ b/t/buildsystems/04-dh_auto_do_autoconf.t
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 31;
+
+use File::Temp qw(tempdir);
+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;
+use Debian::Debhelper::Dh_Buildsystems;
+
+# 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);
+
+$Test::DH::TEST_DH_COMPAT = 10;
+
+# Build the autoconf test package
+sub dh_auto_do_autoconf {
+ my ($sourcedir, $builddir, %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) = @_;
+ my @extra_args;
+ my $extra_str = "";
+ if (exists $args{"${step}_args"}) {
+ push @extra_args, @{$args{"${step}_args"}};
+ $extra_str .= " $_" foreach (@extra_args);
+ }
+ ok(run_dh_tool({ 'quiet' => 1 }, "dh_auto_${step}", @dh_auto_args, '--', @extra_args),
+ "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)};
+ close(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');
+ @lines=();
+ if ( ok(open(FILE, '<', "$buildpath/stamp_test"), "$buildpath/stamp_test exists") ) {
+ @lines = @{readlines(\*FILE)};
+ close(FILE);
+ }
+ is_deeply( \@lines, [ "VERBOSE=1" ],
+ "$buildpath/stamp_test contains VERBOSE=1" );
+ &$do_dh_auto('install');
+ @lines=();
+ if ( ok(open(FILE, '<', "$buildpath/stamp_install"), "$buildpath/stamp_install exists") ) {
+ @lines = @{readlines(\*FILE)};
+ close(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" );
+
+# Local Variables:
+# indent-tabs-mode: t
+# tab-width: 4
+# cperl-indent-level: 4
+# End:
diff --git a/t/buildsystems/05-load-build-system.t b/t/buildsystems/05-load-build-system.t
new file mode 100755
index 0000000..920fbeb
--- /dev/null
+++ b/t/buildsystems/05-load-build-system.t
@@ -0,0 +1,60 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Cwd;
+use Test::More tests => 3;
+
+use File::Temp qw(tempdir);
+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;
+use Debian::Debhelper::Buildsystem;
+
+my $DIR = dirname($0);
+my $SCRIPT = './load-bs.pl'; # relative to $DIR
+my $BS_CWD = Cwd::cwd() . "/${DIR}";
+my $BS_CLASS = 'Debian::Debhelper::Buildsystem';
+my $bs = $BS_CLASS->new();
+my $default_builddir = $bs->DEFAULT_BUILD_DIRECTORY();
+delete($ENV{'TEST_DH_SYSTEM'});
+delete($ENV{'TEST_DH_STEP'});
+
+# NOTE: disabling parallel building explicitly (it might get automatically
+# enabled if run under dpkg-buildpackage -jX) to make output deterministic.
+is_deeply( try_load_bs(undef, 'configure', '--builddirectory=autoconf/bld dir', '--sourcedirectory',
+ 'autoconf', '--max-parallel=1'),
+ [ 'NAME=autoconf', 'builddir=autoconf/bld dir', "cwd=$BS_CWD", 'makecmd=make', 'parallel=1', 'sourcedir=autoconf' ],
+ "autoconf autoselection and sourcedir/builddir" );
+
+is_deeply( try_load_bs('autoconf', 'build', '-Sautoconf', '-D', 'autoconf', '--max-parallel=1'),
+ [ 'NAME=autoconf', 'builddir=undef', "cwd=$BS_CWD", 'makecmd=make', 'parallel=1', 'sourcedir=autoconf' ],
+ "forced autoconf and sourcedir" );
+
+is_deeply( try_load_bs('autoconf', 'build', '-B', '-Sautoconf', '--max-parallel=1'),
+ [ 'NAME=autoconf', "builddir=$default_builddir", "cwd=$BS_CWD", 'makecmd=make', 'parallel=1', 'sourcedir=.' ],
+ "forced autoconf and default build directory" );
+
+sub try_load_bs {
+ my ($system, $step, @params) = @_;
+ my @lines;
+ my $pid = open(my $fd, '-|') // die("fork: $!");
+
+ if (not $pid) {
+ chdir($DIR) or die("chdir($DIR): $!");
+ $ENV{'TEST_DH_SYSTEM'} = $system if defined($system);
+ $ENV{'TEST_DH_STEP'} = $step if defined($step);
+ exec($^X, $SCRIPT, @params);
+ }
+ @lines = map { chomp; $_ } <$fd>;
+ close($fd); # Ignore error
+ return \@lines;
+}
+
+# Local Variables:
+# indent-tabs-mode: t
+# tab-width: 4
+# cperl-indent-level: 4
+# End:
diff --git a/t/buildsystems/06-buildsystem-mkdir-rmdir.t b/t/buildsystems/06-buildsystem-mkdir-rmdir.t
new file mode 100755
index 0000000..8dc36f7
--- /dev/null
+++ b/t/buildsystems/06-buildsystem-mkdir-rmdir.t
@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Cwd;
+use Test::More tests => 6;
+
+use File::Temp qw(tempdir);
+use File::Basename qw(dirname);
+use lib dirname(dirname(__FILE__));
+use File::Path qw(make_path);
+use Test::DH;
+use Debian::Debhelper::Dh_Lib qw(!dirname);
+use Debian::Debhelper::Buildsystem;
+
+chdir(dirname($0)) or die("chdir: $!");
+my $TEMP_DIR = tempdir('tmp.XXXXXXX', CLEANUP => 1);
+my $sourcedir = $TEMP_DIR;
+my $builddir = "${TEMP_DIR}/build";
+my $BS_CLASS = 'Debian::Debhelper::Buildsystem';
+
+# Tests
+
+do_rmdir_builddir($sourcedir, $builddir);
+ok ( ! -e $builddir, "testing rmdir_builddir() 1: builddir parent '$builddir' deleted" );
+ok ( -d $sourcedir, "testing rmdir_builddir() 1: sourcedir '$sourcedir' remains" );
+
+$builddir = "$sourcedir/bld";
+do_rmdir_builddir($sourcedir, "$builddir/dir");
+ok ( ! -e $builddir, "testing rmdir_builddir() 2: builddir parent '$builddir' deleted" );
+ok ( -d $sourcedir, "testing rmdir_builddir() 2: sourcedir '$sourcedir' remains" );
+
+$builddir = "$sourcedir/bld";
+
+make_path($builddir, "$builddir/dir");
+create_empty_file("$builddir/afile");
+create_empty_file("$builddir/dir/afile2");
+do_rmdir_builddir($sourcedir, "$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" );
+
+
+### Test Buildsystem::rmdir_builddir()
+sub do_rmdir_builddir {
+ my ($sourcedir, $builddir) = @_;
+ my $system;
+ $system = $BS_CLASS->new(builddir => $builddir, sourcedir => $sourcedir);
+ $system->mkdir_builddir();
+ $system->rmdir_builddir();
+}
+
+# Local Variables:
+# indent-tabs-mode: t
+# tab-width: 4
+# cperl-indent-level: 4
+# End:
diff --git a/t/buildsystems/buildsystem_tests.t b/t/buildsystems/buildsystem_tests.t
index 111839d..aae8087 100755
--- a/t/buildsystems/buildsystem_tests.t
+++ b/t/buildsystems/buildsystem_tests.t
@@ -1,12 +1,12 @@
#!/usr/bin/perl
-use Test::More tests => 316;
+use Test::More tests => 82;
use strict;
use warnings;
use IPC::Open2;
use Cwd ();
-use File::Temp qw(tempfile tempdir);
+use File::Temp qw(tempfile);
use File::Basename ();
# Let the tests to be run from anywhere but currect directory
@@ -21,22 +21,11 @@ my $TOPDIR = "../..";
my @STEPS = qw(configure build test install clean);
my $BS_CLASS = 'Debian::Debhelper::Buildsystem';
-my ($bs, @bs, %bs);
+my ($bs);
my ($tmp, @tmp, %tmp);
-my ($tmpdir, $builddir, $default_builddir);
+my ($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>;
@@ -75,29 +64,6 @@ sub write_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)=@_;
@@ -204,315 +170,6 @@ $bs = $BS_CLASS->new(builddir => "bld/dir/", sourcedir => "autoconf");
);
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
- at bs = load_all_buildsystems([ $INC[0] ], %tmp);
- at 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, clean => 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 });
-
-touch "$tmpdir/meson.build";
-test_check_auto_buildable($bs{meson}, "meson.build", { configure => 1, clean => 1 });
-
-touch "$tmpdir/builddir/build.ninja";
-test_check_auto_buildable($bs{ninja}, "build.ninja", { configure => 1, build => 1, clean => 1, install => 1, test => 1 });
-
-# Meson + ninja
-test_check_auto_buildable($bs{meson}, "meson.build+build.ninja", { configure => 1, build => 1, clean => 1, install => 1, test => 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 => 1, build => 1, install => 1, clean => 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({'enable-thirdparty' => 0}, $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 => "autoconf",
- test => "autoconf", install => "autoconf", clean => "autoconf" }, %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)};
- close(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');
- @lines=();
- if ( ok(open(FILE, '<', "$buildpath/stamp_test"), "$buildpath/stamp_test exists") ) {
- @lines = @{readlines(\*FILE)};
- close(FILE);
- }
- is_deeply( \@lines, [ "VERBOSE=1" ],
- "$buildpath/stamp_test contains VERBOSE=1" );
- &$do_dh_auto('install');
- @lines=();
- if ( ok(open(FILE, '<', "$buildpath/stamp_install"), "$buildpath/stamp_install exists") ) {
- @lines = @{readlines(\*FILE)};
- close(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} );
@@ -621,6 +278,5 @@ $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/load-bs.pl b/t/buildsystems/load-bs.pl
new file mode 100755
index 0000000..d8f56c2
--- /dev/null
+++ b/t/buildsystems/load-bs.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Debian::Debhelper::Dh_Buildsystems;
+
+buildsystems_init();
+my $system = $ENV{'TEST_DH_SYSTEM'};
+my $step = $ENV{'TEST_DH_STEP'};
+my $bs = load_buildsystem($system, $step);
+if (defined $bs) {
+ print 'NAME=', $bs->NAME(), "\n";
+ print $_, "=", (defined $bs->{$_}) ? $bs->{$_} : 'undef', "\n"
+ foreach (sort keys %$bs);
+}
+
+# Local Variables:
+# indent-tabs-mode: t
+# tab-width: 4
+# cperl-indent-level: 4
+# End:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git
More information about the debhelper-devel
mailing list