Make the many-to-many warning use warnings::register;
[dbsrgits/DBIx-Class-Historic.git] / t / 103many_to_many_warning.t
1 use strict;
2 use warnings;
3 use Test::More;
4
5 use lib qw(t/lib);
6
7
8 our $no_warn = "";
9
10 plan tests => 2;
11 {
12   local $@; 
13   local $SIG{__WARN__} = sub { die @_ };
14   eval "@{[code()]}";
15   ok($@, "Warning triggered without relevant 'no warnings'");
16 }
17
18 {
19   # Clean up the packages
20   delete $INC{'DBICTest/ManyToManyWarning.pm'};
21   delete $DBICTest::{"Schema::"};
22
23   $no_warn = "no warnings 'DBIx::Class::Relationship::ManyToMany';";
24   local $SIG{__WARN__} = sub { die @_ };
25   eval "@{[code()]}";
26   ok(!$@, "No Warning triggered with relevant 'no warnings'");
27 }
28
29 sub code {
30 my $file = << "EOF";
31 use strict;
32 use warnings;
33
34 {
35   package #
36     DBICTest::Schema::Foo;
37   use base 'DBIx::Class::Core';
38   __PACKAGE__->table('foo');
39   __PACKAGE__->add_columns(
40     'fooid' => {
41       data_type => 'integer',
42       is_auto_increment => 1,
43     },
44   );
45   __PACKAGE__->set_primary_key('fooid');
46
47
48   __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar' => 'bar');
49   __PACKAGE__->many_to_many( foos => foo_to_bar => 'bar' );
50
51 }
52 {
53   package #
54     DBICTest::Schema::FooToBar;
55
56   use base 'DBIx::Class::Core';
57   __PACKAGE__->table('foo_to_bar');
58   __PACKAGE__->add_columns(
59     'foo' => {
60       data_type => 'integer',
61     },
62     'bar' => {
63       data_type => 'integer',
64     },
65   );
66   __PACKAGE__->belongs_to('foo' => 'DBICTest::Schema::Foo');
67   __PACKAGE__->belongs_to('bar' => 'DBICTest::Schema::Foo');
68 }
69 {
70   package #
71     DBICTest::Schema::Bar;
72   use base 'DBIx::Class::Core';
73   __PACKAGE__->table('bar');
74   __PACKAGE__->add_columns(
75     'barid' => {
76       data_type => 'integer',
77       is_auto_increment => 1,
78     },
79   );
80
81   use DBIx::Class::Relationship::ManyToMany;
82   $main::no_warn
83   __PACKAGE__->set_primary_key('barid');
84   __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar' => 'foo');
85   __PACKAGE__->many_to_many( bars => foo_to_bar => 'foo' );
86
87   sub add_to_bars {}
88 }
89 EOF
90   return $file;
91 }