Author: jkeenan
Date: Thu Nov  8 05:22:10 2007
New Revision: 22763

Added:
   trunk/t/configure/150-auto_ctags-01.t   (contents, props changed)
   trunk/t/configure/150-auto_ctags-02.t   (contents, props changed)
   trunk/t/configure/150-auto_ctags-03.t   (contents, props changed)
   trunk/t/configure/150-auto_ctags-04.t   (contents, props changed)
Removed:
   trunk/t/configure/150-auto_ctags.t
Modified:
   trunk/MANIFEST
   trunk/config/auto/ctags.pm

Log:
Applying patches submitted via RT 46727.  Refactor configuration step 
auto::ctags to increase testability.  Contribute additional test files to 
achieve high test coverage.

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Thu Nov  8 05:22:10 2007
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Tue Nov  6 11:58:21 2007 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Nov  8 12:56:09 2007 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -3103,7 +3103,10 @@
 t/configure/147-auto_perldoc.t                              []
 t/configure/148-auto_python.t                               []
 t/configure/149-auto_m4.t                                   []
-t/configure/150-auto_ctags.t                                []
+t/configure/150-auto_ctags-01.t                             []
+t/configure/150-auto_ctags-02.t                             []
+t/configure/150-auto_ctags-03.t                             []
+t/configure/150-auto_ctags-04.t                             []
 t/configure/151-auto_cpu-01.t                               []
 t/configure/152-auto_revision.t                             []
 t/configure/153-gen_icu.t                                   []

Modified: trunk/config/auto/ctags.pm
==============================================================================
--- trunk/config/auto/ctags.pm  (original)
+++ trunk/config/auto/ctags.pm  Thu Nov  8 05:22:10 2007
@@ -33,34 +33,53 @@
     return \%data;
 }
 
-our $verbose;
+my @ctags_variations =
+    defined( $ENV{TEST_CTAGS} )
+    ? @{ $ENV{TEST_CTAGS} }
+    : qw( ctags exuberant-ctags ctags-exuberant exctags );
 
 sub runstep {
     my ( $self, $conf ) = @_;
 
-    $verbose = $conf->options->get( 'verbose' );
+    my $verbose = $conf->options->get( 'verbose' );
     print "\n" if $verbose;
 
-    my @ctags_variations = qw( ctags exuberant-ctags ctags-exuberant exctags );
-    for my $ctags ( @ctags_variations ) {
-        my $output = capture_output( $ctags, '--version' ) || '';
-        print $output, "\n" if $verbose;
-        my $has_ctags = ( $output =~ m/Exuberant Ctags/ ) ? 1 : 0;
-        print $has_ctags, "\n" if $verbose;
+    my ($ctags, $has_ctags) =
+        _probe_for_ctags([ @ctags_variations ], $verbose);
+    $self->_evaluate_ctags($conf, $ctags, $has_ctags);
+    return 1;
+}
 
-        if ( $has_ctags ) {
-            $conf->data->set( ctags => $ctags );
-            $self->set_result( 'yes' );
-            return 1;
-        }
+sub _probe_for_ctags {
+    my $variations_ref = shift;
+    my $verbose = shift;
+    my ($ctags, $has_ctags);
+    while (defined (my $t = shift(@$variations_ref))) {
+        my $output = capture_output( $t, '--version' ) || '';
+        print $output, "\n" if $verbose;
+        $has_ctags = _probe_for_ctags_output($output, $verbose);
+        $ctags = $t if $has_ctags;
+        next unless $has_ctags;
     }
+    return ($ctags, $has_ctags);
+}
 
-    # if we get to here, we didn't find a decent ctags; so just set it to
-    # ctags so that the Makefile is happy
-    $conf->data->set( ctags => 'ctags' );
-    $self->set_result( 'no' );
+sub _probe_for_ctags_output {
+    my ($output, $verbose) = @_;
+    my $has_ctags = ( $output =~ m/Exuberant Ctags/ ) ? 1 : 0;
+    print $has_ctags, "\n" if $verbose;
+    return $has_ctags;
+}
 
-    return 1;
+sub _evaluate_ctags {
+    my ($self, $conf, $ctags, $has_ctags) = @_;
+    if ($has_ctags) {
+        $conf->data->set( ctags => $ctags );
+        $self->set_result( 'yes' );
+    } else {
+        $conf->data->set( ctags => 'ctags' );
+        $self->set_result( 'no' );
+    }
 }
 
 1;

Added: trunk/t/configure/150-auto_ctags-01.t
==============================================================================
--- (empty file)
+++ trunk/t/configure/150-auto_ctags-01.t       Thu Nov  8 05:22:10 2007
@@ -0,0 +1,82 @@
+#!perl
+# Copyright (C) 2001-2007, The Perl Foundation.
+# $Id$
+# 150-auto_ctags-01.t
+
+use strict;
+use warnings;
+use Test::More tests => 14;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::auto::ctags');
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Test qw( test_step_thru_runstep);
+
+my $args = process_options(
+    {
+        argv => [ ],
+        mode => q{configure},
+    }
+);
+
+my $conf = Parrot::Configure->new;
+
+test_step_thru_runstep( $conf, q{init::defaults}, $args );
+
+my $pkg = q{auto::ctags};
+
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+
+my ( $task, $step_name, @step_params, $step);
+$task        = $conf->steps->[1];
+$step_name   = $task->step;
[EMAIL PROTECTED] = @{ $task->params };
+
+$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" );
+
+my %possible_ctags = map {$_,1}
+    qw( ctags exuberant-ctags ctags-exuberant exctags );
+
+my $ret = $step->runstep($conf);
+ok( $ret, "$step_name runstep() returned true value" );
+ok(defined($step->result()), "Result was defined");
+ok($possible_ctags{$conf->data->get('ctags')},
+    "Acceptable value for 'ctags' attribute was set");
+
+pass("Keep Devel::Cover happy");
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+t/configure/150-auto_ctags-01.t - tests Parrot::Configure::Step::auto::ctags
+
+=head1 SYNOPSIS
+
+    prove t/configure/150-auto_ctags-01.t
+
+=head1 DESCRIPTION
+
+Regression tests for the L<Parrot::Configure::Step::auto::ctags> module.
+This file holds tests for Parrot::Configure::Step::auto::ctags::runstep()
+(a non-exported subroutine).
+
+=head1 AUTHOR
+
+Paul Cochrane <paultcochrane at gmail dot com>
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/t/configure/150-auto_ctags-02.t
==============================================================================
--- (empty file)
+++ trunk/t/configure/150-auto_ctags-02.t       Thu Nov  8 05:22:10 2007
@@ -0,0 +1,88 @@
+#!perl
+# Copyright (C) 2001-2007, The Perl Foundation.
+# $Id$
+# 150-auto_ctags-02.t
+
+use strict;
+use warnings;
+use Test::More tests => 15;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+$ENV{TEST_CTAGS} = [ ( 'foobar' ) ];
+use_ok('config::auto::ctags');
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Test qw( test_step_thru_runstep);
+use Parrot::IO::Capture::Mini;
+
+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::ctags};
+
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+
+my ( $task, $step_name, @step_params, $step);
+$task        = $conf->steps->[1];
+$step_name   = $task->step;
[EMAIL PROTECTED] = @{ $task->params };
+
+$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" );
+
+{
+    my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini"
+        or croak "Unable to tie";
+    my $ret = $step->runstep($conf);
+    ok( $ret, "$step_name runstep() returned true value" );
+    my @more_lines = $tie_out->READLINE;
+    ok( @more_lines, "verbose output captured" );
+    is($step->result(), q{no}, "Got expected result");
+    is($conf->data->get('ctags'), 'ctags',
+        "Correct value for 'ctags' attribute was set");
+}
+untie *STDOUT;
+
+pass("Keep Devel::Cover happy");
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+t/configure/150-auto_ctags-02.t - tests Parrot::Configure::Step::auto::ctags
+
+=head1 SYNOPSIS
+
+    prove t/configure/150-auto_ctags-02.t
+
+=head1 DESCRIPTION
+
+Regression tests for the L<Parrot::Configure::Step::auto::ctags> module.
+This file holds tests for Parrot::Configure::Step::auto::ctags::runstep()
+(a non-exported subroutine).
+
+=head1 AUTHOR
+
+Paul Cochrane <paultcochrane at gmail dot com>
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/t/configure/150-auto_ctags-03.t
==============================================================================
--- (empty file)
+++ trunk/t/configure/150-auto_ctags-03.t       Thu Nov  8 05:22:10 2007
@@ -0,0 +1,79 @@
+#!perl
+# Copyright (C) 2001-2007, The Perl Foundation.
+# $Id$
+# 150-auto_ctags-03.t
+
+use strict;
+use warnings;
+use Test::More tests => 13;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::auto::ctags');
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Test qw( test_step_thru_runstep);
+
+my $args = process_options(
+    {
+        argv => [ ],
+        mode => q{configure},
+    }
+);
+
+my $conf = Parrot::Configure->new;
+
+test_step_thru_runstep( $conf, q{init::defaults}, $args );
+
+my $pkg = q{auto::ctags};
+
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+
+my ( $task, $step_name, @step_params, $step);
+$task        = $conf->steps->[1];
+$step_name   = $task->step;
[EMAIL PROTECTED] = @{ $task->params };
+
+$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" );
+
+my $pseudo_ctags = q{alpha};
+$step->_evaluate_ctags($conf, $pseudo_ctags, 1);
+is($conf->data->get('ctags'), $pseudo_ctags,
+    "'ctags' attribute was set as expected");
+is($step->result(), q{yes}, "Got expected result");
+
+pass("Keep Devel::Cover happy");
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+t/configure/150-auto_ctags-03.t - tests Parrot::Configure::Step::auto::ctags
+
+=head1 SYNOPSIS
+
+    prove t/configure/150-auto_ctags-03.t
+
+=head1 DESCRIPTION
+
+Regression tests for the L<Parrot::Configure::Step::auto::ctags> module.
+This file holds tests for Parrot::Configure::Step::auto::ctags::runstep()
+(a non-exported subroutine).
+
+=head1 AUTHOR
+
+Paul Cochrane <paultcochrane at gmail dot com>
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/t/configure/150-auto_ctags-04.t
==============================================================================
--- (empty file)
+++ trunk/t/configure/150-auto_ctags-04.t       Thu Nov  8 05:22:10 2007
@@ -0,0 +1,100 @@
+#!perl
+# Copyright (C) 2001-2007, The Perl Foundation.
+# $Id$
+# 150-auto_ctags-04.t
+
+use strict;
+use warnings;
+use Test::More tests => 17;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::init::defaults');
+use_ok('config::auto::ctags');
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Test qw( test_step_thru_runstep);
+use Parrot::IO::Capture::Mini;
+
+my $args = process_options(
+    {
+        argv => [ ],
+        mode => q{configure},
+    }
+);
+
+my $conf = Parrot::Configure->new;
+
+test_step_thru_runstep( $conf, q{init::defaults}, $args );
+
+my $pkg = q{auto::ctags};
+
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+
+my ( $task, $step_name, @step_params, $step);
+$task        = $conf->steps->[1];
+$step_name   = $task->step;
[EMAIL PROTECTED] = @{ $task->params };
+
+$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(auto::ctags::_probe_for_ctags_output('Exuberant Ctags', 0),
+    "Probe returned true when output matched");
+
+ok(! auto::ctags::_probe_for_ctags_output('alpha', 0),
+    "Probe returned false when output matched");
+
+{
+    my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini"
+        or croak "Unable to tie";
+    ok(auto::ctags::_probe_for_ctags_output('Exuberant Ctags', 1),
+        "Probe returned true when output matched");
+    my @more_lines = $tie_out->READLINE;
+    ok( @more_lines, "verbose output captured" );
+}
+untie *STDOUT;
+
+{
+    my $tie_out = tie *STDOUT, "Parrot::IO::Capture::Mini"
+        or croak "Unable to tie";
+    ok(! auto::ctags::_probe_for_ctags_output('alpha', 1),
+        "Probe returned false when output matched");
+    my @more_lines = $tie_out->READLINE;
+    ok( @more_lines, "verbose output captured" );
+}
+untie *STDOUT;
+
+pass("Keep Devel::Cover happy");
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+t/configure/150-auto_ctags-04.t - tests Parrot::Configure::Step::auto::ctags
+
+=head1 SYNOPSIS
+
+    prove t/configure/150-auto_ctags-04.t
+
+=head1 DESCRIPTION
+
+Regression tests for the L<Parrot::Configure::Step::auto::ctags> module.
+This file holds tests for Parrot::Configure::Step::auto::ctags::runstep()
+(a non-exported subroutine).
+
+=head1 AUTHOR
+
+Paul Cochrane <paultcochrane at gmail dot com>
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Reply via email to