1#line 1 2package Module::Install::StandardTests; 3 4use warnings; 5use strict; 6use File::Spec; 7 8use base 'Module::Install::Base'; 9 10 11our $VERSION = '0.05'; 12 13 14sub use_standard_tests { 15 my ($self, %specs) = @_; 16 17 my %with = map { $_ => 1 } qw/compile pod pod_coverage perl_critic/; 18 if (exists $specs{without}) { 19 $specs{without} = [ $specs{without} ] unless ref $specs{without}; 20 delete $with{$_} for @{ $specs{without} }; 21 } 22 23 $self->build_requires('Test::More'); 24 $self->build_requires('UNIVERSAL::require'); 25 26 # Unlike other tests, this is mandatory. 27 $self->build_requires('Test::Compile'); 28 29 $self->write_standard_test_compile; # no if; this is mandatory 30 $self->write_standard_test_pod if $with{pod}; 31 $self->write_standard_test_pod_coverage if $with{pod_coverage}; 32 $self->write_standard_test_perl_critic if $with{perl_critic}; 33} 34 35 36sub write_test_file { 37 my ($self, $filename, $code) = @_; 38 $filename = File::Spec->catfile('t', $filename); 39 40 # Outdent the code somewhat. Remove first empty line, if any. Then 41 # determine the indent of the first line. Throw that amount of indenting 42 # away from any line. This allows you to indent the code so it's visually 43 # clearer (see methods below) while creating output that's indented more 44 # or less correctly. Smoke result HTML pages link to the .t files, so it 45 # looks neater. 46 47 $code =~ s/^ *\n//; 48 (my $indent = $code) =~ s/^( *).*/$1/s; 49 $code =~ s/^$indent//gm; 50 51 print "Creating $filename\n"; 52 open(my $fh, ">$filename") or die "can't create $filename $!"; 53 54 my $perl = $^X; 55 print $fh <<TEST; 56#!$perl -w 57 58use strict; 59use warnings; 60 61$code 62TEST 63 64 close $fh or die "can't close $filename $!\n"; 65 $self->realclean_files($filename); 66} 67 68 69sub write_standard_test_compile { 70 my $self = shift; 71 $self->write_test_file('000_standard__compile.t', q/ 72 BEGIN { 73 use Test::More; 74 eval "use Test::Compile"; 75 Test::More->builder->BAIL_OUT( 76 "Test::Compile required for testing compilation") if $@; 77 all_pm_files_ok(); 78 } 79 /); 80} 81 82 83sub write_standard_test_pod { 84 my $self = shift; 85 $self->write_test_file('000_standard__pod.t', q/ 86 use Test::More; 87 eval "use Test::Pod"; 88 plan skip_all => "Test::Pod required for testing POD" if $@; 89 all_pod_files_ok(); 90 /); 91} 92 93 94sub write_standard_test_pod_coverage { 95 my $self = shift; 96 $self->write_test_file('000_standard__pod_coverage.t', q/ 97 use Test::More; 98 eval "use Test::Pod::Coverage"; 99 plan skip_all => 100 "Test::Pod::Coverage required for testing POD coverage" if $@; 101 all_pod_coverage_ok(); 102 /); 103} 104 105 106sub write_standard_test_perl_critic { 107 my $self = shift; 108 $self->write_test_file('000_standard__perl_critic.t', q/ 109 use FindBin '$Bin'; 110 use File::Spec; 111 use UNIVERSAL::require; 112 use Test::More; 113 114 plan skip_all => 115 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.' 116 unless $ENV{TEST_AUTHOR}; 117 118 my %opt; 119 my $rc_file = File::Spec->catfile($Bin, 'perlcriticrc'); 120 $opt{'-profile'} = $rc_file if -r $rc_file; 121 122 if (Perl::Critic->require('1.078') && 123 Test::Perl::Critic->require && 124 Test::Perl::Critic->import(%opt)) { 125 126 all_critic_ok("lib"); 127 } else { 128 plan skip_all => $@; 129 } 130 /); 131} 132 133 1341; 135 136__END__ 137 138#line 249 139 140