summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Etheridge <ether@cpan.org>2012-03-02 21:57:54 +0000
committerKaren Etheridge <ether@cpan.org>2013-06-21 21:25:08 -0700
commitda64122a3fb0c5c747fb88dfce9909285697cfc2 (patch)
treeaa7230be847eb789eef134c2889ed4fd93bcef00
parent8383bd1012327feb3823ac62222155d4f73cc6ce (diff)
downloaddist-checkconflicts-da64122a3fb0c5c747fb88dfce9909285697cfc2.tar.gz
dist-checkconflicts-da64122a3fb0c5c747fb88dfce9909285697cfc2.zip
fix for RT#75486: instead of silently ignoring conflicts that do not compile, issue a conflict warning
-rw-r--r--Changes2
-rw-r--r--lib/Dist/CheckConflicts.pm18
-rw-r--r--t/02-conflicts.t26
-rw-r--r--t/lib/02/Broken.pm3
-rw-r--r--t/lib/02/Foo/Conflicts/Broken.pm11
-rw-r--r--t/lib/02/Foo/Conflicts/Good.pm1
6 files changed, 54 insertions, 7 deletions
diff --git a/Changes b/Changes
index 899f79e..eb23219 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,8 @@
Revision history for Dist-CheckConflicts
{{$NEXT}}
+ - instead of silently ignoring conflicts that do not compile, issue a
+ conflict warning. (RT#75486, Karen Etheridge)
0.06 2013-06-21
- make the runtime conflict warnings optional, since i'm not sure how
diff --git a/lib/Dist/CheckConflicts.pm b/lib/Dist/CheckConflicts.pm
index 1fea9e2..393e586 100644
--- a/lib/Dist/CheckConflicts.pm
+++ b/lib/Dist/CheckConflicts.pm
@@ -11,6 +11,8 @@ our @EXPORT = our @EXPORT_OK = (
use Carp;
use List::MoreUtils 0.12 'first_index';
+use Class::Load 'try_load_class';
+use Module::Runtime 'module_notional_filename';
=head1 SYNOPSIS
@@ -131,7 +133,7 @@ sub import {
for my $conflict (keys %conflicts) {
(my $file = $conflict) =~ s{::}{/}g;
$file .= '.pm';
- if (exists $INC{$file}) {
+ if (exists $INC{module_notional_filename($conflict)}) {
_check_version([$for], $conflict);
}
}
@@ -266,18 +268,20 @@ sub calculate_conflicts {
my @ret;
+
CONFLICT:
for my $conflict (keys %conflicts) {
- {
- local $SIG{__WARN__} = sub { };
- eval "require $conflict; 1" or next CONFLICT;
- }
- my $installed = $conflict->VERSION;
+ my ($success, $error) = try_load_class($conflict);
+ my $file = module_notional_filename($conflict);
+ next if not $success and $error =~ /Can't locate \Q$file\E in \@INC/;
+
+ warn "Warning: $conflict did not compile" if not $success;
+ my $installed = $success ? $conflict->VERSION : 'unknown';
push @ret, {
package => $conflict,
installed => $installed,
required => $conflicts{$conflict},
- } if $installed le $conflicts{$conflict};
+ } if not $success or $installed le $conflicts{$conflict};
}
return sort { $a->{package} cmp $b->{package} } @ret;
diff --git a/t/02-conflicts.t b/t/02-conflicts.t
index 3d288a2..f59777f 100644
--- a/t/02-conflicts.t
+++ b/t/02-conflicts.t
@@ -3,6 +3,7 @@ use strict;
use warnings;
use Test::More;
use Test::Fatal;
+use Test::Warn;
use lib 't/lib/02';
{
@@ -69,4 +70,29 @@ use lib 't/lib/02';
);
}
+{
+ # conflicting module is utterly broken
+
+ use_ok('Foo::Conflicts::Broken');
+
+ my @conflicts;
+ warning_like { @conflicts = Foo::Conflicts::Broken->calculate_conflicts }
+ qr/Warning: Broken did not compile/,
+ 'Warning is issued when Broken fails to compile';
+
+ is_deeply(
+ \@conflicts,
+ [
+ { package => 'Broken', installed => 'unknown', required => '0.03' },
+ ],
+ "correct versions for all conflicts",
+ );
+
+ is(
+ exception { Foo::Conflicts::Broken->check_conflicts },
+ "Conflicts detected for Foo::Conflicts::Broken:\n Broken is version unknown, but must be greater than version 0.03\n",
+ "correct conflict error"
+ );
+}
+
done_testing;
diff --git a/t/lib/02/Broken.pm b/t/lib/02/Broken.pm
new file mode 100644
index 0000000..de400c3
--- /dev/null
+++ b/t/lib/02/Broken.pm
@@ -0,0 +1,3 @@
+package Broken;
+
+die 'this module is utterly broken';
diff --git a/t/lib/02/Foo/Conflicts/Broken.pm b/t/lib/02/Foo/Conflicts/Broken.pm
new file mode 100644
index 0000000..87043ae
--- /dev/null
+++ b/t/lib/02/Foo/Conflicts/Broken.pm
@@ -0,0 +1,11 @@
+package Foo::Conflicts::Broken;
+use strict;
+use warnings;
+
+use Dist::CheckConflicts
+ -conflicts => {
+ 'Broken' => '0.03',
+ 'NotInstalled' => '0.01',
+ };
+
+1;
diff --git a/t/lib/02/Foo/Conflicts/Good.pm b/t/lib/02/Foo/Conflicts/Good.pm
index f40a955..33d15de 100644
--- a/t/lib/02/Foo/Conflicts/Good.pm
+++ b/t/lib/02/Foo/Conflicts/Good.pm
@@ -7,6 +7,7 @@ use Dist::CheckConflicts
'Foo' => 0.01,
'Foo::Two' => 0.01,
'Foo::Three' => 0.01,
+ 'NotInstalled' => '0.01',
};
1;