From da64122a3fb0c5c747fb88dfce9909285697cfc2 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 2 Mar 2012 21:57:54 +0000 Subject: fix for RT#75486: instead of silently ignoring conflicts that do not compile, issue a conflict warning --- Changes | 2 ++ lib/Dist/CheckConflicts.pm | 18 +++++++++++------- t/02-conflicts.t | 26 ++++++++++++++++++++++++++ t/lib/02/Broken.pm | 3 +++ t/lib/02/Foo/Conflicts/Broken.pm | 11 +++++++++++ t/lib/02/Foo/Conflicts/Good.pm | 1 + 6 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 t/lib/02/Broken.pm create mode 100644 t/lib/02/Foo/Conflicts/Broken.pm 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; -- cgit v1.2.3