]> git.donarmstrong.com Git - debhelper.git/blobdiff - t/buildsystems/buildsystem_tests
More verbose rmdir_builddir() and more its tests
[debhelper.git] / t / buildsystems / buildsystem_tests
index a2b451a96699f77a7079c1100da94bc0df053235..7e9b4bf173c2f8228ad2a2895cb21afcf6e3a6f4 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-use Test::More tests => 224;
+use Test::More tests => 236;
 
 use strict;
 use warnings;
@@ -57,18 +57,27 @@ sub process_stdout {
 }
 
 ### 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->_rel2rel("path/my/file", "path/my"),
+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"),
+is( $BS_CLASS->_rel2rel("path/dir/file", "path/my", "/tmp"),
     "../dir/file", "_rel2rel no2" );
 is( $BS_CLASS->_rel2rel("file", "/root/path/my", "/root"),
-    "../../file", "_rel2rel no3" );
+    "/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 {
@@ -126,24 +135,24 @@ $bs = $BS_CLASS->new(builddir => undef, sourcedir => "autoconf");
 %tmp = (
        "get_sourcedir()" => "autoconf",
        "get_sourcepath(a/b)" => "autoconf/a/b",
-       "get_builddir()" => "autoconf/$default_builddir",
-       "get_buildpath()" => "autoconf/$default_builddir",
-       "get_buildpath(a/b)" =>  "autoconf/$default_builddir/a/b",
-       "get_source_rel2builddir()" => "..",
-       "get_source_rel2builddir(a/b)" => "../a/b",
-       "get_build_rel2sourcedir()" => "$default_builddir",
-       "get_build_rel2sourcedir(a/b)" => "$default_builddir/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);
 
-# Enforced out of source tree building
+# Enforce out of source tree building
 # sourcedir=builddir=autoconf hence default builddir is implied
-$bs = $BS_CLASS->new(builddir => "./autoconf", sourcedir => "autoconf/");
+$bs = $BS_CLASS->new(builddir => "autoconf", sourcedir => "autoconf/");
 $bs->enforce_out_of_source_building();
-test_buildsystem_paths_api($bs, "out of source enforced, sourcedir=autoconf/", \%tmp);
+test_buildsystem_paths_api($bs, "hard out of source enforced, sourcedir=builddir", \%tmp);
 
 # sourcedir=autoconf (builddir should be dropped)
-$bs = $BS_CLASS->new(builddir => ".", sourcedir => "autoconf");
+$bs = $BS_CLASS->new(builddir => "autoconf", sourcedir => "autoconf");
 %tmp = (
        "get_sourcedir()" => "autoconf",
        "get_sourcepath(a/b)" => "autoconf/a/b",
@@ -157,13 +166,18 @@ $bs = $BS_CLASS->new(builddir => ".", sourcedir => "autoconf");
 );
 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 sourcedir)
-$bs = $BS_CLASS->new(builddir => "../bld/dir/", sourcedir => "autoconf");
+# 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",
@@ -177,10 +191,6 @@ $bs = $BS_CLASS->new(builddir => "../bld/dir/", sourcedir => "autoconf");
 );
 test_buildsystem_paths_api($bs, "builddir=../bld/dir, sourcedir=autoconf", \%tmp);
 
-# Builddir relative to the pwd (same path as above).
-$bs = $BS_CLASS->new(builddir => "./bld/dir", sourcedir => "autoconf");
-test_buildsystem_paths_api($bs, "builddir=./bld/dir, sourcedir=autoconf", \%tmp);
-
 ### Test if all buildsystems can be loaded
 @bs = load_all_buildsystems([ $INC[0] ]);
 @tmp = map { $_->NAME() } @bs;
@@ -220,7 +230,7 @@ $tmpdir = tempdir("tmp.XXXXXX");
 $builddir = "$tmpdir/builddir";
 mkdir $builddir;
 %tmp = (
-       builddir => 'builddir',
+       builddir => "$tmpdir/builddir",
        sourcedir => $tmpdir
 );
 
@@ -328,6 +338,36 @@ test_autoselection("cmake",
       test => "makefile", install => "makefile", clean => "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)=@_;
@@ -349,17 +389,18 @@ if (defined \$bs) {
 EOF
 }
 
-is_deeply( process_stdout("DH_AUTO_OPTIONS='--builddirectory=bld\\ dir --sourcedirectory autoconf' $^X -- -",
+$tmp = Cwd::getcwd();
+is_deeply( process_stdout("$^X -- - --builddirectory='autoconf/bld dir' --sourcedirectory autoconf",
                           get_load_bs_source(undef, "configure")),
-    [ 'NAME=autoconf', 'builddir=autoconf/bld dir', 'makecmd=make', 'sourcedir=autoconf' ],
-    "dh_auto_options w/space, autoconf autoselection and sourcedir/builddir" );
+    [ 'NAME=autoconf', 'builddir=autoconf/bld dir', "cwd=$tmp",  'makecmd=make', 'sourcedir=autoconf' ],
+    "autoconf autoselection and sourcedir/builddir" );
 
-is_deeply( process_stdout("$^X -- - -cautoconf -d autoconf", get_load_bs_source("autoconf", "build")),
-    [ 'NAME=autoconf', 'builddir=undef', 'makecmd=make', 'sourcedir=autoconf' ],
+is_deeply( process_stdout("$^X -- - -Sautoconf -D autoconf", get_load_bs_source("autoconf", "build")),
+    [ 'NAME=autoconf', 'builddir=undef', "cwd=$tmp", 'makecmd=make', 'sourcedir=autoconf' ],
     "forced autoconf and sourcedir" );
 
-is_deeply( process_stdout("$^X -- - -b -cautoconf", get_load_bs_source("autoconf", "build")),
-    [ 'NAME=autoconf', "builddir=$default_builddir", 'makecmd=make', 'sourcedir=.' ],
+is_deeply( process_stdout("$^X -- - -B -Sautoconf", get_load_bs_source("autoconf", "build")),
+    [ 'NAME=autoconf', "builddir=$default_builddir", "cwd=$tmp", 'makecmd=make', 'sourcedir=.' ],
     "forced autoconf and default build directory" );
 
 # Build the autoconf test package
@@ -370,12 +411,12 @@ sub dh_auto_do_autoconf {
 
        my (@lines, @extra_args);
        my $buildpath = $sourcedir;
-       my @dh_auto_args = ("-d", $sourcedir);
-       my $dh_auto_str = "-d $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";
+               push @dh_auto_args, "-B", $builddir;
+               $dh_auto_str .= " -B $builddir";
+               $buildpath = $builddir;
        }
 
        my $do_dh_auto = sub {
@@ -422,7 +463,7 @@ sub dh_auto_do_autoconf {
 
 dh_auto_do_autoconf('autoconf');
 dh_auto_do_autoconf('autoconf', 'bld/dir', configure_args => [ "--extra-autoconf-configure-arg" ]);
-ok ( ! -e 'autoconf/bld', "autoconf/bld got deleted too" );
+ok ( ! -e 'bld', "bld got deleted too" );
 
 END {
        system("rm", "-rf", $tmpdir);