From 7ff55144b9c6f9c4933f1b21cc04c1199e9f5de5 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 21 Nov 2010 17:43:09 -0600 Subject: allow using the dist name in the error message --- lib/Dist/CheckConflicts.pm | 17 +++++++--- t/03-dist.t | 70 +++++++++++++++++++++++++++++++++++++++++ t/lib/03/Bar.pm | 7 +++++ t/lib/03/Bar/Conflicts/Bad.pm | 14 +++++++++ t/lib/03/Bar/Conflicts/Bad2.pm | 14 +++++++++ t/lib/03/Bar/Conflicts/Bad3.pm | 11 +++++++ t/lib/03/Bar/Conflicts/Good.pm | 14 +++++++++ t/lib/03/Bar/Conflicts/Good2.pm | 14 +++++++++ t/lib/03/Bar/Conflicts/Good3.pm | 11 +++++++ t/lib/03/Bar/Three.pm | 7 +++++ t/lib/03/Bar/Two.pm | 7 +++++ t/lib/03/Foo.pm | 7 +++++ t/lib/03/Foo/Conflicts/Bad.pm | 13 ++++++++ t/lib/03/Foo/Conflicts/Good.pm | 13 ++++++++ t/lib/03/Foo/Three.pm | 7 +++++ t/lib/03/Foo/Two.pm | 7 +++++ 16 files changed, 229 insertions(+), 4 deletions(-) create mode 100644 t/03-dist.t create mode 100644 t/lib/03/Bar.pm create mode 100644 t/lib/03/Bar/Conflicts/Bad.pm create mode 100644 t/lib/03/Bar/Conflicts/Bad2.pm create mode 100644 t/lib/03/Bar/Conflicts/Bad3.pm create mode 100644 t/lib/03/Bar/Conflicts/Good.pm create mode 100644 t/lib/03/Bar/Conflicts/Good2.pm create mode 100644 t/lib/03/Bar/Conflicts/Good3.pm create mode 100644 t/lib/03/Bar/Three.pm create mode 100644 t/lib/03/Bar/Two.pm create mode 100644 t/lib/03/Foo.pm create mode 100644 t/lib/03/Foo/Conflicts/Bad.pm create mode 100644 t/lib/03/Foo/Conflicts/Good.pm create mode 100644 t/lib/03/Foo/Three.pm create mode 100644 t/lib/03/Foo/Two.pm diff --git a/lib/Dist/CheckConflicts.pm b/lib/Dist/CheckConflicts.pm index da9b859..ec87fc3 100644 --- a/lib/Dist/CheckConflicts.pm +++ b/lib/Dist/CheckConflicts.pm @@ -7,20 +7,22 @@ use List::MoreUtils 'first_index'; use Sub::Exporter; my $import = Sub::Exporter::build_exporter({ - exports => [ qw(conflicts check_conflicts calculate_conflicts) ], + exports => [ qw(conflicts check_conflicts calculate_conflicts dist) ], groups => { - default => [ qw(conflicts check_conflicts calculate_conflicts) ], + default => [ qw(conflicts check_conflicts calculate_conflicts dist) ], }, }); my %CONFLICTS; +my %DISTS; sub import { my $for = caller; - my ($conflicts, $alsos); + my ($conflicts, $alsos, $dist); ($conflicts, @_) = _strip_opt('-conflicts' => @_); ($alsos, @_) = _strip_opt('-also' => @_); + ($dist, @_) = _strip_opt('-dist' => @_); my %conflicts = %{ $conflicts || {} }; for my $also (@{ $alsos || [] }) { @@ -34,6 +36,7 @@ sub import { } $CONFLICTS{$for} = \%conflicts; + $DISTS{$for} = $dist || $for; goto $import; } @@ -56,12 +59,18 @@ sub conflicts { return %{ $CONFLICTS{ $package } }; } +sub dist { + my $package = shift; + return $DISTS{ $package }; +} + sub check_conflicts { my $package = shift; + my $dist = $package->dist; my @conflicts = $package->calculate_conflicts; return unless @conflicts; - my $err = "Conflicts detected for $package:\n"; + my $err = "Conflicts detected for $dist:\n"; for my $conflict (@conflicts) { $err .= " $conflict->{package} is version " . "$conflict->{installed}, but must be greater than version " diff --git a/t/03-dist.t b/t/03-dist.t new file mode 100644 index 0000000..a9555b5 --- /dev/null +++ b/t/03-dist.t @@ -0,0 +1,70 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Fatal; +use lib 't/lib/03'; + +{ + use_ok('Foo::Conflicts::Good'); + is_deeply( + [ Foo::Conflicts::Good->calculate_conflicts ], + [], + "correct versions for all conflicts", + ); + is( + exception { Foo::Conflicts::Good->check_conflicts }, + undef, + "no conflict error" + ); +} + +{ + use_ok('Foo::Conflicts::Bad'); + is_deeply( + [ Foo::Conflicts::Bad->calculate_conflicts ], + [ + { package => 'Foo', installed => '0.02', required => '0.03' }, + { package => 'Foo::Two', installed => '0.02', required => '0.02' }, + ], + "correct versions for all conflicts", + ); + is( + exception { Foo::Conflicts::Bad->check_conflicts }, + "Conflicts detected for Foo:\n Foo is version 0.02, but must be greater than version 0.03\n Foo::Two is version 0.02, but must be greater than version 0.02\n", + "correct conflict error" + ); +} + +{ + use_ok('Bar::Conflicts::Good'); + is_deeply( + [ Bar::Conflicts::Good->calculate_conflicts ], + [], + "correct versions for all conflicts", + ); + is( + exception { Bar::Conflicts::Good->check_conflicts }, + undef, + "no conflict error" + ); +} + +{ + use_ok('Bar::Conflicts::Bad'); + is_deeply( + [ Bar::Conflicts::Bad->calculate_conflicts ], + [ + { package => 'Bar', installed => '0.02', required => '0.03' }, + { package => 'Bar::Two', installed => '0.02', required => '0.02' }, + ], + "correct versions for all conflicts", + ); + is( + exception { Bar::Conflicts::Bad->check_conflicts }, + "Conflicts detected for Bar:\n Bar is version 0.02, but must be greater than version 0.03\n Bar::Two is version 0.02, but must be greater than version 0.02\n", + "correct conflict error" + ); +} + +done_testing; diff --git a/t/lib/03/Bar.pm b/t/lib/03/Bar.pm new file mode 100644 index 0000000..0ce51ad --- /dev/null +++ b/t/lib/03/Bar.pm @@ -0,0 +1,7 @@ +package Bar; +use strict; +use warnings; + +our $VERSION = 0.02; + +1; diff --git a/t/lib/03/Bar/Conflicts/Bad.pm b/t/lib/03/Bar/Conflicts/Bad.pm new file mode 100644 index 0000000..af25aab --- /dev/null +++ b/t/lib/03/Bar/Conflicts/Bad.pm @@ -0,0 +1,14 @@ +package Bar::Conflicts::Bad; +use strict; +use warnings; + +use Dist::CheckConflicts + -dist => 'Bar', + -conflicts => { + 'Bar' => '0.03', + }, + -also => [ + 'Bar::Conflicts::Bad2', + ]; + +1; diff --git a/t/lib/03/Bar/Conflicts/Bad2.pm b/t/lib/03/Bar/Conflicts/Bad2.pm new file mode 100644 index 0000000..c4f1c1a --- /dev/null +++ b/t/lib/03/Bar/Conflicts/Bad2.pm @@ -0,0 +1,14 @@ +package Bar::Conflicts::Bad2; +use strict; +use warnings; + +use Dist::CheckConflicts + -dist => 'Bar', + -conflicts => { + 'Bar::Two' => '0.02', + }, + -also => [ + 'Bar::Conflicts::Bad3', + ]; + +1; diff --git a/t/lib/03/Bar/Conflicts/Bad3.pm b/t/lib/03/Bar/Conflicts/Bad3.pm new file mode 100644 index 0000000..be23e3c --- /dev/null +++ b/t/lib/03/Bar/Conflicts/Bad3.pm @@ -0,0 +1,11 @@ +package Bar::Conflicts::Bad3; +use strict; +use warnings; + +use Dist::CheckConflicts + -dist => 'Bar', + -conflicts => { + 'Bar::Three' => '0.01', + }; + +1; diff --git a/t/lib/03/Bar/Conflicts/Good.pm b/t/lib/03/Bar/Conflicts/Good.pm new file mode 100644 index 0000000..cd64e57 --- /dev/null +++ b/t/lib/03/Bar/Conflicts/Good.pm @@ -0,0 +1,14 @@ +package Bar::Conflicts::Good; +use strict; +use warnings; + +use Dist::CheckConflicts + -dist => 'Bar', + -conflicts => { + 'Bar' => '0.01', + }, + -also => [ + 'Bar::Conflicts::Good2', + ]; + +1; diff --git a/t/lib/03/Bar/Conflicts/Good2.pm b/t/lib/03/Bar/Conflicts/Good2.pm new file mode 100644 index 0000000..ed98ddc --- /dev/null +++ b/t/lib/03/Bar/Conflicts/Good2.pm @@ -0,0 +1,14 @@ +package Bar::Conflicts::Good2; +use strict; +use warnings; + +use Dist::CheckConflicts + -dist => 'Bar', + -conflicts => { + 'Bar::Two' => '0.01', + }, + -also => [ + 'Bar::Conflicts::Good3', + ]; + +1; diff --git a/t/lib/03/Bar/Conflicts/Good3.pm b/t/lib/03/Bar/Conflicts/Good3.pm new file mode 100644 index 0000000..7bb0943 --- /dev/null +++ b/t/lib/03/Bar/Conflicts/Good3.pm @@ -0,0 +1,11 @@ +package Bar::Conflicts::Good3; +use strict; +use warnings; + +use Dist::CheckConflicts + -dist => 'Bar', + -conflicts => { + 'Bar::Three' => '0.01', + }; + +1; diff --git a/t/lib/03/Bar/Three.pm b/t/lib/03/Bar/Three.pm new file mode 100644 index 0000000..8c304fe --- /dev/null +++ b/t/lib/03/Bar/Three.pm @@ -0,0 +1,7 @@ +package Bar::Three; +use strict; +use warnings; + +our $VERSION = 0.02; + +1; diff --git a/t/lib/03/Bar/Two.pm b/t/lib/03/Bar/Two.pm new file mode 100644 index 0000000..172ad51 --- /dev/null +++ b/t/lib/03/Bar/Two.pm @@ -0,0 +1,7 @@ +package Bar::Two; +use strict; +use warnings; + +our $VERSION = 0.02; + +1; diff --git a/t/lib/03/Foo.pm b/t/lib/03/Foo.pm new file mode 100644 index 0000000..9660e6d --- /dev/null +++ b/t/lib/03/Foo.pm @@ -0,0 +1,7 @@ +package Foo; +use strict; +use warnings; + +our $VERSION = 0.02; + +1; diff --git a/t/lib/03/Foo/Conflicts/Bad.pm b/t/lib/03/Foo/Conflicts/Bad.pm new file mode 100644 index 0000000..22905ee --- /dev/null +++ b/t/lib/03/Foo/Conflicts/Bad.pm @@ -0,0 +1,13 @@ +package Foo::Conflicts::Bad; +use strict; +use warnings; + +use Dist::CheckConflicts + -dist => 'Foo', + -conflicts => { + 'Foo' => 0.03, + 'Foo::Two' => 0.02, + 'Foo::Three' => 0.01, + }; + +1; diff --git a/t/lib/03/Foo/Conflicts/Good.pm b/t/lib/03/Foo/Conflicts/Good.pm new file mode 100644 index 0000000..553c698 --- /dev/null +++ b/t/lib/03/Foo/Conflicts/Good.pm @@ -0,0 +1,13 @@ +package Foo::Conflicts::Good; +use strict; +use warnings; + +use Dist::CheckConflicts + -dist => 'Foo', + -conflicts => { + 'Foo' => 0.01, + 'Foo::Two' => 0.01, + 'Foo::Three' => 0.01, + }; + +1; diff --git a/t/lib/03/Foo/Three.pm b/t/lib/03/Foo/Three.pm new file mode 100644 index 0000000..b180934 --- /dev/null +++ b/t/lib/03/Foo/Three.pm @@ -0,0 +1,7 @@ +package Foo::Three; +use strict; +use warnings; + +our $VERSION = 0.02; + +1; diff --git a/t/lib/03/Foo/Two.pm b/t/lib/03/Foo/Two.pm new file mode 100644 index 0000000..7a1daff --- /dev/null +++ b/t/lib/03/Foo/Two.pm @@ -0,0 +1,7 @@ +package Foo::Two; +use strict; +use warnings; + +our $VERSION = 0.02; + +1; -- cgit v1.2.3-54-g00ecf