1 BEGIN { $ENV{DBICTEST_ANFANG_DEFANG} = 1 }
3 # Use a require override instead of @INC munging (less common)
4 # Do the override as early as possible so that CORE::require doesn't get compiled away
6 my ($initial_inc_contents, $expected_dbic_deps, $require_sites);
8 # these envvars *will* bring in more stuff than the baseline
9 delete @ENV{qw(DBICTEST_SQLT_DEPLOY DBIC_TRACE)};
11 # make sure extras do not load even when this is set
12 $ENV{PERL_STRICTURES_EXTRA} = 1;
14 unshift @INC, 't/lib';
15 require DBICTest::Util::OverrideRequire;
17 DBICTest::Util::OverrideRequire::override_global_require( sub {
26 do { @caller = caller($up++) } while (
28 # exclude our test suite, known "module require-rs" and eval frames
29 $caller[1] =~ /^ t [\/\\] /x
31 $caller[0] =~ /^ (?: base | parent | Class::C3::Componentised | Module::Inspector | Module::Runtime ) $/x
33 $caller[3] eq '(eval)',
37 push @{$require_sites->{$req}}, "$caller[1] line $caller[2]"
40 return $res if $req =~ /^DBIx::Class|^DBICTest::/;
42 # exclude everything where the current namespace does not match the called function
43 # (this works around very weird XS-induced require callstack corruption)
45 !$initial_inc_contents->{$req}
47 !$expected_dbic_deps->{$req}
51 $caller[0] =~ /^DBIx::Class/
53 (caller($up))[3] =~ /\Q$caller[0]/
55 CORE::require('Test/More.pm');
56 Test::More::fail ("Unexpected require of '$req' by $caller[0] ($caller[1] line $caller[2])");
58 CORE::require('DBICTest/Util.pm');
59 Test::More::diag( 'Require invoked' . DBICTest::Util::stacktrace() );
71 plan skip_all => 'A defined PERL5OPT may inject extra deps crashing this test'
74 plan skip_all => 'Dependency load patterns are radically different before perl 5.10'
77 # add what we loaded so far
82 $initial_inc_contents->{$mod} = 1;
87 delete $ENV{$_} for qw(
88 DBICTEST_VIA_REPLICATED
89 DBICTEST_DEBUG_CONCURRENCY_LOCKS
94 ### This is where the test starts
97 # checking base schema load, no storage no connection
99 register_lazy_loadable_requires(qw(
105 Devel::GlobalDestruction
120 Class::Accessor::Grouped
121 Class::C3::Componentised
125 require DBICTest::Schema;
126 assert_no_missing_expected_requires();
129 # check schema/storage instantiation with no connect
131 register_lazy_loadable_requires(qw(
134 Method::Generate::Accessor
135 Method::Generate::Constructor
139 my $s = DBICTest::Schema->connect('dbi:SQLite::memory:');
140 ok (! $s->storage->connected, 'no connection');
141 assert_no_missing_expected_requires();
144 # do something (deploy, insert)
146 register_lazy_loadable_requires(qw(
151 my $s = DBICTest::Schema->connect('dbi:SQLite::memory:');
152 $s->storage->dbh_do(sub {
153 $_[1]->do('CREATE TABLE artist (
154 "artistid" INTEGER PRIMARY KEY NOT NULL,
156 "rank" integer NOT NULL DEFAULT 13,
161 my $art = $s->resultset('Artist')->create({ name => \[ '?' => 'foo'], rank => 42 });
162 $art->discard_changes;
163 $art->update({ rank => 69, name => 'foo' });
164 assert_no_missing_expected_requires();
167 # and do full populate() as well, just in case - shouldn't add new stuff
169 local $ENV{DBICTEST_SQLITE_REVERSE_DEFAULT_ORDER};
171 # in general we do not want DBICTest to load before sqla, but it is
173 local $INC{'SQL/Abstract.pm'};
176 my $s = DBICTest->init_schema;
177 is ($s->resultset('Artist')->find(1)->name, 'Caterwauler McCrae');
178 assert_no_missing_expected_requires();
183 sub register_lazy_loadable_requires {
184 local $Test::Builder::Level = $Test::Builder::Level + 1;
187 (my $modfn = "$mod.pm") =~ s!::!\/!g;
189 "Module $mod already loaded by require site(s):",
190 (map { "\t$_" } @{$require_sites->{$mod}}),
192 ) if $INC{$modfn} and !$initial_inc_contents->{$mod};
194 $expected_dbic_deps->{$mod}++
198 # check if anything we were expecting didn't actually load
199 sub assert_no_missing_expected_requires {
201 for my $mod (keys %$expected_dbic_deps) {
202 (my $modfn = "$mod.pm") =~ s/::/\//g;
204 "Expected DBIC core dependency '%s' never loaded - %s needs adjustment",
207 ) unless $INC{$modfn};
209 pass(sprintf 'All modules expected at %s line %s loaded by DBIC: %s',
212 join (', ', sort keys %$expected_dbic_deps ),