Author: jkeenan
Date: Thu Jan 10 16:57:46 2008
New Revision: 24737

Modified:
   trunk/config/auto/readline.pm
   trunk/t/configure/144-auto_readline-01.t
   trunk/t/configure/144-auto_readline-02.t

Log:
auto::readline:  Some refactoring to enable testing of macports-related code.
More tests added to 144-auto_readline-01.t to handle that.


Modified: trunk/config/auto/readline.pm
==============================================================================
--- trunk/config/auto/readline.pm       (original)
+++ trunk/config/auto/readline.pm       Thu Jan 10 16:57:46 2008
@@ -19,6 +19,7 @@
 
 use strict;
 use warnings;
+use File::Spec;
 
 use base qw(Parrot::Configure::Step);
 
@@ -30,6 +31,7 @@
     $data{description} = q{Determining if your platform supports readline};
     $data{args}        = [ qw( verbose ) ];
     $data{result}      = q{};
+    $data{macports_root} = File::Spec->catdir( '/', 'opt', 'local' );
     return \%data;
 }
 
@@ -55,7 +57,7 @@
     # 'auto::macports' config step and do not yet have enough basis to extract
     # this code into a Parrot::Configure::Step::Methods method analogous to
     # _handle_darwin_for_fink().
-    _handle_darwin_for_macports($conf, $osname);
+    $self->_handle_darwin_for_macports($conf, $osname, q{readline/readline.h});
 
     $conf->cc_gen('config/auto/readline/readline.in');
     my $has_readline = 0;
@@ -92,12 +94,16 @@
 }
 
 sub _handle_darwin_for_macports {
-    my ($conf, $osname) = @_;
+    my $self = shift;
+    my ($conf, $osname, $file) = @_;
     if ( $osname =~ /darwin/ ) {
-        if ( -f "/opt/local/include/readline/readline.h" ) {
-            $conf->data->add( ' ', linkflags => '-L/opt/local/lib' );
-            $conf->data->add( ' ', ldflags   => '-L/opt/local/lib' );
-            $conf->data->add( ' ', ccflags   => '-I/opt/local/include' );
+        my $macports_root = $self->{macports_root};
+        my $macports_lib_dir = qq{$macports_root/lib};
+        my $macports_include_dir = qq{$macports_root/include};
+        if ( -f qq{$macports_include_dir/$file} ) {
+            $conf->data->add( ' ', linkflags => "-L$macports_lib_dir" );
+            $conf->data->add( ' ', ldflags   => "-L$macports_lib_dir" );
+            $conf->data->add( ' ', ccflags   => "-I$macports_include_dir" );
         }
     }
     return 1;

Modified: trunk/t/configure/144-auto_readline-01.t
==============================================================================
--- trunk/t/configure/144-auto_readline-01.t    (original)
+++ trunk/t/configure/144-auto_readline-01.t    Thu Jan 10 16:57:46 2008
@@ -5,7 +5,7 @@
 
 use strict;
 use warnings;
-use Test::More tests => 35;
+use Test::More qw(no_plan); # tests => 40;
 use Carp;
 use Cwd;
 use File::Spec;
@@ -123,16 +123,35 @@
 
 $osname = 'foobar';
 $flagsbefore = $conf->data->get( 'linkflags' );
-ok(auto::readline::_handle_darwin_for_macports($conf, $osname, 
'readline/readline.h'),
+ok($step->_handle_darwin_for_macports($conf, $osname, 'readline/readline.h'),
     "handle_darwin_for_macports() returned true value");
 $flagsafter = $conf->data->get( 'linkflags' );
 is($flagsbefore, $flagsafter, "No change in linkflags, as expected");
+# Get ready for the next test
+$conf->data->set( 'linkflags' => undef );
 
-$osname = 'darwin';
-ok(auto::readline::_handle_darwin_for_macports($conf, $osname, 
'readline/readline.h'),
-    "handle_darwin_for_macports() returned true value");
-# Cannot yet do more specific tests for macports, because path to
-# readline/readline.h in sub is an absolute path.
+$cwd = cwd();
+{
+    my $tdir3 = tempdir( CLEANUP => 1 );
+    ok(chdir $tdir3, "Able to change to temporary directory");
+    $step->{macports_root} = $tdir3;
+    ok( (mkdir 'lib'), "Able to make lib directory");
+    ok( (mkdir 'include'), "Able to make include directory");
+    ok( (mkdir 'include/readline'), "Able to make include/readline directory");
+    my $libdir = File::Spec->catdir( $tdir3, 'lib' );
+    my $includedir = File::Spec->catdir( $tdir3, 'include' );
+    my $file = qq{$includedir/readline/readline.h};
+    open my $FH, ">", $file or croak "Unable to open $file for writing";
+    print $FH qq{Hello Darwin\n};
+    close $FH or croak "Unable to close $file after writing";
+    $osname = 'darwin';
+    ok($step->_handle_darwin_for_macports(
+        $conf, $osname, 'readline/readline.h'),
+        "handle_darwin_for_macports() returned true value");
+    like($conf->data->get( 'linkflags' ), qr/-L\Q$libdir\E/,
+        "Linkflags modified as expected" );
+    chdir $cwd or croak "Unable to change back to original directory";
+}
 
 pass("Completed all tests in $0");
 

Modified: trunk/t/configure/144-auto_readline-02.t
==============================================================================
--- trunk/t/configure/144-auto_readline-02.t    (original)
+++ trunk/t/configure/144-auto_readline-02.t    Thu Jan 10 16:57:46 2008
@@ -17,14 +17,6 @@
 use Parrot::Configure::Test qw( test_step_thru_runstep);
 use IO::CaptureOutput qw| capture |;
 
-=for hints_for_testing The documentation for this package is skimpy;
-please try to improve it, e.g., by providing a short description of what
-the 'readline' function is.  Some branches are compiler- or OS-specific.
-As noted in a comment in the module, please consider the issues raised
-in http://rt.perl.org/rt3/Ticket/Display.html?id=43134.
-
-=cut
-
 my $args = process_options(
     {
         argv => [ ],

Reply via email to