diff options
Diffstat (limited to 't')
-rw-r--r-- | t/00-load.t | 6 | ||||
-rw-r--r-- | t/lib/TestLib.pm | 3 | ||||
-rw-r--r-- | t/main.t | 19 | ||||
-rw-r--r-- | t/memory.t | 45 |
4 files changed, 73 insertions, 0 deletions
diff --git a/t/00-load.t b/t/00-load.t new file mode 100644 index 0000000..06de4f7 --- /dev/null +++ b/t/00-load.t @@ -0,0 +1,6 @@ +use strict; + +use Test::More tests => 1; + +require_ok('Module::Reader') + || BAIL_OUT("Stopping due to compile failure!"); diff --git a/t/lib/TestLib.pm b/t/lib/TestLib.pm new file mode 100644 index 0000000..3e1b6ff --- /dev/null +++ b/t/lib/TestLib.pm @@ -0,0 +1,3 @@ +package TestLib; + +1; diff --git a/t/main.t b/t/main.t new file mode 100644 index 0000000..67c86ae --- /dev/null +++ b/t/main.t @@ -0,0 +1,19 @@ +use strict; +use warnings; + +use Test::More 0.88; +use Module::Reader qw(:all); + +my $mod_content = do { + open my $fh, '<', 't/lib/TestLib.pm'; + local $/; + <$fh>; +}; + +{ + local @INC = @INC; + unshift @INC, 't/lib'; + is module_content('TestLib'), $mod_content, 'correctly load module from disk'; +} + +done_testing; diff --git a/t/memory.t b/t/memory.t new file mode 100644 index 0000000..d33974e --- /dev/null +++ b/t/memory.t @@ -0,0 +1,45 @@ +use strict; +use warnings; + +use Test::More 0.88; +use Module::Reader qw(:all); + +my $mod_content = do { + open my $fh, '<', 't/lib/TestLib.pm'; + local $/; + <$fh>; +}; + +{ + local @INC = @INC; + unshift @INC, sub { + return unless $_[1] eq 'TestLib.pm'; + if ($] < 5.008) { + my $mod = $mod_content; + return sub { + return 0 unless length $mod; + $mod =~ s/^([^\n]*\n?)//; + $_ = $1; + return 1; + }; + } + open my $fh, '<', \$mod_content; + return $fh; + }; + is module_content('TestLib'), $mod_content, 'correctly load module from sub @INC hook'; + SKIP: { + skip 'found option doesn\'t work with @INC hooks in perl < 5.8', 2 + if $] < 5.008; + require TestLib; + unshift @INC, sub { + return unless $_[1] eq 'TestLib.pm'; + my $content = '1;'; + open my $fh, '<', \$content; + return $fh; + }; + is module_content('TestLib'), '1;', 'loads overridden module from sub @INC hook'; + is module_content('TestLib', { found => \%INC } ), $mod_content, 'found => \%INC loads mod as it was required'; + } +} + +done_testing; |