Smarter todoification (this doesn't sound like a bad idea for CPAN in general)
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest.pm
index 42a691b..8b72950 100644 (file)
@@ -3,6 +3,69 @@ package # hide from PAUSE
 
 use strict;
 use warnings;
+
+# Needs to load 1st so that the correct SQLA::Test is picked up
+use DBIx::Class::_TempExtlib;
+
+# this noop trick initializes the STDOUT, so that the TAP::Harness
+# issued IO::Select->can_read calls (which are blocking wtf wtf wtf)
+# keep spinning and scheduling jobs
+# This results in an overall much smoother job-queue drainage, since
+# the Harness blocks less
+# (ideally this needs to be addressed in T::H, but a quick patchjob
+# broke everything so tabling it for now)
+BEGIN {
+  if ($INC{'Test/Builder.pm'}) {
+    local $| = 1;
+    print "#\n";
+  }
+}
+
+# This is a pretty good candidate for a standalone extraction (Test::AutoSkip?)
+BEGIN {
+  if (
+    ! $ENV{RELEASE_TESTING}
+      and
+    ! $ENV{AUTHOR_TESTING}
+      and
+    $0 =~ /^ (.*) x?t [\/\\] .+ \.t $/x
+      and
+    -f ( my $fn = "$1.auto_todo")
+  ) {
+    # fuck you win32
+    require File::Spec;
+    my $canonical_dollarzero = File::Spec::Unix->catpath(File::Spec->splitpath($0));
+
+    for my $t ( map {
+      ( $_ =~ /^ \s* ( [^\#\n]+ ) /x ) ? $1 : ()
+    } do { local @ARGV = $fn; <> } ) {
+      if ( $canonical_dollarzero =~ m! (?: \A | / ) \Q$t\E \z !x ) {
+        require Test::Builder;
+        Test::Builder->new->todo_start("Global todoification of '$t' specified in $fn");
+      }
+    }
+  }
+}
+
+use Module::Runtime 'module_notional_filename';
+BEGIN {
+  for my $mod (qw( DBIC::SqlMakerTest SQL::Abstract )) {
+    if ( $INC{ module_notional_filename($mod) } ) {
+      # FIXME this does not seem to work in BEGIN - why?!
+      #require Carp;
+      #$Carp::Internal{ (__PACKAGE__) }++;
+      #Carp::croak( __PACKAGE__ . " must be loaded before $mod" );
+
+      my ($fr, @frame) = 1;
+      while (@frame = caller($fr++)) {
+        last if $frame[1] !~ m|^t/lib/DBICTest|;
+      }
+
+      die __PACKAGE__ . " must be loaded before $mod (or modules using $mod) at $frame[1] line $frame[2]\n";
+    }
+  }
+}
+
 use DBICTest::RunMode;
 use DBICTest::Schema;
 use DBICTest::Util::LeakTracer qw/populate_weakregistry assert_empty_weakregistry/;