X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F103many_to_many_warning.t;h=f2944b4462bb9ff55df16c0ac18b0df5986531f7;hb=5cbe5b1216f07b5e329f493bd8bdfa5b0aa0f5eb;hp=c316820b2f970cc310a8307a0f24870257720114;hpb=d81b27717bde480b144014669f66f3438dc310dd;p=dbsrgits%2FDBIx-Class.git diff --git a/t/103many_to_many_warning.t b/t/103many_to_many_warning.t index c316820..f2944b4 100644 --- a/t/103many_to_many_warning.t +++ b/t/103many_to_many_warning.t @@ -3,40 +3,40 @@ use warnings; use Test::More; use lib qw(t/lib); -use Data::Dumper; +use DBICTest; -plan tests => 2; +plan tests => 4; +my $exp_warn = qr/The many-to-many relationship 'bars' is trying to create/; { - my @w; - local $SIG{__WARN__} = sub { push @w, @_ }; - + my @w; + local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] }; 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'"); + ok (@w, "Warning triggered without DBIC_OVERWRITE_HELPER_METHODS_OK"); } { - my @w; - local $SIG{__WARN__} = sub { push @w, @_ }; + my @w; + local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] }; - my $code = gen_code ( suffix => 2, no_warn => 1 ); - eval "$code"; + my $code = gen_code ( suffix => 2 ); -diag Dumper \@w; + local $ENV{DBIC_OVERWRITE_HELPER_METHODS_OK} = 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'"); + ok (! @w, "No warning triggered with DBIC_OVERWRITE_HELPER_METHODS_OK"); } sub gen_code { my $args = { @_ }; my $suffix = $args->{suffix}; - my $no_warn = ( $args->{no_warn} - ? "no warnings 'DBIx::Class::Relationship::ManyToMany';" - : '', - ); return <table('foo'); __PACKAGE__->add_columns( 'fooid' => { @@ -81,6 +82,7 @@ use warnings; DBICTest::Schema::Bar${suffix}; use base 'DBIx::Class::Core'; + __PACKAGE__->table('bar'); __PACKAGE__->add_columns( 'barid' => { @@ -89,7 +91,6 @@ use warnings; }, ); - ${no_warn} __PACKAGE__->set_primary_key('barid'); __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'foo');