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 ) $/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 # FIXME - work around RT#114641
45 # Because *OF COURSE* when (questionable) unicode tests fail on < 5.8
46 # the answer is to make the entire module 5.8 only, instead of skipping
47 # the tests in question
48 # rjbs-- # thinly veiled passive aggressive bullshit
50 # The actual skip is needed because the use happens before 'package' had
51 # a chance to switch the namespace, so the shim thinks DBIC::Schema tried
53 return $res if $req eq '5.008';
55 # exclude everything where the current namespace does not match the called function
56 # (this works around very weird XS-induced require callstack corruption)
58 !$initial_inc_contents->{$req}
60 !$expected_dbic_deps->{$req}
64 $caller[0] =~ /^DBIx::Class/
66 (CORE::caller($up))[3] =~ /\Q$caller[0]/
68 local $stack{neutralize_override} = 1;
70 do 1 while CORE::caller(++$up);
72 require('Test/More.pm');
73 local $Test::Builder::Level = $up + 1;
74 Test::More::fail ("Unexpected require of '$req' by $caller[0] ($caller[1] line $caller[2])");
76 require('DBICTest/Util.pm');
77 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 $ENV{DBICTEST_ANFANG_DEFANG} = 1;
110 # make sure extras do not load even when this is set
111 $ENV{PERL_STRICTURES_EXTRA} = 1;
113 # add what we loaded so far
118 $initial_inc_contents->{$mod} = 1;
124 ### This is where the test starts
127 # checking base schema load, no storage no connection
129 register_lazy_loadable_requires(qw(
135 Devel::GlobalDestruction
148 Class::Accessor::Grouped
149 Class::C3::Componentised
152 require DBIx::Class::Schema;
153 assert_no_missing_expected_requires();
156 # check schema/storage instantiation with no connect
158 register_lazy_loadable_requires(qw(
161 Method::Generate::Accessor
162 Method::Generate::Constructor
167 my $s = DBIx::Class::Schema->connect('dbi:SQLite::memory:');
168 ok (! $s->storage->connected, 'no connection');
169 assert_no_missing_expected_requires();
172 # do something (deploy, insert)
174 register_lazy_loadable_requires(qw(
180 eval <<'EOP' or die $@;
182 package DBICTest::Result::Artist;
187 use base 'DBIx::Class::Core';
189 __PACKAGE__->table("artist");
191 __PACKAGE__->add_columns(
193 data_type => 'integer',
194 is_auto_increment => 1,
197 data_type => 'varchar',
202 data_type => 'integer',
212 __PACKAGE__->set_primary_key('artistid');
213 __PACKAGE__->add_unique_constraint(['name']);
214 __PACKAGE__->add_unique_constraint(u_nullable => [qw/charfield rank/]);
221 my $s = DBIx::Class::Schema->connect('dbi:SQLite::memory:');
223 $s->register_class( Artist => 'DBICTest::Result::Artist' );
225 $s->storage->dbh_do(sub {
226 $_[1]->do('CREATE TABLE artist (
227 "artistid" INTEGER PRIMARY KEY NOT NULL,
229 "rank" integer NOT NULL DEFAULT 13,
234 my $art = $s->resultset('Artist')->create({ name => \[ '?' => 'foo'], rank => 42 });
235 $art->discard_changes;
236 $art->update({ rank => 69, name => 'foo' });
237 $s->resultset('Artist')->all;
238 assert_no_missing_expected_requires();
242 # and do full DBICTest based populate() as well, just in case - shouldn't add new stuff
244 # DBICTest needs File::Spec, but older versions of Storable load it alread
245 # Instead of adding a contrived conditional, just preempt the testing entirely
251 my $s = DBICTest->init_schema;
252 is ($s->resultset('Artist')->find(1)->name, 'Caterwauler McCrae', 'Expected find() result');
256 # one final quiet guard to run at all times
257 END { assert_no_missing_expected_requires('quiet') };
259 sub register_lazy_loadable_requires {
260 local $Test::Builder::Level = $Test::Builder::Level + 1;
263 (my $modfn = "$mod.pm") =~ s!::!\/!g;
265 "Module $mod already loaded by require site(s):",
266 (map { "\t$_" } @{$require_sites->{$mod}}),
268 ) if $INC{$modfn} and !$initial_inc_contents->{$mod};
270 $expected_dbic_deps->{$mod}++
274 # check if anything we were expecting didn't actually load
275 sub assert_no_missing_expected_requires {
278 for my $mod (keys %$expected_dbic_deps) {
279 (my $modfn = "$mod.pm") =~ s/::/\//g;
281 "Expected DBIC core dependency '%s' never loaded - %s needs adjustment",
284 ) unless $INC{$modfn};
287 pass(sprintf 'All modules expected at %s line %s loaded by DBIC: %s',
290 join (', ', sort keys %$expected_dbic_deps ),