diff options
Diffstat (limited to 't')
-rw-r--r-- | t/00-compile.t | 50 | ||||
-rw-r--r-- | t/00-report-prereqs.dd | 45 | ||||
-rw-r--r-- | t/00-report-prereqs.t | 176 | ||||
-rw-r--r-- | t/author-no-tabs.t | 47 | ||||
-rw-r--r-- | t/author-pod-spell.t | 36 | ||||
-rw-r--r-- | t/basic.t | 37 | ||||
-rw-r--r-- | t/both-fail.t | 28 | ||||
-rw-r--r-- | t/env-value.t | 39 | ||||
-rw-r--r-- | t/lib/T/Impl1.pm | 16 | ||||
-rw-r--r-- | t/lib/T/Impl2.pm | 18 | ||||
-rw-r--r-- | t/lib/T/ImplFails1.pm | 16 | ||||
-rw-r--r-- | t/lib/T/ImplFails2.pm | 16 | ||||
-rw-r--r-- | t/more-symbols.t | 47 | ||||
-rw-r--r-- | t/namespace-cleanliness.t | 33 | ||||
-rw-r--r-- | t/one-impl-fails1.t | 28 | ||||
-rw-r--r-- | t/one-impl-fails2.t | 28 | ||||
-rw-r--r-- | t/release-cpan-changes.t | 19 | ||||
-rw-r--r-- | t/release-eol.t | 16 | ||||
-rw-r--r-- | t/release-pod-coverage.t | 43 | ||||
-rw-r--r-- | t/release-pod-linkcheck.t | 28 | ||||
-rw-r--r-- | t/release-pod-no404s.t | 29 | ||||
-rw-r--r-- | t/release-pod-syntax.t | 14 | ||||
-rw-r--r-- | t/release-portability.t | 19 | ||||
-rw-r--r-- | t/requested-fails.t | 30 | ||||
-rw-r--r-- | t/taint.t | 48 |
25 files changed, 906 insertions, 0 deletions
diff --git a/t/00-compile.t b/t/00-compile.t new file mode 100644 index 0000000..8d3b17e --- /dev/null +++ b/t/00-compile.t @@ -0,0 +1,50 @@ +use 5.006; +use strict; +use warnings; + +# this test was generated with Dist::Zilla::Plugin::Test::Compile 2.046 + +use Test::More tests => 1 + ($ENV{AUTHOR_TESTING} ? 1 : 0); + + + +my @module_files = ( + 'Module/Implementation.pm' +); + + + +# no fake home requested + +my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; + +use File::Spec; +use IPC::Open3; +use IO::Handle; + +open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; + +my @warnings; +for my $lib (@module_files) +{ + # see L<perlfaq8/How can I capture STDERR from an external command?> + my $stderr = IO::Handle->new; + + my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); + binmode $stderr, ':crlf' if $^O eq 'MSWin32'; + my @_warnings = <$stderr>; + waitpid($pid, 0); + is($?, 0, "$lib loaded ok"); + + if (@_warnings) + { + warn @_warnings; + push @warnings, @_warnings; + } +} + + + +is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', explain \@warnings if $ENV{AUTHOR_TESTING}; + + diff --git a/t/00-report-prereqs.dd b/t/00-report-prereqs.dd new file mode 100644 index 0000000..a3f6c98 --- /dev/null +++ b/t/00-report-prereqs.dd @@ -0,0 +1,45 @@ +do { my $x = { + 'configure' => { + 'requires' => { + 'ExtUtils::MakeMaker' => '0' + } + }, + 'develop' => { + 'requires' => { + 'Pod::Coverage::TrustPod' => '0', + 'Test::CPAN::Changes' => '0.19', + 'Test::More' => '0.88', + 'Test::NoTabs' => '0', + 'Test::Pod' => '1.41', + 'Test::Pod::Coverage' => '1.08', + 'Test::Spelling' => '0.12' + } + }, + 'runtime' => { + 'requires' => { + 'Carp' => '0', + 'Module::Runtime' => '0.012', + 'Try::Tiny' => '0', + 'strict' => '0', + 'warnings' => '0' + } + }, + 'test' => { + 'recommends' => { + 'CPAN::Meta' => '2.120900' + }, + 'requires' => { + 'ExtUtils::MakeMaker' => '0', + 'File::Spec' => '0', + 'IO::Handle' => '0', + 'IPC::Open3' => '0', + 'Test::Fatal' => '0.006', + 'Test::More' => '0.88', + 'Test::Requires' => '0', + 'lib' => '0', + 'perl' => '5.006' + } + } + }; + $x; + }
\ No newline at end of file diff --git a/t/00-report-prereqs.t b/t/00-report-prereqs.t new file mode 100644 index 0000000..402b3d9 --- /dev/null +++ b/t/00-report-prereqs.t @@ -0,0 +1,176 @@ +#!perl + +use strict; +use warnings; + +# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.019 + +use Test::More tests => 1; + +use ExtUtils::MakeMaker; +use File::Spec; + +# from $version::LAX +my $lax_version_re = + qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? + | + (?:\.[0-9]+) (?:_[0-9]+)? + ) | (?: + v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? + | + (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? + ) + )/x; + +# hide optional CPAN::Meta modules from prereq scanner +# and check if they are available +my $cpan_meta = "CPAN::Meta"; +my $cpan_meta_pre = "CPAN::Meta::Prereqs"; +my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic + +# Verify requirements? +my $DO_VERIFY_PREREQS = 1; + +sub _max { + my $max = shift; + $max = ( $_ > $max ) ? $_ : $max for @_; + return $max; +} + +sub _merge_prereqs { + my ($collector, $prereqs) = @_; + + # CPAN::Meta::Prereqs object + if (ref $collector eq $cpan_meta_pre) { + return $collector->with_merged_prereqs( + CPAN::Meta::Prereqs->new( $prereqs ) + ); + } + + # Raw hashrefs + for my $phase ( keys %$prereqs ) { + for my $type ( keys %{ $prereqs->{$phase} } ) { + for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { + $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; + } + } + } + + return $collector; +} + +my @include = qw( + +); + +my @exclude = qw( + +); + +# Add static prereqs to the included modules list +my $static_prereqs = do 't/00-report-prereqs.dd'; + +# Merge all prereqs (either with ::Prereqs or a hashref) +my $full_prereqs = _merge_prereqs( + ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), + $static_prereqs +); + +# Add dynamic prereqs to the included modules list (if we can) +my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; +if ( $source && $HAS_CPAN_META ) { + if ( my $meta = eval { CPAN::Meta->load_file($source) } ) { + $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); + } +} +else { + $source = 'static metadata'; +} + +my @full_reports; +my @dep_errors; +my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; + +# Add static includes into a fake section +for my $mod (@include) { + $req_hash->{other}{modules}{$mod} = 0; +} + +for my $phase ( qw(configure build test runtime develop other) ) { + next unless $req_hash->{$phase}; + next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); + + for my $type ( qw(requires recommends suggests conflicts modules) ) { + next unless $req_hash->{$phase}{$type}; + + my $title = ucfirst($phase).' '.ucfirst($type); + my @reports = [qw/Module Want Have/]; + + for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { + next if $mod eq 'perl'; + next if grep { $_ eq $mod } @exclude; + + my $file = $mod; + $file =~ s{::}{/}g; + $file .= ".pm"; + my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; + + my $want = $req_hash->{$phase}{$type}{$mod}; + $want = "undef" unless defined $want; + $want = "any" if !$want && $want == 0; + + my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; + + if ($prefix) { + my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); + $have = "undef" unless defined $have; + push @reports, [$mod, $want, $have]; + + if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { + if ( $have !~ /\A$lax_version_re\z/ ) { + push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; + } + elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { + push @dep_errors, "$mod version '$have' is not in required range '$want'"; + } + } + } + else { + push @reports, [$mod, $want, "missing"]; + + if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { + push @dep_errors, "$mod is not installed ($req_string)"; + } + } + } + + if ( @reports ) { + push @full_reports, "=== $title ===\n\n"; + + my $ml = _max( map { length $_->[0] } @reports ); + my $wl = _max( map { length $_->[1] } @reports ); + my $hl = _max( map { length $_->[2] } @reports ); + splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; + + push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; + push @full_reports, "\n"; + } + } +} + +if ( @full_reports ) { + diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; +} + +if ( @dep_errors ) { + diag join("\n", + "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", + "The following REQUIRED prerequisites were not satisfied:\n", + @dep_errors, + "\n" + ); +} + +pass; + +# vim: ts=4 sts=4 sw=4 et: diff --git a/t/author-no-tabs.t b/t/author-no-tabs.t new file mode 100644 index 0000000..678f479 --- /dev/null +++ b/t/author-no-tabs.t @@ -0,0 +1,47 @@ + +BEGIN { + unless ($ENV{AUTHOR_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for testing by the author'); + } +} + +use strict; +use warnings; + +# this test was generated with Dist::Zilla::Plugin::Test::NoTabs 0.09 + +use Test::More 0.88; +use Test::NoTabs; + +my @files = ( + 'lib/Module/Implementation.pm', + 't/00-compile.t', + 't/00-report-prereqs.dd', + 't/00-report-prereqs.t', + 't/author-no-tabs.t', + 't/author-pod-spell.t', + 't/basic.t', + 't/both-fail.t', + 't/env-value.t', + 't/lib/T/Impl1.pm', + 't/lib/T/Impl2.pm', + 't/lib/T/ImplFails1.pm', + 't/lib/T/ImplFails2.pm', + 't/more-symbols.t', + 't/namespace-cleanliness.t', + 't/one-impl-fails1.t', + 't/one-impl-fails2.t', + 't/release-cpan-changes.t', + 't/release-eol.t', + 't/release-pod-coverage.t', + 't/release-pod-linkcheck.t', + 't/release-pod-no404s.t', + 't/release-pod-syntax.t', + 't/release-portability.t', + 't/requested-fails.t', + 't/taint.t' +); + +notabs_ok($_) foreach @files; +done_testing; diff --git a/t/author-pod-spell.t b/t/author-pod-spell.t new file mode 100644 index 0000000..f5f0487 --- /dev/null +++ b/t/author-pod-spell.t @@ -0,0 +1,36 @@ + +BEGIN { + unless ($ENV{AUTHOR_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for testing by the author'); + } +} + +use strict; +use warnings; +use Test::More; + +# generated by Dist::Zilla::Plugin::Test::PodSpelling 2.006008 +use Test::Spelling 0.12; +use Pod::Wordlist; + + +add_stopwords(<DATA>); +all_pod_files_spelling_ok( qw( bin lib ) ); +__DATA__ +DROLSKY +DROLSKY's +Rolsky +Rolsky's +API +PurePerl +env +namespace +Dave +autarch +Peter +Rabbitson +ribasushi +lib +Module +Implementation diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..da33b4e --- /dev/null +++ b/t/basic.t @@ -0,0 +1,37 @@ +use strict; +use warnings; + +use Test::More 0.88; + +{ + package T; + + use strict; + use warnings; + + use lib 't/lib'; + + use Module::Implementation; + my $loader = Module::Implementation::build_loader_sub( + implementations => [ 'Impl1', 'Impl2' ], + symbols => ['return_42'], + ); + + ::is( $loader->(), 'T::Impl1', 'loader return loaded package name' ); +} + +{ + ok( T->can('return_42'), 'T package has a return_42 sub' ); + ok( + !T->can('return_package'), + 'T package does not have return_package sub - only copied requested symbols' + ); + is( T::return_42(), 42, 'T::return_42 work as expected' ); + is( + Module::Implementation::implementation_for('T'), + 'Impl1', + 'T::_implementation returns default implementation' + ); +} + +done_testing(); diff --git a/t/both-fail.t b/t/both-fail.t new file mode 100644 index 0000000..e21cb78 --- /dev/null +++ b/t/both-fail.t @@ -0,0 +1,28 @@ +use strict; +use warnings; + +use Test::More 0.88; +use Test::Fatal 0.006; + +{ + package T; + + use strict; + use warnings; + + use lib 't/lib'; + + use Module::Implementation; + my $loader = Module::Implementation::build_loader_sub( + implementations => [ 'ImplFails1', 'ImplFails2' ], + symbols => [qw( return_42 )], + ); + + ::like( + ::exception{ $loader->() }, + qr/Could not find a suitable T implementation/, + 'Got an exception when all implementations fail to load' + ); +} + +done_testing(); diff --git a/t/env-value.t b/t/env-value.t new file mode 100644 index 0000000..c1d439e --- /dev/null +++ b/t/env-value.t @@ -0,0 +1,39 @@ +use strict; +use warnings; + +use Test::More 0.88; + +{ + package T; + + use strict; + use warnings; + + use lib 't/lib'; + + use Module::Implementation; + my $loader = Module::Implementation::build_loader_sub( + implementations => [ 'Impl1', 'Impl2' ], + symbols => ['return_42'], + ); + + $ENV{T_IMPLEMENTATION} = 'Impl2'; + + $loader->(); +} + +{ + ok( T->can('return_42'), 'T package has a return_42 sub' ); + ok( + !T->can('return_package'), + 'T package does not have return_package sub - only copied requested symbols' + ); + is( T::return_42(), 42, 'T::return_42 work as expected' ); + is( + Module::Implementation::implementation_for('T'), + 'Impl2', + 'T::_implementation returns implementation set in ENV' + ); +} + +done_testing(); diff --git a/t/lib/T/Impl1.pm b/t/lib/T/Impl1.pm new file mode 100644 index 0000000..6ac7073 --- /dev/null +++ b/t/lib/T/Impl1.pm @@ -0,0 +1,16 @@ +package T::Impl1; + +use strict; +use warnings; + +sub return_42 { + return 42; +} + +sub return_package { + return __PACKAGE__; +} + +our $SCALAR = 42; +our @ARRAY = ( 1, 2, 3 ); +our %HASH = ( key => 'val' ); diff --git a/t/lib/T/Impl2.pm b/t/lib/T/Impl2.pm new file mode 100644 index 0000000..7de6c47 --- /dev/null +++ b/t/lib/T/Impl2.pm @@ -0,0 +1,18 @@ +package T::Impl2; + +use strict; +use warnings; + +sub return_42 { + return 42; +} + +sub return_package { + return __PACKAGE__; +} + +our $SCALAR = 42; +our @ARRAY = ( 1, 2, 3 ); +our %HASH = ( key => 'val' ); + +1; diff --git a/t/lib/T/ImplFails1.pm b/t/lib/T/ImplFails1.pm new file mode 100644 index 0000000..0f88cff --- /dev/null +++ b/t/lib/T/ImplFails1.pm @@ -0,0 +1,16 @@ +package T::ImplFails1; + +use strict; +use warnings; + +sub return_42 { + return 42; +} + +sub return_package { + return __PACKAGE__; +} + +die 'Error loading something or other'; + +1; diff --git a/t/lib/T/ImplFails2.pm b/t/lib/T/ImplFails2.pm new file mode 100644 index 0000000..c66b649 --- /dev/null +++ b/t/lib/T/ImplFails2.pm @@ -0,0 +1,16 @@ +package T::ImplFails2; + +use strict; +use warnings; + +sub return_42 { + return 42; +} + +sub return_package { + return __PACKAGE__; +} + +die 'Error loading something or other'; + +1; diff --git a/t/more-symbols.t b/t/more-symbols.t new file mode 100644 index 0000000..8bd8329 --- /dev/null +++ b/t/more-symbols.t @@ -0,0 +1,47 @@ +use strict; +use warnings; + +use Test::More 0.88; + +{ + package T; + + use strict; + use warnings; + + use lib 't/lib'; + + use Module::Implementation; + my $loader = Module::Implementation::build_loader_sub( + implementations => [ 'Impl1', 'Impl2' ], + symbols => [qw( return_42 &return_package $SCALAR @ARRAY %HASH )], + ); + + $loader->(); +} + +{ + ok( T->can('return_42'), 'T package has a return_42 sub' ); + ok( T->can('return_package'), 'T package has a return_package sub' ); + is( T::return_42(), 42, 'T::return_42 work as expected' ); + is( + T::return_package(), + 'T::Impl1', + 'T::return_package returns implementation package' + ); + + no warnings 'once'; + is( $T::SCALAR, 42, '$T::SCALAR was copied from implementation' ); + is_deeply( + \@T::ARRAY, + [ 1, 2, 3 ], + '@T::ARRAY was copied from implementation' + ); + is_deeply( + \%T::HASH, + { key => 'val' }, + '%T::HASH was copied from implementation' + ); +} + +done_testing(); diff --git a/t/namespace-cleanliness.t b/t/namespace-cleanliness.t new file mode 100644 index 0000000..a9917bf --- /dev/null +++ b/t/namespace-cleanliness.t @@ -0,0 +1,33 @@ +use strict; +use warnings; + +use Test::More 0.88; + +use Test::Requires { + 'Test::CleanNamespaces' => 0, +}; + +{ + package T; + + use strict; + use warnings; + + use lib 't/lib'; + + use Module::Implementation; + my $loader = Module::Implementation::build_loader_sub( + implementations => [ 'Impl1', 'Impl2' ], + symbols => ['return_42'], + ); + $loader->(); +} + +$INC{'T.pm'} = 1; + +{ + local $TODO = q{Without Sub::Name there's no good way to avoid dirtiness}; + namespaces_clean('T'); +} + +done_testing(); diff --git a/t/one-impl-fails1.t b/t/one-impl-fails1.t new file mode 100644 index 0000000..1df94a0 --- /dev/null +++ b/t/one-impl-fails1.t @@ -0,0 +1,28 @@ +use strict; +use warnings; + +use Test::More 0.88; + +{ + package T; + + use strict; + use warnings; + + use lib 't/lib'; + + use Module::Implementation; + my $loader = Module::Implementation::build_loader_sub( + implementations => [ 'ImplFails1', 'Impl1' ], + symbols => [qw( return_42 )], + ); + + $loader->(); +} + +{ + ok( T->can('return_42'), 'T package has a return_42 sub' ); + ok( !T->can('return_package'), 'T package has a return_package sub' ); +} + +done_testing(); diff --git a/t/one-impl-fails2.t b/t/one-impl-fails2.t new file mode 100644 index 0000000..444d1e8 --- /dev/null +++ b/t/one-impl-fails2.t @@ -0,0 +1,28 @@ +use strict; +use warnings; + +use Test::More 0.88; + +{ + package T; + + use strict; + use warnings; + + use lib 't/lib'; + + use Module::Implementation; + my $loader = Module::Implementation::build_loader_sub( + implementations => [ 'Impl1', 'ImplFails1' ], + symbols => [qw( return_42 )], + ); + + $loader->(); +} + +{ + ok( T->can('return_42'), 'T package has a return_42 sub' ); + ok( !T->can('return_package'), 'T package has a return_package sub' ); +} + +done_testing(); diff --git a/t/release-cpan-changes.t b/t/release-cpan-changes.t new file mode 100644 index 0000000..214650f --- /dev/null +++ b/t/release-cpan-changes.t @@ -0,0 +1,19 @@ +#!perl + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + + +use strict; +use warnings; + +use Test::More 0.96 tests => 2; +use_ok('Test::CPAN::Changes'); +subtest 'changes_ok' => sub { + changes_file_ok('Changes'); +}; +done_testing(); diff --git a/t/release-eol.t b/t/release-eol.t new file mode 100644 index 0000000..4ce4ad8 --- /dev/null +++ b/t/release-eol.t @@ -0,0 +1,16 @@ + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + +use strict; +use warnings; +use Test::More; + +eval 'use Test::EOL'; +plan skip_all => 'Test::EOL required' if $@; + +all_perl_files_ok({ trailing_whitespace => 1 }); diff --git a/t/release-pod-coverage.t b/t/release-pod-coverage.t new file mode 100644 index 0000000..1f3b7b6 --- /dev/null +++ b/t/release-pod-coverage.t @@ -0,0 +1,43 @@ +#!perl + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + +# This file was automatically generated by Dist::Zilla::Plugin::Test::Pod::Coverage::Configurable. + +use Test::Pod::Coverage 1.08; +use Test::More 0.88; +use Pod::Coverage::TrustPod; + +my %skip = map { $_ => 1 } qw( ); + +my @modules; +for my $module ( all_modules() ) { + next if $skip{$module}; + + push @modules, $module; +} + +plan skip_all => 'All the modules we found were excluded from POD coverage test.' + unless @modules; + +plan tests => scalar @modules; + +my %trustme = (); + +for my $module ( sort @modules ) { + pod_coverage_ok( + $module, + { + coverage_class => 'Pod::Coverage::TrustPod', + trustme => $trustme{$module} || [], + }, + "pod coverage for $module" + ); +} + +done_testing(); diff --git a/t/release-pod-linkcheck.t b/t/release-pod-linkcheck.t new file mode 100644 index 0000000..654cf06 --- /dev/null +++ b/t/release-pod-linkcheck.t @@ -0,0 +1,28 @@ +#!perl + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + + +use strict; +use warnings; +use Test::More; + +foreach my $env_skip ( qw( + SKIP_POD_LINKCHECK +) ){ + plan skip_all => "\$ENV{$env_skip} is set, skipping" + if $ENV{$env_skip}; +} + +eval "use Test::Pod::LinkCheck"; +if ( $@ ) { + plan skip_all => 'Test::Pod::LinkCheck required for testing POD'; +} +else { + Test::Pod::LinkCheck->new->all_pod_ok; +} diff --git a/t/release-pod-no404s.t b/t/release-pod-no404s.t new file mode 100644 index 0000000..da185ec --- /dev/null +++ b/t/release-pod-no404s.t @@ -0,0 +1,29 @@ +#!perl + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + + +use strict; +use warnings; +use Test::More; + +foreach my $env_skip ( qw( + SKIP_POD_NO404S + AUTOMATED_TESTING +) ){ + plan skip_all => "\$ENV{$env_skip} is set, skipping" + if $ENV{$env_skip}; +} + +eval "use Test::Pod::No404s"; +if ( $@ ) { + plan skip_all => 'Test::Pod::No404s required for testing POD'; +} +else { + all_pod_files_ok(); +} diff --git a/t/release-pod-syntax.t b/t/release-pod-syntax.t new file mode 100644 index 0000000..cdd6a6c --- /dev/null +++ b/t/release-pod-syntax.t @@ -0,0 +1,14 @@ +#!perl + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + +# This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. +use Test::More; +use Test::Pod 1.41; + +all_pod_files_ok(); diff --git a/t/release-portability.t b/t/release-portability.t new file mode 100644 index 0000000..f0fd79f --- /dev/null +++ b/t/release-portability.t @@ -0,0 +1,19 @@ +#!perl + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + + +use strict; +use warnings; + +use Test::More; + +eval 'use Test::Portability::Files'; +plan skip_all => 'Test::Portability::Files required for testing portability' + if $@; +run_tests(); diff --git a/t/requested-fails.t b/t/requested-fails.t new file mode 100644 index 0000000..da34424 --- /dev/null +++ b/t/requested-fails.t @@ -0,0 +1,30 @@ +use strict; +use warnings; + +use Test::More 0.88; +use Test::Fatal 0.006; + +{ + package T; + + use strict; + use warnings; + + use lib 't/lib'; + + use Module::Implementation; + my $loader = Module::Implementation::build_loader_sub( + implementations => [ 'ImplFails1', 'Impl1' ], + symbols => [qw( return_42 )], + ); + + $ENV{T_IMPLEMENTATION} = 'ImplFails1'; + + ::like( + ::exception{ $loader->() }, + qr/Could not load T::ImplFails1/, + 'Got an exception when implementation requested in env value fails to load' + ); +} + +done_testing(); diff --git a/t/taint.t b/t/taint.t new file mode 100644 index 0000000..13f197a --- /dev/null +++ b/t/taint.t @@ -0,0 +1,48 @@ +#!perl -T + +use strict; +use warnings; + +use Test::Requires { + 'Test::Taint' => '0', +}; + +use Test::More 0.88; +use Test::Fatal 0.006; + +taint_checking_ok(); + +{ + package T; + + use strict; + use warnings; + + use lib 't/lib'; + + use Module::Implementation; + my $loader = Module::Implementation::build_loader_sub( + implementations => [ 'Impl1', 'Impl2' ], + symbols => ['return_42'], + ); + + ::taint( $ENV{T_IMPLEMENTATION} = 'Impl2' ); + + ::tainted_ok( $ENV{T_IMPLEMENTATION}, '$ENV{T_IMPLEMENTATION} is tainted' ); + + ::is( + ::exception{ $loader->() }, + undef, + 'no exception when implementation is specified in env var under taint mode' + ); +} + +{ + is( + Module::Implementation::implementation_for('T'), + 'Impl2', + 'T::_implementation returns implementation set in ENV' + ); +} + +done_testing(); |