Debian Codegraph @

t/unit/Test2/Harness/Runner/DepTracer.t

raw
1 use Test2::V0 -target => 'Test2::Harness::Runner::DepTracer';
2 # HARNESS-NO-PRELOAD
3
4 BEGIN { skip_all 'TODO' }
5
6 use ok $CLASS;
7
8 unshift @INC => 't/lib';
9
10 subtest require_hook => sub {
11 my $one = $CLASS->new;
12 isa_ok($one, [$CLASS], "Made a new instance");
13 ok(!$one->real_require, "Did not find an existing require hook");
14
15 my $two = $CLASS->new;
16 ref_is($one->my_require, $two->real_require, "Found the existing require hook");
17
18 require xxx;
19
20 is($one->loaded, {}, "Nothing tracked yet");
21
22 $one->start;
23
24 # use eval so we do not pre-bind the require
25 eval qq(#line ${ \__LINE__ } "${ \__FILE__ }"\nrequire baz; 1) or die $@;
26
27 is($one->loaded, {map { $_ => T } qw/baz.pm foo.pm bar.pm/}, "Loaded 3 modules");
28
29 is(
30 $one->dep_map, {
31 'baz.pm' => [['main', 't/Test2/Harness/Runner/DepTracer.t']],
32 'foo.pm' => [['baz', 't/lib/baz.pm'], ['bar', 't/lib/bar.pm']],
33 'bar.pm' => [['baz', 't/lib/baz.pm']],
34 },
35 "Built dep-map"
36 );
37
38 $one->stop;
39
40 eval "require Data::Dumper; 1" or die $@;
41
42 is($one->loaded, {map { $_ => T } qw/baz.pm foo.pm bar.pm/}, "Did not track Data::Dumper");
43
44 $one->clear_loaded;
45 $one->start;
46
47 eval "use 5.8.9; 1" or die $@;
48
49 is($one->loaded, {}, "Did not track from version import");
50 };
51
52 subtest inc_hook => sub {
53 my $one = $CLASS->new;
54 isa_ok($one, [$CLASS], "Made a new instance");
55 ok($one->real_require, "Did find an existing require hook");
56
57 my $two = $CLASS->new;
58 ref_is($one->my_require, $two->real_require, "Found the existing require hook");
59
60 require xxx;
61
62 is($one->loaded, {}, "Nothing tracked yet");
63
64 $one->start;
65
66 # use eval so we do not pre-bind the require
67 eval qq(#line ${ \__LINE__ } "${ \__FILE__ }"\nCORE::require('baz_core.pm'); 1) or die $@;
68
69 is($one->loaded, {map { $_ => T } qw/baz_core.pm foo_core.pm bar_core.pm/}, "Loaded 3 modules");
70
71 is(
72 $one->dep_map, {
73 'baz_core.pm' => [['main', 't/Test2/Harness/Runner/DepTracer.t']],
74 # The @INC hook is limited, it can catch hidden loads for watching,
75 # but it cannot trace deps when a thing is loaded more than once.
76 'foo_core.pm' => [['baz_core', 't/lib/baz_core.pm']], #, ['bar', 't/lib/bar_core.pm']],
77 'bar_core.pm' => [['baz_core', 't/lib/baz_core.pm']],
78 },
79 "Built dep-map"
80 );
81
82 $one->stop;
83
84 eval "CORE::require('yyy.pm'); 1" or die $@;
85
86 is($one->loaded, {map { $_ => T } qw/baz_core.pm foo_core.pm bar_core.pm/}, "Did not track yyy");
87
88 $one->clear_loaded;
89 $one->start;
90
91 eval "use 5.8.9; 1" or die $@;
92
93 is($one->loaded, {}, "Did not track from version import");
94 };
95
96
97 done_testing;