move d.pl to a sensible place so the MANIFEST picks it up
[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   system($^X, "-Mblib", "-MApp::FatPacker::Trace", $file);
19
20   open my $trace, "<", "fatpacker.trace";
21   my @traced = sort map { chomp; $_ } <$trace>;
22
23   is_deeply \@loaded, \@traced, "All expected modules loaded for $file";
24   unlink "fatpacker.trace";
25 }
26
27 test_trace("t/mod/a.pm" => ("t/mod/b.pm", "t/mod/c.pm"));
28
29 sub test_trace_stderr {
30   my($file, @loaded) = @_;
31   local $Test::Builder::Level = $Test::Builder::Level + 1;
32
33   system(join(' ',
34     $^X, "-Mblib", "-MApp::FatPacker::Trace", '--to-stderr', $file,
35     '>', 'fatpacker.trace', '2>&1'));
36
37   open my $trace, "<", "fatpacker.trace";
38   while(<$trace>) {
39     chomp;
40     my $load = $_;
41     @loaded = grep { $load ne $_ } @loaded;
42   }
43
44   ok !@loaded, "All expected modules loaded for $file";
45   unlink "fatpacker.trace";
46 }
47