use inlined module hiding in tests
Graham Knop [Mon, 13 Feb 2017 06:29:15 +0000 (01:29 -0500)]
Test::Without::Module and Devel::Hide both handle repeated module
loading wrong.  They also generate error messages that aren't compatible
with Class::Load.

Also add some module hiding for 'Foo' and 'Bar', as they may exist
locally, breaking tests.

Makefile.PL
t/aggregate/unit_core_script_server-without_modules.t
t/class_traits.t
t/class_traits_CAR_bug.t

index 5a47d3e..5451d90 100644 (file)
@@ -120,7 +120,6 @@ author_requires(
   @author_requires,
   map {; $_ => 0 } qw(
   File::Copy::Recursive
-  Test::Without::Module
   Starman
   MooseX::Daemonize
   Test::NoTabs
index 0fdaa87..d6bbcaf 100644 (file)
@@ -10,26 +10,19 @@ BEGIN { $ENV{PACKAGE_STASH_IMPLEMENTATION} = 'PP' if $] < '5.008007' }
 use Test::More;
 use Try::Tiny;
 
-plan skip_all => "Need Test::Without::Module for this test"
-    unless try { require Test::Without::Module; 1 };
-
-Test::Without::Module->import(qw(
+my %hidden = map { (my $m = "$_.pm") =~ s{::}{/}g; $m => 1 } qw(
     Starman::Server
     Plack::Handler::Starman
     MooseX::Daemonize
     MooseX::Daemonize::Pid::File
     MooseX::Daemonize::Core
-));
-
-require "$Bin/../aggregate/unit_core_script_server.t";
+);
+local @INC = (sub {
+  return unless exists $hidden{$_[1]};
+  die "Can't locate $_[1] in \@INC (hidden)\n";
+}, @INC);
 
-Test::Without::Module->unimport(qw(
-    Starman::Server
-    Plack::Handler::Starman
-    MooseX::Daemonize
-    MooseX::Daemonize::Pid::File
-    MooseX::Daemonize::Core
-));
+do "$Bin/../aggregate/unit_core_script_server.t"
+  or die $@ || 'test returned false';
 
 1;
-
index edccea2..d6a0c50 100644 (file)
@@ -4,6 +4,17 @@ use Test::More;
 use Class::MOP;
 
 BEGIN {
+  my %hidden = map { (my $m = "$_.pm") =~ s{::}{/}g; $m => 1 } qw(
+    Foo
+    Bar
+  );
+  unshift @INC, sub {
+    return unless exists $hidden{$_[1]};
+    die "Can't locate $_[1] in \@INC (hidden)\n";
+  };
+}
+
+BEGIN {
   package TestRole;
   $INC{'TestRole'} = __FILE__;
   use Moose::Role;
@@ -30,7 +41,7 @@ BEGIN {
 
   sub c { 'c' }
 
-  package TestApp::TraitFor::Response::Bar; 
+  package TestApp::TraitFor::Response::Bar;
   $INC{'TestApp/TraitFor/Response/Bar.pm'} = __FILE__;
 
   use Moose::Role;
index d160e73..cc57bc1 100644 (file)
@@ -11,6 +11,17 @@ BEGIN {
 }
 
 BEGIN {
+  my %hidden = map { (my $m = "$_.pm") =~ s{::}{/}g; $m => 1 } qw(
+    Foo
+    Bar
+  );
+  unshift @INC, sub {
+    return unless exists $hidden{$_[1]};
+    die "Can't locate $_[1] in \@INC (hidden)\n";
+  };
+}
+
+BEGIN {
   package TestRole;
   $INC{'TestRole'} = __FILE__;
   use Moose::Role;