b844f189382c35a99a74e2d7de8097c57e1a4595
[p5sagit/App-FatPacker.git] / t / trace.t
1 use strict;
2 use warnings FATAL => 'all';
3 use Test::More qw(no_plan);
4
5 test_trace("t/mod/a.pm" => ("t/mod/b.pm", "t/mod/c.pm"));
6 test_trace("t/mod/b.pm" => ("t/mod/c.pm"));
7 test_trace("t/mod/c.pm" => ());
8 test_trace("t/mod/d.pl" => ("t/mod/d.pm"));
9
10 # Attempts to conditionally load a module that isn't present
11 test_trace("t/mod/cond.pm" => ());
12
13 sub test_trace {
14   my($file, @loaded) = @_;
15   local $Test::Builder::Level = $Test::Builder::Level + 1;
16
17   unlink "fatpacker.trace";
18   system($^X, "-Mblib", "-MApp::FatPacker::Trace", $file);
19
20   open my $trace, "<", "fatpacker.trace";
21   my @traced = sort map { chomp; $_ } <$trace>;
22   close $trace;
23
24   is_deeply \@traced, \@loaded, "All expected modules loaded for $file";
25   unlink "fatpacker.trace";
26 }
27
28 test_trace("t/mod/a.pm" => ("t/mod/b.pm", "t/mod/c.pm"));
29
30 sub test_trace_stderr {
31   my($file, @loaded) = @_;
32   local $Test::Builder::Level = $Test::Builder::Level + 1;
33
34   system(join(' ',
35     $^X, "-Mblib", "-MApp::FatPacker::Trace", '--to-stderr', $file,
36     '>', 'fatpacker.trace', '2>&1'));
37
38   open my $trace, "<", "fatpacker.trace";
39   while(<$trace>) {
40     chomp;
41     my $load = $_;
42     @loaded = grep { $load ne $_ } @loaded;
43   }
44
45   ok !@loaded, "All expected modules loaded for $file";
46   unlink "fatpacker.trace";
47 }
48