~ubuntu-branches/ubuntu/natty/libsignatures-perl/natty

« back to all changes in this revision

Viewing changes to inc/Module/Install/ExtraTests.pm

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Niebur
  • Date: 2009-05-18 20:34:44 UTC
  • Revision ID: james.westby@ubuntu.com-20090518203444-ee3iqibpk6uxo7u8
Tags: upstream-0.05
ImportĀ upstreamĀ versionĀ 0.05

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#line 1
 
2
use strict;
 
3
use warnings;
 
4
use 5.006;
 
5
package Module::Install::ExtraTests;
 
6
use Module::Install::Base;
 
7
 
 
8
BEGIN {
 
9
  our $VERSION = '0.006';
 
10
  our $ISCORE  = 1;
 
11
  our @ISA     = qw{Module::Install::Base};
 
12
}
 
13
 
 
14
sub extra_tests {
 
15
  my ($self) = @_;
 
16
 
 
17
  return unless -d 'xt';
 
18
  return unless my @content = grep { $_ =~ /^[.]/ } <xt/*>;
 
19
 
 
20
  die "unknown files found in ./xt" if grep { -f } @content;
 
21
 
 
22
  my %known   = map {; $_ => 1 } qw(author smoke release);
 
23
  my @unknown = grep { not $known{$_} } @content;
 
24
  die "unknown directories found in ./xt: @unknown" if @unknown;
 
25
 
 
26
  {
 
27
    no warnings qw(closure once);
 
28
    package # The newline tells PAUSE, "DO NOT INDEXING!"
 
29
    MY;
 
30
    sub test_via_harness {
 
31
      my ($self, $perl, $tests) = @_;
 
32
      my $a_str = -d 'xt/author'  ? 'xt/author'  : '';
 
33
      my $r_str = -d 'xt/release' ? 'xt/release' : '';
 
34
      my $s_str = -d 'xt/smoke'   ? 'xt/smoke'   : '';
 
35
      my $is_author = $Module::Install::AUTHOR ? 1 : 0;
 
36
 
 
37
      return qq{\t$perl "-Iinc" "-MModule::Install::ExtraTests" }
 
38
           . qq{"-e" "Module::Install::ExtraTests::__harness('Test::Harness', $is_author, '$a_str', '$r_str', '$s_str', \$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n};
 
39
    }
 
40
 
 
41
    sub dist_test {
 
42
      my ($self, @args) = @_;
 
43
      my $text = $self->SUPER::dist_test(@args);
 
44
      my @lines = split /\n/, $text;
 
45
      $_ =~ s/ (\S*MAKE\S* test )/ RELEASE_TESTING=1 $1 / for grep { m/ test / } @lines;
 
46
      return join "\n", @lines;
 
47
    }
 
48
 
 
49
  }
 
50
}
 
51
 
 
52
sub __harness {
 
53
  my $harness_class = shift;
 
54
  my $is_author     = shift;
 
55
  my $author_tests  = shift;
 
56
  my $release_tests = shift;
 
57
  my $smoke_tests   = shift;
 
58
 
 
59
  eval "require $harness_class; 1" or die;
 
60
  require File::Spec;
 
61
 
 
62
  my $verbose = shift;
 
63
  eval "\$$harness_class\::verbose = $verbose; 1" or die;
 
64
 
 
65
  # Because Windows doesn't do this for us and listing all the *.t files
 
66
  # out on the command line can blow over its exec limit.
 
67
  require ExtUtils::Command;
 
68
  push @ARGV, __PACKAGE__->_deep_t($author_tests)
 
69
    if $author_tests and (exists $ENV{AUTHOR_TESTING} ? $ENV{AUTHOR_TESTING} : $is_author);
 
70
 
 
71
  push @ARGV, __PACKAGE__->_deep_t($release_tests)
 
72
    if $release_tests and $ENV{RELEASE_TESTING};
 
73
 
 
74
  push @ARGV, __PACKAGE__->_deep_t($smoke_tests)
 
75
    if $smoke_tests and $ENV{AUTOMATED_TESTING};
 
76
 
 
77
  my @argv = ExtUtils::Command::expand_wildcards(@ARGV);
 
78
 
 
79
  local @INC = @INC;
 
80
  unshift @INC, map { File::Spec->rel2abs($_) } @_;
 
81
  $harness_class->can('runtests')->(sort { lc $a cmp lc $b } @argv);
 
82
}
 
83
 
 
84
sub _wanted {
 
85
  my $href = shift;
 
86
  no warnings 'once';
 
87
  sub { /\.t$/ and -f $_ and $href->{$File::Find::dir} = 1 }
 
88
}
 
89
 
 
90
sub _deep_t {
 
91
  my ($self, $dir) = @_;
 
92
  require File::Find;
 
93
 
 
94
  my %test_dir;
 
95
  File::Find::find(_wanted(\%test_dir), $dir);
 
96
  return map { "$_/*.t" } sort keys %test_dir;
 
97
}
 
98
 
 
99
1;
 
100
__END__