move load_optional_class into Class::C3::Componentised
[dbsrgits/DBIx-Class.git] / t / 103many_to_many_warning.t
index ff48590..a8f790a 100644 (file)
@@ -3,38 +3,54 @@ use warnings;
 use Test::More;
 
 use lib qw(t/lib);
+use Data::Dumper;
 
+plan ( ($] >= 5.009000 and $] < 5.010001)
+  ? (skip_all => 'warnings::register broken under 5.10: http://rt.perl.org/rt3/Public/Bug/Display.html?id=62522')
+  : (tests => 4)
+);
 
-our $no_warn = "";
-
-plan tests => 2;
 {
-  local $@; 
-  local $SIG{__WARN__} = sub { die @_ };
-  eval "@{[code()]}";
-  ok($@, "Warning triggered without relevant 'no warnings'");
+  my @w; 
+  local $SIG{__WARN__} = sub { push @w, @_ };
+  my $code = gen_code ( suffix => 1 );
+  eval "$code";
+  ok (! $@, 'Eval code without warnings suppression')
+    || diag $@;
+
+  ok ( (grep { $_ =~ /The many-to-many relationship bars is trying to create/ } @w), "Warning triggered without relevant 'no warnings'");
 }
 
 {
-  # Clean up the packages
-  delete $INC{'DBICTest/ManyToManyWarning.pm'};
-  delete $DBICTest::{"Schema::"};
-
-  $no_warn = "no warnings 'DBIx::Class::Relationship::ManyToMany';";
-  local $SIG{__WARN__} = sub { die @_ };
-  eval "@{[code()]}";
-  ok(!$@, "No Warning triggered with relevant 'no warnings'");
+  my @w; 
+  local $SIG{__WARN__} = sub { push @w, @_ };
+
+  my $code = gen_code ( suffix => 2, no_warn => 1 );
+  eval "$code";
+  ok (! $@, 'Eval code with warnings suppression')
+    || diag $@;
+
+  ok ( (not grep { $_ =~ /The many-to-many relationship bars is trying to create/ } @w), "No warning triggered with relevant 'no warnings'");
 }
 
-sub code {
-my $file = << "EOF";
+sub gen_code {
+
+  my $args = { @_ };
+  my $suffix = $args->{suffix};
+  my $no_warn = ( $args->{no_warn}
+    ? "no warnings 'DBIx::Class::Relationship::ManyToMany';"
+    : '',
+  );
+
+  return <<EOF;
 use strict;
 use warnings;
 
 {
   package #
-    DBICTest::Schema::Foo;
+    DBICTest::Schema::Foo${suffix};
   use base 'DBIx::Class::Core';
+
   __PACKAGE__->table('foo');
   __PACKAGE__->add_columns(
     'fooid' => {
@@ -45,13 +61,12 @@ use warnings;
   __PACKAGE__->set_primary_key('fooid');
 
 
-  __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar' => 'bar');
+  __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'bar');
   __PACKAGE__->many_to_many( foos => foo_to_bar => 'bar' );
-
 }
 {
   package #
-    DBICTest::Schema::FooToBar;
+    DBICTest::Schema::FooToBar${suffix};
 
   use base 'DBIx::Class::Core';
   __PACKAGE__->table('foo_to_bar');
@@ -63,13 +78,15 @@ use warnings;
       data_type => 'integer',
     },
   );
-  __PACKAGE__->belongs_to('foo' => 'DBICTest::Schema::Foo');
-  __PACKAGE__->belongs_to('bar' => 'DBICTest::Schema::Foo');
+  __PACKAGE__->belongs_to('foo' => 'DBICTest::Schema::Foo${suffix}');
+  __PACKAGE__->belongs_to('bar' => 'DBICTest::Schema::Foo${suffix}');
 }
 {
   package #
-    DBICTest::Schema::Bar;
+    DBICTest::Schema::Bar${suffix};
+
   use base 'DBIx::Class::Core';
+
   __PACKAGE__->table('bar');
   __PACKAGE__->add_columns(
     'barid' => {
@@ -78,14 +95,14 @@ use warnings;
     },
   );
 
-  use DBIx::Class::Relationship::ManyToMany;
-  $main::no_warn
+  ${no_warn}
   __PACKAGE__->set_primary_key('barid');
-  __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar' => 'foo');
+  __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'foo');
+
   __PACKAGE__->many_to_many( bars => foo_to_bar => 'foo' );
 
   sub add_to_bars {}
 }
 EOF
-  return $file;
+
 }