浏览代码

Dpkg::Build::Types: Allow disabling the checks in set_build_type()

This makes it possible to test the different code paths.
Guillem Jover 10 年之前
父节点
当前提交
e731c1fcca
共有 2 个文件被更改,包括 19 次插入4 次删除
  1. 7 3
      scripts/Dpkg/Build/Types.pm
  2. 12 1
      scripts/t/Dpkg_Build_Types.t

+ 7 - 3
scripts/Dpkg/Build/Types.pm

@@ -160,19 +160,23 @@ sub build_is
     return $current_type == $bits;
 }
 
-=item set_build_type($build_type, $build_option)
+=item set_build_type($build_type, $build_option, %opts)
 
 Set the current build type to $build_type, which was specified via the
 $build_option command-line option.
 
+The function will check and abort on incompatible build type assignments,
+this behavior can be disabled by using the boolean option "nocheck".
+
 =cut
 
 sub set_build_type
 {
-    my ($build_type, $build_option) = @_;
+    my ($build_type, $build_option, %opts) = @_;
 
     usageerr(g_('cannot combine %s and %s'), $current_option, $build_option)
-        if build_has_none(BUILD_DEFAULT) and $current_type != $build_type;
+        if not $opts{nocheck} and
+           build_has_none(BUILD_DEFAULT) and $current_type != $build_type;
 
     $current_type = $build_type;
     $current_option = $build_option;

+ 12 - 1
scripts/t/Dpkg_Build_Types.t

@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 12;
+use Test::More tests => 19;
 
 BEGIN {
     use_ok('Dpkg::Build::Types');
@@ -41,4 +41,15 @@ ok(!build_has_all(BUILD_SOURCE | BUILD_ARCH_DEP),
    'build source,all not has_all source,any');
 ok(!build_has_all(BUILD_FULL), 'build source,all has_all full');
 
+set_build_type(BUILD_BINARY, '--build=binary', nocheck => 1);
+ok(build_is(BUILD_BINARY), 'build binary is binary');
+ok(build_has_any(BUILD_ARCH_DEP), 'build binary has_any any');
+ok(build_has_any(BUILD_ARCH_INDEP), 'build binary has_any all');
+ok(build_has_all(BUILD_BINARY), 'build binary has_all binary');
+ok(build_has_none(BUILD_SOURCE), 'build binary has_none source');
+
+set_build_type(BUILD_FULL, '--build=full', nocheck => 1);
+ok(build_has_any(BUILD_SOURCE), 'build full has_any source');
+ok(build_has_all(BUILD_BINARY), 'build full has_all binary');
+
 1;