# New Ticket Created by  James Keenan 
# Please include the string:  [perl #53592]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=53592 >


Hmm, yet another config step class that appeared without an RT ...

In any case, here are some touch-ups to the code and some tests which  
closely follow those for other recently added configuration step  
classes.

kid51

Index: MANIFEST
===================================================================
--- MANIFEST    (revision 27261)
+++ MANIFEST    (working copy)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Apr 30 20:45:06 2008 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu May  1 02:02:56 2008 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -3494,6 +3494,9 @@
 t/steps/auto_opengl-03.t                                    []
 t/steps/auto_ops-01.t                                       []
 t/steps/auto_pack-01.t                                      []
+t/steps/auto_pcre-01.t                                      []
+t/steps/auto_pcre-02.t                                      []
+t/steps/auto_pcre-03.t                                      []
 t/steps/auto_perldoc-01.t                                   []
 t/steps/auto_perldoc-02.t                                   []
 t/steps/auto_pmc-01.t                                       []
Index: t/steps/auto_pcre-02.t
===================================================================
--- t/steps/auto_pcre-02.t      (revision 27261)
+++ t/steps/auto_pcre-02.t      (working copy)
@@ -1,11 +1,11 @@
 #! perl
 # Copyright (C) 2007-2008, The Perl Foundation.
 # $Id$
-# auto_pcre-01.t
+# auto_pcre-02.t
 
 use strict;
 use warnings;
-use Test::More tests => 13;
+use Test::More tests => 21;
 use Carp;
 use lib qw( lib );
 use_ok('config::init::defaults');
@@ -16,7 +16,7 @@
 
 my $args = process_options(
     {
-        argv => [ q{--without-pcre} ],
+        argv => [ ],
         mode => q{configure},
     }
 );
@@ -36,35 +36,108 @@
 $step = $step_name->new();
 ok( defined $step, "$step_name constructor returned defined value" );
 isa_ok( $step, $step_name );
-ok( $step->description(), "$step_name has description" );
 
-ok( $step->runstep($conf), "runstep() returned true value");
-is( $step->result(), 'no', "Got expected result" );
-is( $conf->data->get( 'has_pcre' ), 0,
-    "Got expected value for 'has_pre'");
+# Mock values for OS and C-compiler
+my ($osname, $cc, $initial_value);
 
+$osname = 'mswin32';
+$cc = 'gcc';
+$initial_value = $conf->data->get( 'libs' );
+ok($step->_add_to_libs( {
+    conf            => $conf,
+    osname          => $osname,
+    cc              => $cc,
+    win32_nongcc    => 'pcre.lib',
+    default         => '-lpcre',
+} ),
+    "_add_to_libs() returned true value");
+like($conf->data->get( 'libs' ), qr/-lpcre/,
+    "'libs' modified as expected");
+# Restore value for next test.
+$conf->data->set( 'libs' => $initial_value );
+
+$osname = 'mswin32';
+$cc = 'cc';
+$initial_value = $conf->data->get( 'libs' );
+ok($step->_add_to_libs( {
+    conf            => $conf,
+    osname          => $osname,
+    cc              => $cc,
+    win32_nongcc    => 'pcre.lib',
+    default         => '-lpcre',
+} ),
+    "_add_to_libs() returned true value");
+like($conf->data->get( 'libs' ), qr/pcre\.lib/,
+    "'libs' modified as expected");
+# Restore value for next test.
+$conf->data->set( 'libs' => $initial_value );
+
+$osname = 'foobar';
+$cc = 'gcc';
+$initial_value = $conf->data->get( 'libs' );
+ok($step->_add_to_libs( {
+    conf            => $conf,
+    osname          => $osname,
+    cc              => $cc,
+    win32_nongcc    => 'pcre.lib',
+    default         => '-lpcre',
+} ),
+    "_add_to_libs() returned true value");
+like($conf->data->get( 'libs' ), qr/-lpcre/,
+    "'libs' modified as expected");
+# Restore value for next test.
+$conf->data->set( 'libs' => $initial_value );
+
+# Mock different outcomes of _evaluate_cc_run
+my ($test, $has_pcre);
+my $verbose = $conf->options->get('verbose');
+
+$test = q{pcre foobar};
+ok(! $step->_evaluate_cc_run($test, $verbose),
+    "Got expected setting for has_pcre");
+
+$test = q{pcre 4.1};
+ok($step->_evaluate_cc_run($test, $verbose),
+    "_evaluate_cc_run returned true value as expected");
+is($step->result(), q{yes, v4.1}, "Got expected PCRE version");
+
+# Mock different outcomes of _recheck_settings()
+my ($libs, $ccflags, $linkflags);
+
+$libs = q{-lalpha};
+$ccflags = q{-Ibeta};
+$linkflags = q{-Lgamma};
+$verbose = undef;
+$step->_recheck_settings($conf, $libs, $ccflags, $linkflags, $verbose);
+like($conf->data->get('libs'), qr/$libs/,
+    "Got expected value for 'libs'");
+like($conf->data->get('ccflags'), qr/$ccflags/,
+    "Got expected value for 'ccflags'");
+like($conf->data->get('linkflags'), qr/$linkflags/,
+    "Got expected value for 'linkflags'");
+
 pass("Completed all tests in $0");
 
 ################### DOCUMENTATION ###################
 
 =head1 NAME
 
-  auto_pcre-01.t - test config::auto::pcre
+  auto_pcre-02.t - test config::auto::pcre
 
 =head1 SYNOPSIS
 
-    % prove t/steps/auto_pcre-01.t
+    % prove t/steps/auto_pcre-02.t
 
 =head1 DESCRIPTION
 
 The files in this directory test functionality used by F<Configure.pl>.
 
-The tests in this file test configuration step class auto::pcre in the case
-where C<--without-pcre> has been requested on the command line.
+The tests in this file test internal subroutines of configuration step class
+auto::pcre in the 'normal' case.
 
 =head1 AUTHOR
 
-Alberto SimÃes.
+James E Keenan
 
 =head1 SEE ALSO
 
Index: t/steps/auto_pcre-03.t
===================================================================
--- t/steps/auto_pcre-03.t      (revision 0)
+++ t/steps/auto_pcre-03.t      (revision 0)
@@ -0,0 +1,116 @@
+#! perl
+# Copyright (C) 2007-2008, The Perl Foundation.
+# $Id$
+# auto_pcre-03.t
+
+use strict;
+use warnings;
+use Test::More tests => 16;
+use Carp;
+use lib qw( lib );
+use_ok('config::init::defaults');
+use_ok('config::auto::pcre');
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Test qw( test_step_thru_runstep);
+use IO::CaptureOutput qw| capture |;
+
+my $args = process_options(
+    {
+        argv => [ q{--verbose} ],
+        mode => q{configure},
+    }
+);
+
+my $conf = Parrot::Configure->new;
+test_step_thru_runstep( $conf, q{init::defaults}, $args );
+
+my $pkg = q{auto::pcre};
+
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+
+my ( $task, $step_name, $step);
+$task        = $conf->steps->[-1];
+$step_name   = $task->step;
+
+$step = $step_name->new();
+ok( defined $step, "$step_name constructor returned defined value" );
+isa_ok( $step, $step_name );
+
+# Mock different outcomes of _evaluate_cc_run
+my ($test, $has_pcre);
+my $verbose = $conf->options->get('verbose');
+
+$test = q{pcre 4.0};
+{
+    my ($stdout, $stderr);
+    capture(
+        sub {
+            $has_pcre = $step->_evaluate_cc_run($test, $verbose);
+        },
+        \$stdout,
+    );
+    ok($has_pcre, "_evaluate_cc_run returned true value as expected");
+    is($step->result(), q{yes, v4.0}, "Got expected PCRE version");
+    like($stdout, qr/\(yes, 4\.0\)/, "Got expected verbose output");
+}
+
+# Mock different outcomes of _recheck_settings()
+my ($libs, $ccflags, $linkflags);
+
+$libs = q{-ldelta};
+$ccflags = q{-Iepsilon};
+$linkflags = q{-Lzeta};
+{
+    my ($stdout, $stderr);
+    capture(
+        sub { $step->_recheck_settings(
+            $conf, $libs, $ccflags, $linkflags, $verbose); },
+        \$stdout,
+    );
+    like($conf->data->get('libs'), qr/$libs/,
+        "Got expected value for 'libs'");
+    like($conf->data->get('ccflags'), qr/$ccflags/,
+        "Got expected value for 'ccflags'");
+    like($conf->data->get('linkflags'), qr/$linkflags/,
+        "Got expected value for 'linkflags'");
+    like($stdout, qr/\(no\)/, "Got expected verbose output");
+}
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+  auto_pcre-03.t - test config::auto::pcre
+
+=head1 SYNOPSIS
+
+    % prove t/steps/auto_pcre-03.t
+
+=head1 DESCRIPTION
+
+The files in this directory test functionality used by F<Configure.pl>.
+
+The tests in this file test internal subroutines of configuration step class
+auto::pcre in the case where C<--verbose> output has been requested on the
+command line.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+config::auto::pcre, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Property changes on: t/steps/auto_pcre-03.t
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Index: config/auto/pcre.pm
===================================================================
--- config/auto/pcre.pm (revision 27261)
+++ config/auto/pcre.pm (working copy)
@@ -56,14 +56,12 @@
         conf            => $conf,
         osname          => $osname,
         cc              => $cc,
-        win32_gcc       => '-lpcre',
         win32_nongcc    => 'pcre.lib',
         default         => '-lpcre',
     } );
 
     # On OS X check the presence of the pcre headers in the standard
     # Fink/macports locations.
-    # Mindlessly morphed from readline ... may need to be fixed
     $self->_handle_darwin_for_fink    ($conf, $osname, 'pcre.h');
     $self->_handle_darwin_for_macports($conf, $osname, 'pcre.h');
 
@@ -74,10 +72,7 @@
         my $test = $conf->cc_run();
         $has_pcre = $self->_evaluate_cc_run($test, $verbose);
     }
-    if ($has_pcre) {
-        _handle_pcre($conf, $verbose);
-    }
-    else {
+    if (! $has_pcre) {
         # The Parrot::Configure settings might have changed while class ran
         $self->_recheck_settings($conf, $libs, $ccflags, $linkflags, $verbose);
     }
@@ -91,22 +86,14 @@
     my ($test, $verbose) = @_;
     my $has_pcre = 0;
     if ( $test =~ /pcre (\d+\.\d+)/ ) {
+        my $pcre_version = $1;
         $has_pcre = 1;
-        print " (yes, $1) " if $verbose;
-        $self->set_result("yes, v$1");
+        print " (yes, $pcre_version) " if $verbose;
+        $self->set_result("yes, v$pcre_version");
     }
     return $has_pcre;
 }
 
-sub _handle_pcre {
-    my ($conf, $verbose) = @_;
-#    $conf->data->add( ' ', ccflags => "-DHAS_PCRE" );
-#    $verbose and print "\n  ccflags: ", $conf->data->get("ccflags"), "\n";
-    return 1;
-}
-
-
-
 1;
 
 # Local Variables:

Reply via email to