Skip to content

Commit

Permalink
Add diagnostics on compilation failure.
Browse files Browse the repository at this point in the history
Now you can know why it failed!  Makes heisenbugs so much easier to
track down.
  • Loading branch information
schwern committed Mar 14, 2014
1 parent 8538a78 commit 685ae5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/Test/Compile/Internal.pm
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Returns true if C<$file> compiles as a perl module.
=cut

sub pm_file_compiles {
my ($self,$file) = @_;
my ($self,$file,%args) = @_;

return $self->_run_closure(
sub{
Expand All @@ -186,7 +186,15 @@ sub pm_file_compiles {
$module =~ s![/\\]!::!g;
$module =~ s/\.pm$//;

return $module->require ? 1 : 0;
return 1 if $module->require;

$self->{test}->diag("Compilation of $module failed: $@")
unless $args{no_diag};
return 0;
}
else {
$self->{test}->diag("$file could not be found") unless $args{no_diag};
return 0;
}
}
);
Expand Down
4 changes: 2 additions & 2 deletions t/100-internal-pm-file-compiles.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ my $internal = Test::Compile::Internal->new();
my $yes = $internal->pm_file_compiles('t/scripts/Module.pm');
ok($yes, "Module.pm should compile");

my $no = $internal->pm_file_compiles('t/scripts/CVS/Ignore.pm');
my $no = $internal->pm_file_compiles('t/scripts/CVS/Ignore.pm', no_diag => 1);
ok(!$no, "Ignore.pm should not compile");

my $notfound = $internal->pm_file_compiles('t/scripts/NotFound.pm');
my $notfound = $internal->pm_file_compiles('t/scripts/NotFound.pm', no_diag => 1);
ok(!$notfound, "NotFound.pm should not compile");

note "Does not call import"; {
Expand Down

0 comments on commit 685ae5f

Please sign in to comment.