Commit | Line | Data |
---|---|---|
b6ae0ea7 CBW |
1 | use strict; |
2 | use warnings; | |
3 | ||
4 | use CPAN::Meta::Requirements; | |
5 | ||
6 | use Test::More 0.88; | |
7 | ||
8 | sub dies_ok (&@) { | |
9 | my ($code, $qr, $comment) = @_; | |
10 | ||
11 | my $lived = eval { $code->(); 1 }; | |
12 | ||
13 | if ($lived) { | |
14 | fail("$comment: did not die"); | |
15 | } else { | |
16 | like($@, $qr, $comment); | |
17 | } | |
18 | } | |
19 | ||
20 | { | |
21 | my $string_hash = { | |
22 | Left => 10, | |
23 | Shared => '>= 2, <= 9, != 7', | |
24 | Right => 18, | |
25 | }; | |
26 | ||
27 | my $req = CPAN::Meta::Requirements->from_string_hash($string_hash); | |
28 | ||
29 | is_deeply( | |
30 | $req->as_string_hash, | |
31 | $string_hash, | |
32 | "we can load from a string hash", | |
33 | ); | |
34 | } | |
35 | ||
36 | { | |
37 | my $string_hash = { | |
38 | Left => 10, | |
39 | Shared => '= 2', | |
40 | Right => 18, | |
41 | }; | |
42 | ||
43 | dies_ok { CPAN::Meta::Requirements->from_string_hash($string_hash) } | |
44 | qr/Can't convert/, | |
45 | "we die when we can't understand a version spec"; | |
46 | } | |
47 | ||
48 | { | |
49 | my $string_hash = { | |
50 | Left => 10, | |
51 | Shared => undef, | |
52 | Right => 18, | |
53 | }; | |
54 | ||
55 | my $warning; | |
56 | local $SIG{__WARN__} = sub { $warning = join("\n",@_) }; | |
57 | ||
58 | my $req = CPAN::Meta::Requirements->from_string_hash($string_hash); | |
59 | ||
60 | is( | |
61 | $req->as_string_hash->{Shared}, 0, | |
62 | "undef requirement treated as '0'", | |
63 | ); | |
64 | ||
65 | like ($warning, qr/Undefined requirement.*treated as '0'/, "undef requirement warns"); | |
66 | ||
67 | } | |
68 | ||
69 | done_testing; |