Cleanup shebang lines of all maint/example scripts, remove from tests entirely
[dbsrgits/DBIx-Class.git] / t / 39load_namespaces_rt41083.t
1 use strict;
2 use warnings;
3
4 use lib 't/lib';
5 use DBICTest; # do not remove even though it is not used 
6 use Test::More tests => 8;
7
8 sub _chk_warning {
9   defined $_[0]?
10     $_[0] !~ qr/We found ResultSet class '([^']+)' for '([^']+)', but it seems that you had already set '([^']+)' to use '([^']+)' instead/ :
11     1
12 }
13
14 sub _chk_extra_sources_warning {
15   my $p = qr/already has a source, use register_extra_source for additional sources/;
16   defined $_[0]? $_[0] !~ /$p/ : 1;
17 }
18
19 sub _verify_sources {
20   my @monikers = @_;
21   is_deeply (
22     [ sort DBICNSTest::RtBug41083->sources ],
23     \@monikers,
24     'List of resultsource registrations',
25   );
26 }
27
28 {
29   my $warnings;
30   eval {
31     local $SIG{__WARN__} = sub { $warnings .= shift };
32     package DBICNSTest::RtBug41083;
33     use base 'DBIx::Class::Schema';
34     __PACKAGE__->load_namespaces(
35       result_namespace => 'Schema_A',
36       resultset_namespace => 'ResultSet_A',
37       default_resultset_class => 'ResultSet'
38     );
39   };
40
41   ok(!$@) or diag $@;
42   ok(_chk_warning($warnings), 'expected no resultset complaint');
43   ok(_chk_extra_sources_warning($warnings), 'expected no extra sources complaint') or diag($warnings);
44
45   _verify_sources (qw/A A::Sub/);
46 }
47
48 {
49   my $warnings;
50   eval {
51     local $SIG{__WARN__} = sub { $warnings .= shift };
52     package DBICNSTest::RtBug41083;
53     use base 'DBIx::Class::Schema';
54     __PACKAGE__->load_namespaces(
55       result_namespace => 'Schema',
56       resultset_namespace => 'ResultSet',
57       default_resultset_class => 'ResultSet'
58     );
59   };
60   ok(!$@) or diag $@;
61   ok(_chk_warning($warnings), 'expected no resultset complaint') or diag $warnings;
62   ok(_chk_extra_sources_warning($warnings), 'expected no extra sources complaint') or diag($warnings);
63
64   _verify_sources (qw/A A::Sub Foo Foo::Sub/);
65 }