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
5 if ( $ENV{RELEASE_TESTING} ) {
6 require warnings and warnings->import;
7 require strict and strict->import;
11 my ($initial_inc_contents, $expected_dbic_deps, $require_sites, %stack);
13 unshift @INC, 't/lib';
14 require DBICTest::Util::OverrideRequire;
16 DBICTest::Util::OverrideRequire::override_global_require( sub {
19 return $res if $stack{neutralize_override};
27 do { @caller = CORE::caller($up++) } while (
29 # exclude our test suite, known "module require-rs" and eval frames
30 $caller[1] =~ / (?: \A | [\/\\] ) x?t [\/\\] /x
32 $caller[0] =~ /^ (?: base | parent | Class::C3::Componentised | Module::Inspector | Module::Runtime | DBIx::Class::Optional::Dependencies ) $/x
34 $caller[3] eq '(eval)',
38 push @{$require_sites->{$req}}, "$caller[1] line $caller[2]"
41 return $res if $req =~ /^DBIx::Class|^DBICTest::/;
43 # Some modules have a bare 'use $perl_version' as the first statement
44 # Since the use() happens before 'package' had a chance to switch
45 # the namespace, the shim thinks DBIC* tried to require this
46 return $res if $req =~ /^v?[0-9.]+$/;
49 !$initial_inc_contents->{$req}
51 !$expected_dbic_deps->{$req}
55 $caller[0] =~ /^DBIx::Class/
57 local $stack{neutralize_override} = 1;
59 # find last-most frame, to feed to T::B below
60 while( CORE::caller(++$up) ) { 1 }
62 require('Test/More.pm');
63 local $Test::Builder::Level = $up + 1;
65 # work around the trainwreck that is https://github.com/doy/package-stash-xs/pull/4
66 local $::TODO = 'sigh' if (
67 $INC{'Package/Stash/XS.pm'}
72 Test::More::fail ("Unexpected require of '$req' by $caller[0] ($caller[1] line $caller[2])");
75 require('DBICTest/Util.pm');
76 Test::More::diag( 'Require invoked' . DBICTest::Util::stacktrace() );
89 plan skip_all => 'A defined PERL5OPT may inject extra deps crashing this test'
92 plan skip_all => 'Presence of sitecustomize.pl may inject extra deps crashing this test'
93 if grep { $_ =~ m| \/ sitecustomize\.pl $ |x } keys %INC;
95 plan skip_all => 'Dependency load patterns are radically different before perl 5.10'
98 # these envvars *will* bring in more stuff than the baseline
101 DBIC_SHUFFLE_UNORDERED_RESULTSETS
103 DBICTEST_SQLITE_REVERSE_DEFAULT_ORDER
104 DBICTEST_VIA_REPLICATED
105 DBICTEST_DEBUG_CONCURRENCY_LOCKS
108 # ensures the checker won't be disabled in
109 # t/lib/DBICTest/BaseSchema.pm
110 $ENV{DBIC_ASSERT_NO_FAILING_SANITY_CHECKS} = 1;
112 $ENV{DBICTEST_ANFANG_DEFANG} = 1;
114 # make sure extras do not load even when this is set
115 $ENV{PERL_STRICTURES_EXTRA} = 1;
117 # add what we loaded so far
122 $initial_inc_contents->{$mod} = 1;
128 ### This is where the test starts
131 # checking base schema load, no storage no connection
133 register_lazy_loadable_requires(qw(
139 Devel::GlobalDestruction
152 Class::Accessor::Grouped
153 Class::C3::Componentised
156 # load Storable ourselves here - there are too many
157 # variations with DynaLoader and XSLoader making testing
158 # for it rather unstable
161 require DBIx::Class::Schema;
162 assert_no_missing_expected_requires();
165 # check schema/storage instantiation with no connect
167 register_lazy_loadable_requires(qw(
170 Method::Generate::Accessor
171 Method::Generate::Constructor
176 my $s = DBIx::Class::Schema->connect('dbi:SQLite::memory:');
177 ok (! $s->storage->connected, 'no connection');
178 assert_no_missing_expected_requires();
181 # do something (deploy, insert)
183 register_lazy_loadable_requires(qw(
190 eval <<'EOP' or die $@;
192 package DBICTest::Result::Artist;
197 use base 'DBIx::Class::Core';
199 __PACKAGE__->table("artist");
201 __PACKAGE__->add_columns(
203 data_type => 'integer',
204 is_auto_increment => 1,
207 data_type => 'varchar',
212 data_type => 'integer',
222 __PACKAGE__->set_primary_key('artistid');
223 __PACKAGE__->add_unique_constraint(['name']);
224 __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]);
231 my $s = DBIx::Class::Schema->connect('dbi:SQLite::memory:');
233 $s->register_class( Artist => 'DBICTest::Result::Artist' );
235 $s->storage->dbh_do(sub {
236 $_[1]->do('CREATE TABLE artist (
237 "artistid" INTEGER PRIMARY KEY NOT NULL,
239 "rank" integer NOT NULL DEFAULT 13,
244 my $art = $s->resultset('Artist')->create({ name => \[ '?' => 'foo'], rank => 42 });
245 $art->discard_changes;
246 $art->update({ rank => 69, name => 'foo' });
247 $s->resultset('Artist')->all;
248 assert_no_missing_expected_requires();
252 # and do full DBICTest based populate() as well, just in case - shouldn't add new stuff
254 # DBICTest needs File::Spec, but older versions of Storable load it alread
255 # Instead of adding a contrived conditional, just preempt the testing entirely
261 my $s = DBICTest->init_schema;
262 is ($s->resultset('Artist')->find(1)->name, 'Caterwauler McCrae', 'Expected find() result');
266 # one final quiet guard to run at all times
267 END { assert_no_missing_expected_requires('quiet') };
269 sub register_lazy_loadable_requires {
270 local $Test::Builder::Level = $Test::Builder::Level + 1;
273 (my $modfn = "$mod.pm") =~ s!::!\/!g;
275 "Module $mod already loaded by require site(s):",
276 (map { "\t$_" } @{$require_sites->{$mod}}),
278 ) if $INC{$modfn} and !$initial_inc_contents->{$mod};
280 $expected_dbic_deps->{$mod}++
284 # check if anything we were expecting didn't actually load
285 sub assert_no_missing_expected_requires {
288 for my $mod (keys %$expected_dbic_deps) {
289 (my $modfn = "$mod.pm") =~ s/::/\//g;
291 "Expected DBIC core dependency '%s' never loaded - %s needs adjustment",
294 ) unless $INC{$modfn};
297 pass(sprintf 'All modules expected at %s line %s loaded by DBIC: %s',
300 join (', ', sort keys %$expected_dbic_deps ),