Author: ericwilhelm
Date: Wed Jul  9 15:40:21 2008
New Revision: 11508

Added:
   Module-Build/trunk/t/test_file_exts.t
Modified:
   Module-Build/trunk/Changes
   Module-Build/trunk/MANIFEST
   Module-Build/trunk/lib/Module/Build.pm
   Module-Build/trunk/lib/Module/Build/Base.pm

Log:
** patch from David Wheeler for test_file_exts support
t/test_file_exts.t       - a test
lib/Module/Build/Base.pm - adding test_file_exts property, default to ['.t']
lib/Module/Build.pm      - documenting test_file_exts
MANIFEST                 - regen
Changes                  - update


Modified: Module-Build/trunk/Changes
==============================================================================
--- Module-Build/trunk/Changes  (original)
+++ Module-Build/trunk/Changes  Wed Jul  9 15:40:21 2008
@@ -1,5 +1,8 @@
 Revision history for Perl extension Module::Build.
 
+ - Added test_file_exts property for main-run tests other than '*.t'.
+   [David Wheeler]
+
  - Fixed getcwd()/rmtree() failure case on 5.10+mac where something is
    unhappy about all of the tests deleting their distgen directory
    before leaving it. [Eric Wilhelm & David Wheeler]

Modified: Module-Build/trunk/MANIFEST
==============================================================================
--- Module-Build/trunk/MANIFEST (original)
+++ Module-Build/trunk/MANIFEST Wed Jul  9 15:40:21 2008
@@ -63,6 +63,7 @@
 t/runthrough.t
 t/script_dist.t
 t/signature.t
+t/test_file_exts.t
 t/test_type.t
 t/test_types.t
 t/tilde.t

Modified: Module-Build/trunk/lib/Module/Build.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build.pm      (original)
+++ Module-Build/trunk/lib/Module/Build.pm      Wed Jul  9 15:40:21 2008
@@ -554,6 +554,10 @@
 If you want to run tests under the perl debugger, pass the argument
 C<debugger=1>.
 
+If you want to have Module::Build find test files with different file
+name extensions, pass the C<test_file_exts> argument with an array
+of extensions, such as C<[qw( .t .s .z )]>.
+
 In addition, if a file called C<visual.pl> exists in the top-level
 directory, this file will be executed as a Perl script and its output
 will be shown to the user.  This is a good place to put speed tests or
@@ -597,7 +601,7 @@
     ...
     test_types  => {
       special => '.st',
-      author  => '.at',
+      author  => ['.at', '.pt' ],
     },
     ...
 

Modified: Module-Build/trunk/lib/Module/Build/Base.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build/Base.pm (original)
+++ Module-Build/trunk/lib/Module/Build/Base.pm Wed Jul  9 15:40:21 2008
@@ -776,6 +776,7 @@
 __PACKAGE__->add_property(create_packlist => 1);
 __PACKAGE__->add_property(allow_mb_mismatch => 0);
 __PACKAGE__->add_property(config => undef);
+__PACKAGE__->add_property(test_file_exts => ['.t']);
 
 {
   my $Is_ActivePerl = eval {require ActivePerl::DocTools};
@@ -2110,7 +2111,7 @@
   @types or croak "need some types of tests to check";
 
   my %test_types = (
-    default => '.t',
+    default => $p->{test_file_exts},
     (defined($p->{test_types}) ? %{$p->{test_types}} : ()),
   );
 
@@ -2120,7 +2121,7 @@
   }
 
   # we use local here because it ends up two method calls deep
-  local $p->{test_file_exts} = [ @[EMAIL PROTECTED] ];
+  local $p->{test_file_exts} = [ map { ref $_ ? @$_ : $_ } @[EMAIL PROTECTED] 
];
   $self->depends_on('code');
 
   # Protect others against our @INC changes
@@ -2186,7 +2187,7 @@
 
 sub expand_test_dir {
   my ($self, $dir) = @_;
-  my $exts = $self->{properties}{test_file_exts} || ['.t'];
+  my $exts = $self->{properties}{test_file_exts};
 
   return sort map { @{$self->rscan_dir($dir, qr{^[^.].*\Q$_\E$})} } @$exts
     if $self->recursive_test_files;

Added: Module-Build/trunk/t/test_file_exts.t
==============================================================================
--- (empty file)
+++ Module-Build/trunk/t/test_file_exts.t       Wed Jul  9 15:40:21 2008
@@ -0,0 +1,45 @@
+#!/usr/bin/perl -w
+
+use strict;
+use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
+use MBTest tests => 5;
+use DistGen;
+
+use_ok 'Module::Build';
+ensure_blib('Module::Build');
+
+my $tmp = MBTest->tmpdir;
+my $dist = DistGen->new( dir => $tmp );
+
+$dist->add_file('t/mytest.s', <<'---' );
+#!perl
+use Test::More tests => 2;
+ok(1, 'first mytest.s');
+ok(1, 'second mytest.s');
+---
+
+$dist->regen;
+$dist->chdir_in;
+
+#########################
+
+# So make sure that the test gets run with the alternate extension.
+ok my $mb = Module::Build->new(
+    module_name    => $dist->name,
+    test_file_exts => ['.s'],
+    quiet          => 1,
+), 'Construct build object with test_file_exts parameter';
+
+$mb->add_to_cleanup('save_out');
+# Use uc() so we don't confuse the current test output
+my $out = uc(stdout_of(
+    sub {$mb->dispatch('test', verbose => 1)}
+));
+
+like $out, qr/^OK 1 - FIRST MYTEST[.]S/m, 'Should see first test output';
+like $out, qr/^OK 2 - SECOND MYTEST[.]S/m, 'Should see second test output';
+
+# Cleanup.
+$dist->remove;
+
+# vim:ts=4:sw=4:et:sta

Reply via email to