Try to fix test on 5.10
[dbsrgits/DBIx-Class.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 our $suffix = "";
10
11 plan tests => 2;
12 {
13   local $@; 
14   local $SIG{__WARN__} = sub { die @_ };
15   eval "@{[code()]}";
16   like($@, qr/The many-to-many relationship bars/,
17        "Warning triggered without relevant 'no warnings'");
18 }
19
20 {
21
22   $no_warn = "no warnings 'DBIx::Class::Relationship::ManyToMany';";
23   $suffix = "2";
24   local $SIG{__WARN__} = sub { die @_ };
25   eval "@{[code()]}";
26   unlike($@, qr/The many-to-many relationship bars.*?Bar2/s,
27          "No warning triggered with relevant 'no warnings'");
28 }
29
30 sub code {
31 my $file = << "EOF";
32 use strict;
33 use warnings;
34
35 {
36   package #
37     DBICTest::Schema::Foo$suffix;
38   use base 'DBIx::Class::Core';
39   __PACKAGE__->table('foo');
40   __PACKAGE__->add_columns(
41     'fooid' => {
42       data_type => 'integer',
43       is_auto_increment => 1,
44     },
45   );
46   __PACKAGE__->set_primary_key('fooid');
47
48
49   __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar$main::suffix' => 'bar');
50   __PACKAGE__->many_to_many( foos => foo_to_bar => 'bar' );
51
52 }
53 {
54   package #
55     DBICTest::Schema::FooToBar$suffix;
56
57   use base 'DBIx::Class::Core';
58   __PACKAGE__->table('foo_to_bar');
59   __PACKAGE__->add_columns(
60     'foo' => {
61       data_type => 'integer',
62     },
63     'bar' => {
64       data_type => 'integer',
65     },
66   );
67   __PACKAGE__->belongs_to('foo' => 'DBICTest::Schema::Foo$main::suffix');
68   __PACKAGE__->belongs_to('bar' => 'DBICTest::Schema::Foo$main::suffix');
69 }
70 {
71   package #
72     DBICTest::Schema::Bar$suffix;
73   use base 'DBIx::Class::Core';
74   __PACKAGE__->table('bar');
75   __PACKAGE__->add_columns(
76     'barid' => {
77       data_type => 'integer',
78       is_auto_increment => 1,
79     },
80   );
81
82   use DBIx::Class::Relationship::ManyToMany;
83   $main::no_warn
84   __PACKAGE__->set_primary_key('barid');
85   __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar$main::suffix' => 'foo');
86   __PACKAGE__->many_to_many( bars => foo_to_bar => 'foo' );
87
88   sub add_to_bars {}
89   die $main::suffix;
90 }
91 EOF
92   return $file;
93 }