0021597d7485818ec2f581eee0c0fb3826183b6c
[p5sagit/App-FatPacker.git] / t / trace.t
1 #!perl
2 use strict;
3 use warnings FATAL => 'all';
4 use Test::More qw(no_plan);
5
6 test_trace("t/mod/a.pm" => ("t/mod/b.pm", "t/mod/c.pm"));
7 test_trace("t/mod/b.pm" => ("t/mod/c.pm"));
8 test_trace("t/mod/c.pm" => ());
9 test_trace("t/mod/d.pl" => ("t/mod/d.pm"));
10
11 # Attempts to conditionally load a module that isn't present
12 test_trace("t/mod/cond.pm" => ());
13
14 sub test_trace {
15   my($file, @loaded) = @_;
16   local $Test::Builder::Level = $Test::Builder::Level + 1;
17
18   unlink "fatpacker.trace";
19   system($^X, "-Mblib", "-MApp::FatPacker::Trace", $file);
20
21   open my $trace, "<", "fatpacker.trace";
22   my @traced = sort map { chomp; $_ } <$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