Bläddra i källkod

Dpkg::BuildOptions: Add tests and fix errors found

This whole module was one giant brown paper bag bug...
Frank Lichtenheld 19 år sedan
förälder
incheckning
76209ff4c9
3 ändrade filer med 48 tillägg och 3 borttagningar
  1. 3 1
      ChangeLog
  2. 4 2
      scripts/Dpkg/BuildOptions.pm
  3. 41 0
      scripts/t/300_Dpkg_BuildOptions.t

+ 3 - 1
ChangeLog

@@ -1,7 +1,9 @@
 2007-10-12  Frank Lichtenheld  <djpig@debian.org>
 
+	* scripts/t/300_Dpkg_BuildOptions.t: New file.
+	Leads to the following fixes:
 	* scripts/Dpkg/BuildOptions.pm (parse): Add
-	support for nocheck.
+	support for nocheck and make it actually work.
 	(set): Really set DEB_BUILD_OPTIONS. Discovered
 	by Daniel Shepler.
 

+ 4 - 2
scripts/Dpkg/BuildOptions.pm

@@ -11,9 +11,10 @@ sub parse {
     unless ($env) { return {}; }
 
     my %opts;
-    if ($env =~ s/(noopt|nostrip|nocheck),?//ig) {
+    while ($env =~ s/(noopt|nostrip|nocheck),?//i) {
 	$opts{lc $1} = '';
-    } elsif ($env =~ s/(parallel)=(-?\d+),?//ig) {
+    }
+    while ($env =~ s/(parallel)=(-?\d+),?//i) {
 	$opts{lc $1} = $2;
     }
 
@@ -35,6 +36,7 @@ sub set {
     }
 
     $ENV{DEB_BUILD_OPTIONS} = $env if $env;
+    return $env;
 }
 
 1;

+ 41 - 0
scripts/t/300_Dpkg_BuildOptions.t

@@ -0,0 +1,41 @@
+# -*- mode: cperl;-*-
+
+use Test::More tests => 6;
+
+use strict;
+use warnings;
+
+use_ok('Dpkg::BuildOptions');
+
+$ENV{DEB_BUILD_OPTIONS} = 'foonostripbar,parallel=3,bazNOCHECK';
+
+my $dbo = Dpkg::BuildOptions::parse();
+
+my %dbo = (
+	   nostrip => '',
+	   nocheck => '',
+	   parallel => 3,
+	   );
+my %dbo2 = (
+	    nocheck => '',
+	   );
+
+
+is_deeply($dbo, \%dbo, 'parse');
+
+$dbo = Dpkg::BuildOptions::parse('no opt,no-strip,parallel = 5,nocheck');
+
+is_deeply($dbo, \%dbo2, 'parse (param)');
+
+$dbo->{parallel} = 5;
+$dbo->{noopt} = '';
+
+my $env = Dpkg::BuildOptions::set($dbo,1);
+
+is($ENV{DEB_BUILD_OPTIONS}, $env, 'set (return value)');
+is_deeply(Dpkg::BuildOptions::parse(), $dbo, 'set (env)');
+
+$ENV{DEB_BUILD_OPTIONS} = 'foobar';
+$dbo = { noopt => '' };
+$env = Dpkg::BuildOptions::set($dbo);
+is($env, "foobar,noopt,", 'set (append)');