File: 39load_namespaces_rt41083.t

package info (click to toggle)
libdbix-class-perl 0.082844-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,320 kB
  • sloc: perl: 27,215; sql: 322; sh: 29; makefile: 16
file content (63 lines) | stat: -rw-r--r-- 1,704 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use strict;
use warnings;

use lib 't/lib';
use DBICTest; # do not remove even though it is not used
use Test::More tests => 8;

sub _chk_warning {
  defined $_[0]?
    $_[0] !~ qr/We found ResultSet class '([^']+)' for '([^']+)', but it seems that you had already set '([^']+)' to use '([^']+)' instead/ :
    1
}

sub _chk_extra_sources_warning {
  my $p = qr/already has a source, use register_extra_source for additional sources/;
  defined $_[0]? $_[0] !~ /$p/ : 1;
}

sub _verify_sources {
  my @monikers = @_;
  is_deeply (
    [ sort DBICNSTest::RtBug41083->sources ],
    \@monikers,
    'List of resultsource registrations',
  );
}

{
  my $warnings;
  eval {
    local $SIG{__WARN__} = sub { $warnings .= shift };
    package DBICNSTest::RtBug41083;
    use base 'DBIx::Class::Schema';
    __PACKAGE__->load_namespaces(
      result_namespace => 'Result_A',
      resultset_namespace => 'ResultSet_A',
      default_resultset_class => 'ResultSet'
    );
  };

  ok(!$@) or diag $@;
  ok(_chk_warning($warnings), 'expected no resultset complaint');
  ok(_chk_extra_sources_warning($warnings), 'expected no extra sources complaint') or diag($warnings);

  _verify_sources (qw/A A::Sub/);
}

{
  my $warnings;
  eval {
    local $SIG{__WARN__} = sub { $warnings .= shift };
    package DBICNSTest::RtBug41083;
    use base 'DBIx::Class::Schema';
    __PACKAGE__->load_namespaces(
      default_resultset_class => 'ResultSet'
    );
  };
  ok(!$@) or diag $@;
  ok(_chk_warning($warnings), 'expected no resultset complaint') or diag $warnings;
  ok(_chk_extra_sources_warning($warnings), 'expected no extra sources complaint') or diag($warnings);

  _verify_sources (qw/A A::Sub Foo Foo::Sub/);
}