Fix failures with DBICTEST_SQLITE_USE_FILE=1 introduced by 50261284
[dbsrgits/DBIx-Class.git] / t / 53lean_startup.t
index 0054f03..8af340a 100644 (file)
@@ -1,14 +1,17 @@
 # Use a require override instead of @INC munging (less common)
 # Do the override as early as possible so that CORE::require doesn't get compiled away
-# We will replace $req_override in a bit
+# We will add the hook in a bit, got to load some regular stuff
 
 my $test_hook;
 BEGIN {
-  $test_hook = sub {}; # noop at first
-  *CORE::GLOBAL::require = sub {
-    $test_hook->(@_);
-    CORE::require($_[0]);
-  };
+  unshift @INC, 't/lib';
+  require DBICTest::Util::OverrideRequire;
+
+  DBICTest::Util::OverrideRequire::override_global_require( sub {
+    my $res = $_[0]->();
+    $test_hook->($_[1]) if $test_hook;
+    return $res;
+  });
 }
 
 use strict;
@@ -16,8 +19,16 @@ use warnings;
 use Test::More;
 use Data::Dumper;
 
+# Package::Stash::XS is silly and fails if a require hook contains regular
+# expressions on perl < 5.8.7. Load the damned thing if the case
+BEGIN {
+  require Package::Stash if $] < 5.008007;
+}
+
+my $expected_core_modules;
+
 BEGIN {
-  my $core_modules = { map { $_ => 1 } qw/
+  $expected_core_modules = { map { $_ => 1 } qw/
     strict
     warnings
 
@@ -30,6 +41,7 @@ BEGIN {
 
     namespace::clean
     Try::Tiny
+    Context::Preserve
     Sub::Name
 
     Scalar::Util
@@ -44,6 +56,8 @@ BEGIN {
 
     Class::Accessor::Grouped
     Class::C3::Componentised
+    Moo
+    Sub::Quote
   /, $] < 5.010 ? ( 'Class::C3', 'MRO::Compat' ) : () }; # this is special-cased in DBIx/Class.pm
 
   $test_hook = sub {
@@ -70,7 +84,7 @@ BEGIN {
     # exclude everything where the current namespace does not match the called function
     # (this works around very weird XS-induced require callstack corruption)
     if (
-      !$core_modules->{$req}
+      !$expected_core_modules->{$req}
         and
       @caller
         and
@@ -80,7 +94,7 @@ BEGIN {
     ) {
       fail ("Unexpected require of '$req' by $caller[0] ($caller[1] line $caller[2])");
 
-      if ($ENV{TEST_VERBOSE}) { 
+      if ($ENV{TEST_VERBOSE}) {
         my ($i, @stack) = 1;
         while (my @f = caller($i++) ) {
           push @stack, \@f;
@@ -103,4 +117,21 @@ delete $ENV{$_} for qw/
 my $schema = DBICTest->init_schema;
 is ($schema->resultset('Artist')->next->name, 'Caterwauler McCrae');
 
+# check if anything we were expecting didn't actually load
+my $nl;
+for (keys %$expected_core_modules) {
+  my $mod = "$_.pm";
+  $mod =~ s/::/\//g;
+  unless ($INC{$mod}) {
+    my $err = sprintf "Expected DBIC core module %s never loaded - %s needs adjustment", $_, __FILE__;
+    if (DBICTest::RunMode->is_smoker or DBICTest::RunMode->is_author) {
+      fail ($err)
+    }
+    else {
+      diag "\n" unless $nl++;
+      diag $err;
+    }
+  }
+}
+
 done_testing;