diff options
author | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2012-05-31 20:08:13 +0100 |
---|---|---|
committer | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2012-06-15 14:33:49 +0100 |
commit | 2dde78c805d5b8715c7194600056f758aa51f982 (patch) | |
tree | f215436c77659c1fec8cd1246fa0d07f831b9940 /cpan/CPAN-Meta/t | |
parent | b6ae0ea7f180d433b705f6494697c84e9cf6010f (diff) | |
download | perl-2dde78c805d5b8715c7194600056f758aa51f982.tar.gz |
Updated CPAN-Meta to CPAN version 2.120921
[DELTA]
2.120921 2012-04-01 15:20:24 Europe/Paris
[REMOVED]
- CPAN::Meta::Requirements has been split out into its own distribution
so it can be used by CPAN.pm without requiring all of CPAN::Meta
2.120920 2012-04-01 11:30:43 Europe/Paris
[ADDED]
- CPAN::Meta::Requirements now has a 'requirements_for_module' method
to retrieve a version requirements string for a specific module
[Leon Timmermans]
[OTHER]
- Parse::CPAN::Meta prerequisite bumped to 1.4403
- JSON::PP prerequisites bumped to 2.27200
- CPAN::Meta::YAML prerequisite bumped to 0.008
2.120900 2012-03-30 13:15:15 Europe/Paris
[BUGFIX]
- CPAN::Meta::Requirements now treats undef requirements given to
from_string_hash() as '0' and warns about it; add_string_requirements()
dies if it does not get a requirements string to parse
Diffstat (limited to 'cpan/CPAN-Meta/t')
-rw-r--r-- | cpan/CPAN-Meta/t/accepts.t | 29 | ||||
-rw-r--r-- | cpan/CPAN-Meta/t/bad_version_hook.t | 49 | ||||
-rw-r--r-- | cpan/CPAN-Meta/t/basic.t | 224 | ||||
-rw-r--r-- | cpan/CPAN-Meta/t/finalize.t | 91 | ||||
-rw-r--r-- | cpan/CPAN-Meta/t/from-hash.t | 48 | ||||
-rw-r--r-- | cpan/CPAN-Meta/t/merge.t | 136 | ||||
-rw-r--r-- | cpan/CPAN-Meta/t/prereqs.t | 1 | ||||
-rw-r--r-- | cpan/CPAN-Meta/t/strings.t | 19 |
8 files changed, 19 insertions, 578 deletions
diff --git a/cpan/CPAN-Meta/t/accepts.t b/cpan/CPAN-Meta/t/accepts.t deleted file mode 100644 index 3456394873..0000000000 --- a/cpan/CPAN-Meta/t/accepts.t +++ /dev/null @@ -1,29 +0,0 @@ -use strict; -use warnings; - -use CPAN::Meta::Requirements; - -use Test::More 0.88; - -{ - my $req = CPAN::Meta::Requirements->new->add_minimum(Foo => 1); - - ok( $req->accepts_module(Foo => 1)); - ok(! $req->accepts_module(Foo => 0)); -} - -{ - my $req = CPAN::Meta::Requirements->new->add_maximum(Foo => 1); - - ok( $req->accepts_module(Foo => 1)); - ok(! $req->accepts_module(Foo => 2)); -} - -{ - my $req = CPAN::Meta::Requirements->new->add_exclusion(Foo => 1); - - ok( $req->accepts_module(Foo => 0)); - ok(! $req->accepts_module(Foo => 1)); -} - -done_testing; diff --git a/cpan/CPAN-Meta/t/bad_version_hook.t b/cpan/CPAN-Meta/t/bad_version_hook.t deleted file mode 100644 index 4b7c8c0d78..0000000000 --- a/cpan/CPAN-Meta/t/bad_version_hook.t +++ /dev/null @@ -1,49 +0,0 @@ -use strict; -use warnings; - -use CPAN::Meta::Requirements; -use version; - -use Test::More 0.88; - -sub dies_ok (&@) { - my ($code, $qr, $comment) = @_; - - my $lived = eval { $code->(); 1 }; - - if ($lived) { - fail("$comment: did not die"); - } else { - like($@, $qr, $comment); - } -} - -sub _fixit { return version->new(42) } - -{ - my $req = CPAN::Meta::Requirements->new( {bad_version_hook => \&_fixit} ); - - $req->add_minimum('Foo::Bar' => 10); - $req->add_minimum('Foo::Baz' => 'invalid_version'); - - is_deeply( - $req->as_string_hash, - { - 'Foo::Bar' => 10, - 'Foo::Baz' => 42, - }, - "hook fixes invalid version", - ); -} - -{ - my $req = CPAN::Meta::Requirements->new( {bad_version_hook => sub { 0 }} ); - - dies_ok { $req->add_minimum('Foo::Baz' => 'invalid_version') } - qr/Invalid version/, - "dies if hook doesn't return version object"; - -} - - -done_testing; diff --git a/cpan/CPAN-Meta/t/basic.t b/cpan/CPAN-Meta/t/basic.t deleted file mode 100644 index 81061b5e0d..0000000000 --- a/cpan/CPAN-Meta/t/basic.t +++ /dev/null @@ -1,224 +0,0 @@ -use strict; -use warnings; - -use CPAN::Meta::Requirements; - -use Test::More 0.88; - -sub dies_ok (&@) { - my ($code, $qr, $comment) = @_; - - my $lived = eval { $code->(); 1 }; - - if ($lived) { - fail("$comment: did not die"); - } else { - like($@, $qr, $comment); - } -} - -{ - my $req = CPAN::Meta::Requirements->new; - - $req->add_minimum('Foo::Bar' => 10); - $req->add_minimum('Foo::Bar' => 0); - $req->add_minimum('Foo::Bar' => 2); - - $req->add_minimum('Foo::Baz' => version->declare('v1.2.3')); - - $req->add_minimum('Foo::Undef' => undef); - - is_deeply( - $req->as_string_hash, - { - 'Foo::Bar' => 10, - 'Foo::Baz' => 'v1.2.3', - 'Foo::Undef' => 0, - }, - "some basic minimums", - ); - - ok($req->is_simple, "just minimums? simple"); -} - -{ - my $req = CPAN::Meta::Requirements->new; - $req->add_maximum(Foo => 1); - is_deeply($req->as_string_hash, { Foo => '<= 1' }, "max only"); - - ok(! $req->is_simple, "maximums? not simple"); -} - -{ - my $req = CPAN::Meta::Requirements->new; - $req->add_exclusion(Foo => 1); - $req->add_exclusion(Foo => 2); - - # Why would you ever do this?? -- rjbs, 2010-02-20 - is_deeply($req->as_string_hash, { Foo => '!= 1, != 2' }, "excl only"); -} - -{ - my $req = CPAN::Meta::Requirements->new; - - $req->add_minimum(Foo => 1); - $req->add_maximum(Foo => 2); - - is_deeply( - $req->as_string_hash, - { - Foo => '>= 1, <= 2', - }, - "min and max", - ); - - $req->add_maximum(Foo => 3); - - is_deeply( - $req->as_string_hash, - { - Foo => '>= 1, <= 2', - }, - "exclusions already outside range do not matter", - ); - - $req->add_exclusion(Foo => 1.5); - - is_deeply( - $req->as_string_hash, - { - Foo => '>= 1, <= 2, != 1.5', - }, - "exclusions", - ); - - $req->add_minimum(Foo => 1.6); - - is_deeply( - $req->as_string_hash, - { - Foo => '>= 1.6, <= 2', - }, - "exclusions go away when made irrelevant", - ); -} - -{ - my $req = CPAN::Meta::Requirements->new; - - $req->add_minimum(Foo => 1); - $req->add_exclusion(Foo => 1); - $req->add_maximum(Foo => 2); - - is_deeply( - $req->as_string_hash, - { - Foo => '> 1, <= 2', - }, - "we can exclude an endpoint", - ); -} - -{ - my $req = CPAN::Meta::Requirements->new; - $req->add_minimum(Foo => 1); - - $req->add_exclusion(Foo => 1); - - dies_ok { $req->add_maximum(Foo => 1); } - qr/excluded all/, - "can't exclude all values" ; -} - -{ - my $req = CPAN::Meta::Requirements->new; - $req->add_minimum(Foo => 1); - dies_ok {$req->exact_version(Foo => 0.5); } - qr/outside of range/, - "can't add outside-range exact spec to range"; -} - -{ - my $req = CPAN::Meta::Requirements->new; - $req->add_minimum(Foo => 1); - dies_ok { $req->add_maximum(Foo => 0.5); } - qr/minimum exceeds maximum/, - "maximum must exceed (or equal) minimum"; - - $req = CPAN::Meta::Requirements->new; - $req->add_maximum(Foo => 0.5); - dies_ok { $req->add_minimum(Foo => 1); } - qr/minimum exceeds maximum/, - "maximum must exceed (or equal) minimum"; -} - -{ - my $req = CPAN::Meta::Requirements->new; - - $req->add_minimum(Foo => 1); - $req->add_maximum(Foo => 1); - - $req->add_maximum(Foo => 2); # ignored - $req->add_minimum(Foo => 0); # ignored - $req->add_exclusion(Foo => .5); # ignored - - is_deeply( - $req->as_string_hash, - { - 'Foo' => '== 1', - }, - "if min==max, becomes exact requirement", - ); -} - -{ - my $req = CPAN::Meta::Requirements->new; - $req->add_minimum(Foo => 1); - $req->add_exclusion(Foo => 0); - $req->add_maximum(Foo => 3); - $req->add_exclusion(Foo => 4); - - $req->add_exclusion(Foo => 2); - $req->add_exclusion(Foo => 2); - - is_deeply( - $req->as_string_hash, - { - Foo => '>= 1, <= 3, != 2', - }, - 'test exclusion-skipping', - ); -} - -sub foo_1 { - my $req = CPAN::Meta::Requirements->new; - $req->exact_version(Foo => 1); - return $req; -} - -{ - my $req = foo_1; - - $req->exact_version(Foo => 1); # ignored - - is_deeply($req->as_string_hash, { Foo => '== 1' }, "exact requirement"); - - dies_ok { $req->exact_version(Foo => 2); } - qr/unequal/, - "can't exactly specify differing versions" ; - - $req = foo_1; - $req->add_minimum(Foo => 0); # ignored - $req->add_maximum(Foo => 2); # ignored - - dies_ok { $req->add_maximum(Foo => 0); } qr/maximum below/, "max < fixed"; - - $req = foo_1; - dies_ok { $req->add_minimum(Foo => 2); } qr/minimum above/, "min > fixed"; - - $req = foo_1; - $req->add_exclusion(Foo => 8); # ignored - dies_ok { $req->add_exclusion(Foo => 1); } qr/excluded exact/, "!= && =="; -} - -done_testing; diff --git a/cpan/CPAN-Meta/t/finalize.t b/cpan/CPAN-Meta/t/finalize.t deleted file mode 100644 index 58048b51d5..0000000000 --- a/cpan/CPAN-Meta/t/finalize.t +++ /dev/null @@ -1,91 +0,0 @@ -use strict; -use warnings; - -use CPAN::Meta::Requirements; - -use Test::More 0.88; - -sub dies_ok (&@) { - my ($code, $qr, $comment) = @_; - - my $lived = eval { $code->(); 1 }; - - if ($lived) { - fail("$comment: did not die"); - } else { - like($@, $qr, $comment); - } -} - -{ - my $req = CPAN::Meta::Requirements->new; - - $req->add_minimum('Foo::Bar' => 10); - $req->add_minimum('Foo::Bar' => 0); - $req->add_minimum('Foo::Bar' => 2); - - $req->add_minimum('Foo::Baz' => version->declare('v1.2.3')); - - $req->add_minimum('Foo::Undef' => undef); - - my $want = { - 'Foo::Bar' => 10, - 'Foo::Baz' => 'v1.2.3', - 'Foo::Undef' => 0, - }; - - is_deeply( - $req->as_string_hash, - $want, - "some basic minimums", - ); - - $req->finalize; - - $req->add_minimum('Foo::Bar', 2); - - pass('we can add a Foo::Bar requirement with no effect post finalization'); - - dies_ok { $req->add_minimum('Foo::Bar', 12) } - qr{finalized req}, - "can't add a higher Foo::Bar after finalization"; - - dies_ok { $req->add_minimum('Foo::New', 0) } - qr{finalized req}, - "can't add a new module prereq after finalization"; - - dies_ok { $req->clear_requirement('Foo::Bar') } - qr{finalized req}, - "can't clear an existing prereq after finalization"; - - $req->clear_requirement('Bogus::Req'); - - pass('we can clear a prereq that was not set to begin with'); - - is_deeply( - $req->as_string_hash, - $want, - "none of our attempts to alter the object post-finalization worked", - ); - - my $cloned = $req->clone; - - $cloned->add_minimum('Foo::Bar', 12); - - is_deeply( - $cloned->as_string_hash, - { - %$want, - 'Foo::Bar' => 12, - }, - "we can alter a cloned V:R (finalization does not survive cloning)", - ); - - is_deeply( - $req->as_string_hash, - $want, - "...and original requirements are untouched", - ); -} - -done_testing; diff --git a/cpan/CPAN-Meta/t/from-hash.t b/cpan/CPAN-Meta/t/from-hash.t deleted file mode 100644 index a7f65590b7..0000000000 --- a/cpan/CPAN-Meta/t/from-hash.t +++ /dev/null @@ -1,48 +0,0 @@ -use strict; -use warnings; - -use CPAN::Meta::Requirements; - -use Test::More 0.88; - -sub dies_ok (&@) { - my ($code, $qr, $comment) = @_; - - my $lived = eval { $code->(); 1 }; - - if ($lived) { - fail("$comment: did not die"); - } else { - like($@, $qr, $comment); - } -} - -{ - my $string_hash = { - Left => 10, - Shared => '>= 2, <= 9, != 7', - Right => 18, - }; - - my $req = CPAN::Meta::Requirements->from_string_hash($string_hash); - - is_deeply( - $req->as_string_hash, - $string_hash, - "we can load from a string hash", - ); -} - -{ - my $string_hash = { - Left => 10, - Shared => '= 2', - Right => 18, - }; - - dies_ok { CPAN::Meta::Requirements->from_string_hash($string_hash) } - qr/Can't convert/, - "we die when we can't understand a version spec"; -} - -done_testing; diff --git a/cpan/CPAN-Meta/t/merge.t b/cpan/CPAN-Meta/t/merge.t deleted file mode 100644 index a0513560e4..0000000000 --- a/cpan/CPAN-Meta/t/merge.t +++ /dev/null @@ -1,136 +0,0 @@ -use strict; -use warnings; - -use CPAN::Meta::Requirements; - -use Test::More 0.88; - -sub dies_ok (&@) { - my ($code, $qr, $comment) = @_; - - my $lived = eval { $code->(); 1 }; - - if ($lived) { - fail("$comment: did not die"); - } else { - like($@, $qr, $comment); - } -} - -{ - my $req_1 = CPAN::Meta::Requirements->new; - $req_1->add_minimum(Left => 10); - $req_1->add_minimum(Shared => 2); - $req_1->add_exclusion(Shared => 7); - - my $req_2 = CPAN::Meta::Requirements->new; - $req_2->add_minimum(Shared => 1); - $req_2->add_maximum(Shared => 9); - $req_2->add_minimum(Right => 18); - - $req_1->add_requirements($req_2); - - is_deeply( - $req_1->as_string_hash, - { - Left => 10, - Shared => '>= 2, <= 9, != 7', - Right => 18, - }, - "add requirements to an existing set of requirements", - ); -} - -{ - my $req_1 = CPAN::Meta::Requirements->new; - $req_1->add_minimum(Left => 10); - $req_1->add_minimum(Shared => 2); - $req_1->add_exclusion(Shared => 7); - $req_1->exact_version(Exact => 8); - - my $req_2 = CPAN::Meta::Requirements->new; - $req_2->add_minimum(Shared => 1); - $req_2->add_maximum(Shared => 9); - $req_2->add_minimum(Right => 18); - $req_2->exact_version(Exact => 8); - - my $clone = $req_1->clone->add_requirements($req_2); - - is_deeply( - $req_1->as_string_hash, - { - Left => 10, - Shared => '>= 2, != 7', - Exact => '== 8', - }, - "clone/add_requirements does not affect lhs", - ); - - is_deeply( - $req_2->as_string_hash, - { - Shared => '>= 1, <= 9', - Right => 18, - Exact => '== 8', - }, - "clone/add_requirements does not affect rhs", - ); - - is_deeply( - $clone->as_string_hash, - { - Left => 10, - Shared => '>= 2, <= 9, != 7', - Right => 18, - Exact => '== 8', - }, - "clone and add_requirements", - ); - - $clone->clear_requirement('Shared'); - - is_deeply( - $clone->as_string_hash, - { - Left => 10, - Right => 18, - Exact => '== 8', - }, - "cleared the shared requirement", - ); -} - -{ - my $req_1 = CPAN::Meta::Requirements->new; - $req_1->add_maximum(Foo => 1); - - my $req_2 = $req_1->clone; - - is_deeply( - $req_2->as_string_hash, - { - 'Foo' => '<= 1', - }, - 'clone with only max', - ); -} - -{ - my $left = CPAN::Meta::Requirements->new; - $left->add_minimum(Foo => 0); - $left->add_minimum(Bar => 1); - - my $right = CPAN::Meta::Requirements->new; - $right->add_requirements($left); - - is_deeply( - $right->as_string_hash, - { - Foo => 0, - Bar => 1, - }, - "we do not lose 0-min reqs on merge", - ); -} - -done_testing; diff --git a/cpan/CPAN-Meta/t/prereqs.t b/cpan/CPAN-Meta/t/prereqs.t index 1ffacb55dc..6142d6386a 100644 --- a/cpan/CPAN-Meta/t/prereqs.t +++ b/cpan/CPAN-Meta/t/prereqs.t @@ -85,6 +85,7 @@ is_deeply($prereq->as_string_hash, $prereq_struct, "round-trip okay"); (! grep { 'Test' eq $_ } @req_mod), "...but not the build requirements", ); + } { diff --git a/cpan/CPAN-Meta/t/strings.t b/cpan/CPAN-Meta/t/strings.t index 300492eb13..bb87c68d1d 100644 --- a/cpan/CPAN-Meta/t/strings.t +++ b/cpan/CPAN-Meta/t/strings.t @@ -2,6 +2,18 @@ use strict; use warnings; use Test::More 0.88; +sub dies_ok (&@) { + my ($code, $qr, $comment) = @_; + + my $lived = eval { $code->(); 1 }; + + if ($lived) { + fail("$comment: did not die"); + } else { + like($@, $qr, $comment); + } +} + use CPAN::Meta::Requirements; my $req = CPAN::Meta::Requirements->new; @@ -43,4 +55,9 @@ ok(!$req->accepts_module('A::Tribe::Called' => '1.2'), 'lower version (>=, <=, ! ok(!$req->accepts_module('A::Tribe::Called' => '2.1'), 'higher version (>=, <=, !)'); ok(!$req->accepts_module('A::Tribe::Called' => '1.6'), 'excluded version (>=, <=, !)'); -done_testing;
\ No newline at end of file +# Test fatal errors +dies_ok { $req->add_string_requirement('Foo::Bar', undef) } + qr/No requirement string provided/, + "die without a requirement string"; + +done_testing; |