Author: jkeenan
Date: Sat Jul 26 16:02:27 2008
New Revision: 29778

Modified:
   branches/parallel/config/gen/config_h.pm
   branches/parallel/t/steps/gen_config_h-01.t

Log:
[configure] Refactor code from inside runstep() to _handle_define_option() to
increase testability of previously uncovered branch.  Add appropriate tests.


Modified: branches/parallel/config/gen/config_h.pm
==============================================================================
--- branches/parallel/config/gen/config_h.pm    (original)
+++ branches/parallel/config/gen/config_h.pm    Sat Jul 26 16:02:27 2008
@@ -85,22 +85,7 @@
     my $osname = $conf->data->get_p5('OSNAME');
     print {$HH} "\n#define BUILD_OS_NAME \"$osname\"\n";
 
-    my $define = $conf->options->get('define');
-
-    if ($define) {
-        my @vals = split /,/, $define;
-        print {$HH} <<EOF;
-
-/*
- * defines from commandline
- */
-
-EOF
-        for (@vals) {
-            print {$HH} "#define PARROT_DEF_" . uc($_), " 1\n";
-        }
-
-    }
+    _handle_define_option($conf, $HH);
 
     print {$HH} <<EOF;
 
@@ -150,6 +135,25 @@
     return 1;
 }
 
+sub _handle_define_option {
+    my ($conf, $HH) = @_;
+    my $define = $conf->options->get('define');
+
+    if ($define) {
+        my @vals = split /,/, $define;
+        print {$HH} <<EOF;
+
+/*
+ * defines from commandline
+ */
+
+EOF
+        for my $v (@vals) {
+            print {$HH} "#define PARROT_DEF_" . uc($v), " 1\n";
+        }
+    }
+}
+
 1;
 
 # Local Variables:

Modified: branches/parallel/t/steps/gen_config_h-01.t
==============================================================================
--- branches/parallel/t/steps/gen_config_h-01.t (original)
+++ branches/parallel/t/steps/gen_config_h-01.t Sat Jul 26 16:02:27 2008
@@ -5,16 +5,20 @@
 
 use strict;
 use warnings;
-use Test::More tests =>  7;
+use Test::More tests => 11;
 use Carp;
+use Cwd;
+use File::Temp qw( tempdir );
 use lib qw( lib );
 use_ok('config::gen::config_h');
 use Parrot::Configure;
 use Parrot::Configure::Options qw( process_options );
 use Parrot::Configure::Test qw(
     test_step_thru_runstep
+    rerun_defaults_for_testing
     test_step_constructor_and_description
 );
+use Parrot::Configure::Utils qw( _slurp );
 
 my $args = process_options(
     {
@@ -24,6 +28,9 @@
 );
 
 my $conf = Parrot::Configure->new;
+
+my $serialized = $conf->pcfreeze();
+
 my $pkg = q{gen::config_h};
 $conf->add_steps($pkg);
 $conf->options->set( %{$args} );
@@ -31,6 +38,31 @@
 ok(-f $step->{templates}->{config_h}, "Template for config_h located");
 ok(-f $step->{templates}->{feature_h}, "Template for feature_h located");
 
+$conf->replenish($serialized);
+
+$args = process_options( {
+    argv => [ q{--define=inet_aton} ],
+    mode => q{configure},
+} );
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+$step = test_step_constructor_and_description($conf);
+
+my $cwd = cwd();
+{
+    my $tdir = tempdir( CLEANUP => 1 );
+    chdir $tdir or croak "Unable to change to temporary directory";
+    my $hh = "has_header.h";
+    open( my $HH, ">", "$hh.tmp" )
+        or die "Can't open has_header.h: $!";
+    gen::config_h::_handle_define_option( $conf, $HH );
+    close $HH or die "Can't close temp file: $!";
+    my $text = _slurp("$hh.tmp");
+    like($text, qr/#define PARROT_DEF_INET_ATON 1/s,
+        "Got expected define");
+    chdir $cwd or croak "Unable to change back to starting directory";
+}
+
 pass("Completed all tests in $0");
 
 ################### DOCUMENTATION ###################

Reply via email to