[svn:parrot] r40017 - in branches/darwin2hints: config/init/hints t/steps/init/hints

jkeenan at svn.parrot.org jkeenan at svn.parrot.org
Sun Jul 12 14:07:30 UTC 2009


Author: jkeenan
Date: Sun Jul 12 14:07:28 2009
New Revision: 40017
URL: https://trac.parrot.org/parrot/changeset/40017

Log:
Refactor some code into internal sub _add_to_flags(), then write tests for it.  This handles some more edge cases.

Modified:
   branches/darwin2hints/config/init/hints/darwin.pm
   branches/darwin2hints/t/steps/init/hints/darwin-01.t

Modified: branches/darwin2hints/config/init/hints/darwin.pm
==============================================================================
--- branches/darwin2hints/config/init/hints/darwin.pm	Sun Jul 12 13:56:58 2009	(r40016)
+++ branches/darwin2hints/config/init/hints/darwin.pm	Sun Jul 12 14:07:28 2009	(r40017)
@@ -242,24 +242,30 @@
         if ($library eq 'macports') {
             $addl_flags_ref = _probe_for_macports($conf);
         }
-        if (defined $addl_flags_ref) {
-            foreach my $addl (keys %{ $addl_flags_ref } ) {
-                if (defined $flagsref->{$addl}) {
-                    my @elements = split /\s+/, $flagsref->{$addl};
-                    my %seen = map {$_, 1} @elements;
-                    $flagsref->{$addl} .= " $addl_flags_ref->{$addl}"
-                        unless $seen{$addl_flags_ref->{$addl}};
-                }
+        my $rv = _add_to_flags( $addl_flags_ref, $flagsref, $title, $verbose );
+        return $rv;
+    }
+    return;
+}
+
+sub _add_to_flags {
+    my ( $addl_flags_ref, $flagsref, $title, $verbose ) = @_;
+    if ( defined $addl_flags_ref ) {
+        foreach my $addl ( keys %{ $addl_flags_ref } ) {
+            my %seen;
+            if ( defined $flagsref->{$addl} ) {
+                my @elements = split /\s+/, $flagsref->{$addl};
+                %seen = map {$_, 1} @elements;
             }
-            print "Probe for $title successful\n" if $verbose;
-            return 1;
-        }
-        else {
-            print "Probe for $title unsuccessful\n" if $verbose;
-            return 1;
+            $flagsref->{$addl} .= " $addl_flags_ref->{$addl}"
+                unless $seen{ $addl_flags_ref->{$addl} };
         }
+        print "Probe for $title successful\n" if $verbose;
     }
-    return;
+    else {
+        print "Probe for $title unsuccessful\n" if $verbose;
+    }
+    return 1;
 }
 
 1;

Modified: branches/darwin2hints/t/steps/init/hints/darwin-01.t
==============================================================================
--- branches/darwin2hints/t/steps/init/hints/darwin-01.t	Sun Jul 12 13:56:58 2009	(r40016)
+++ branches/darwin2hints/t/steps/init/hints/darwin-01.t	Sun Jul 12 14:07:28 2009	(r40017)
@@ -9,8 +9,8 @@
 use File::Temp qw( tempdir );
 use Test::More;
 plan( skip_all => 'only needs testing on Darwin' ) unless $^O =~ /darwin/i;
-plan( tests =>  37 );
-#use Test::More qw(no_plan); # tests => 37;
+plan( tests =>  40 );
+#use Test::More qw(no_plan); # tests => 40;
 
 use lib qw( lib t/configure/testlib );
 use_ok('config::init::defaults');
@@ -322,6 +322,7 @@
 }
 
 ##### _probe_for_libraries() #####
+
 {
     $conf->options->set( 'darwin_no_fink' => 1 );
     $conf->options->set( 'verbose' => 0 );
@@ -336,6 +337,53 @@
     ), "_probe_for_libraries() returned undef as expected" );
     is_deeply( $flagsref, { %state_before },
         "No change in flags, as expected" );
+
+    $conf->options->set( 'darwin_no_fink' => 0 );
+}
+
+##### _add_to_flags() #####
+
+{
+    my ( $addl_flags_ref, $flagsref, $title, $verbose );
+    $addl_flags_ref = undef;
+    $flagsref = undef;
+    $title = 'Fink';
+    $verbose = 0;
+    ok( init::hints::darwin::_add_to_flags(
+        $addl_flags_ref, $flagsref, $title, $verbose
+    ), "_add_to_flags(): returned true value when no probes found" );
+
+    $verbose = 1;
+    {
+        my ($stdout, $stderr);
+        capture(
+            sub { init::hints::darwin::_add_to_flags(
+                $addl_flags_ref, $flagsref, $title, $verbose
+            ); },
+            \$stdout,
+            \$stderr,
+        );
+        like( $stdout, qr/Probe for $title unsuccessful/,
+            "_add_to_flags(): got expected verbose output when probe unsuccessful" );
+    }
+
+    $addl_flags_ref = {
+        ldflags   => "-Lfink_lib_dir",
+        ccflags   => "-Lfink_include_dir",
+        linkflags => "-Lfink_lib_dir",
+    };
+    my $lib_dir = $conf->data->get('build_dir') . "/blib/lib";
+    $flagsref = undef;
+    $flagsref->{ldflags} = " -L$lib_dir";
+    $flagsref->{ccflags} = " -pipe -fno-common -Wno-long-double ";
+    $flagsref->{linkflags} = undef;
+    $title = 'Fink';
+    $verbose = 0;
+    my $rv = init::hints::darwin::_add_to_flags(
+        $addl_flags_ref, $flagsref, $title, $verbose
+    );
+    is( $flagsref->{linkflags}, " $addl_flags_ref->{linkflags}",
+        "_add_to_flags():  flag added where not previously populated" );
 }
 
 pass("Completed all tests in $0");


More information about the parrot-commits mailing list