1 # Use a require override instead of @INC munging (less common)
2 # Do the override as early as possible so that CORE::require doesn't get compiled away
4 my ($initial_inc_contents, $expected_dbic_deps, $require_sites);
6 # these envvars *will* bring in more stuff than the baseline
7 delete @ENV{qw(DBICTEST_SQLT_DEPLOY DBIC_TRACE)};
9 # make sure extras do not load even when this is set
10 $ENV{PERL_STRICTURES_EXTRA} = 1;
12 unshift @INC, 't/lib';
13 require DBICTest::Util::OverrideRequire;
15 DBICTest::Util::OverrideRequire::override_global_require( sub {
24 do { @caller = caller($up++) } while (
26 # exclude our test suite, known "module require-rs" and eval frames
27 $caller[1] =~ /^ t [\/\\] /x
29 $caller[0] =~ /^ (?: base | parent | Class::C3::Componentised | Module::Inspector | Module::Runtime ) $/x
31 $caller[3] eq '(eval)',
35 push @{$require_sites->{$req}}, "$caller[1] line $caller[2]"
38 return $res if $req =~ /^DBIx::Class|^DBICTest::/;
40 # exclude everything where the current namespace does not match the called function
41 # (this works around very weird XS-induced require callstack corruption)
43 !$initial_inc_contents->{$req}
45 !$expected_dbic_deps->{$req}
49 $caller[0] =~ /^DBIx::Class/
51 (caller($up))[3] =~ /\Q$caller[0]/
53 CORE::require('Test/More.pm');
54 Test::More::fail ("Unexpected require of '$req' by $caller[0] ($caller[1] line $caller[2])");
56 if ( $ENV{TEST_VERBOSE} or ! DBICTest::RunMode->is_plain ) {
57 CORE::require('DBICTest/Util.pm');
58 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 ### This is where the test starts
90 # checking base schema load, no storage no connection
92 register_lazy_loadable_requires(qw(
98 Devel::GlobalDestruction
112 Class::Accessor::Grouped
113 Class::C3::Componentised
120 require DBICTest::Schema;
121 assert_no_missing_expected_requires();
124 # check schema/storage instantiation with no connect
126 register_lazy_loadable_requires(qw(
129 Method::Generate::Accessor
130 Method::Generate::Constructor
135 my $s = DBICTest::Schema->connect('dbi:SQLite::memory:');
136 ok (! $s->storage->connected, 'no connection');
137 assert_no_missing_expected_requires();
140 # do something (deploy, insert)
142 register_lazy_loadable_requires(qw(
147 my $s = DBICTest::Schema->connect('dbi:SQLite::memory:');
148 $s->storage->dbh_do(sub {
149 $_[1]->do('CREATE TABLE artist (
150 "artistid" INTEGER PRIMARY KEY NOT NULL,
152 "rank" integer NOT NULL DEFAULT 13,
157 my $art = $s->resultset('Artist')->create({ name => \[ '?' => 'foo'], rank => 42 });
158 $art->discard_changes;
159 $art->update({ rank => 69, name => 'foo' });
160 assert_no_missing_expected_requires();
163 # and do full populate() as well, just in case - shouldn't add new stuff
165 local $ENV{DBICTEST_SQLITE_REVERSE_DEFAULT_ORDER};
167 # in general we do not want DBICTest to load before sqla, but it is
169 local $INC{'SQL/Abstract.pm'};
172 my $s = DBICTest->init_schema;
173 is ($s->resultset('Artist')->find(1)->name, 'Caterwauler McCrae');
174 assert_no_missing_expected_requires();
177 # make sure we never loaded any of the strictures XS bullshit
179 ok( ! exists $INC{ Module::Runtime::module_notional_filename($_) }, "$_ load never attempted" )
180 for qw(indirect multidimensional bareword::filehandles);
185 sub register_lazy_loadable_requires {
186 local $Test::Builder::Level = $Test::Builder::Level + 1;
189 (my $modfn = "$mod.pm") =~ s!::!\/!g;
191 "Module $mod already loaded by require site(s):",
192 (map { "\t$_" } @{$require_sites->{$mod}}),
194 ) if $INC{$modfn} and !$initial_inc_contents->{$mod};
196 $expected_dbic_deps->{$mod}++
200 # check if anything we were expecting didn't actually load
201 sub assert_no_missing_expected_requires {
203 for my $mod (keys %$expected_dbic_deps) {
204 (my $modfn = "$mod.pm") =~ s/::/\//g;
205 unless ($INC{$modfn}) {
206 my $err = sprintf "Expected DBIC core dependency '%s' never loaded - %s needs adjustment", $mod, __FILE__;
207 if (DBICTest::RunMode->is_smoker or DBICTest::RunMode->is_author) {
211 diag "\n" unless $nl->{$mod}++;
216 pass(sprintf 'All modules expected at %s line %s loaded by DBIC: %s',
219 join (', ', sort keys %$expected_dbic_deps ),