f58e8c62df835256e809df0295d24cf0c71d837c
[perl.git] / cpan / CPAN-Meta / t / merge.t
1 #! perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use CPAN::Meta;
8 use CPAN::Meta::Merge;
9
10 my %base = (
11         abstract => 'This is a test',
12         author => ['A.U. Thor'],
13         generated_by => 'Myself',
14         license => [ 'perl_5' ],
15         resources => {
16                 license => [ 'http://dev.perl.org/licenses/' ],
17         },
18         prereqs => {
19                 runtime => {
20                         requires => {
21                                 Foo => '0',
22                         },
23                 },
24         },
25         dynamic_config => 0,
26         provides => {
27                 Baz => {
28                         file => 'lib/Baz.pm',
29                 },
30         },
31         'meta-spec' => {
32                 url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
33                 version => 2,
34         },
35 );
36
37 my %first = (
38         author => [ 'I.M. Poster' ],
39         generated_by => 'Some other guy',
40         license => [ 'bsd' ],
41         resources => {
42                 license => [ 'http://opensource.org/licenses/bsd-license.php' ],
43         },
44         prereqs => {
45                 runtime => {
46                         requires => {
47                                 Foo => '< 1',
48                         },
49                         recommends => {
50                                 Bar => '3.14',
51                         },
52                 },
53                 test => {
54                         requires => {
55                                 'Test::Bar' => 0,
56                         },
57                 },
58         },
59         dynamic_config => 1,
60         provides => {
61                 Quz => {
62                         file => 'lib/Quz.pm',
63                 },
64         },
65 );
66 my %first_expected = (
67         abstract => 'This is a test',
68         author => [ 'A.U. Thor', 'I.M. Poster' ],
69         generated_by => 'Myself, Some other guy',
70         license => [ 'perl_5', 'bsd' ],
71         resources => {
72                 license => [ 'http://dev.perl.org/licenses/', 'http://opensource.org/licenses/bsd-license.php' ],
73         },
74         prereqs => {
75                 runtime => {
76                         requires => {
77                                 Foo => '>= 0, < 1',
78                         },
79                         recommends => {
80                                 Bar => '3.14',
81                         },
82                 },
83                 test => {
84                         requires => {
85                                 'Test::Bar' => 0,
86                         },
87                 },
88         },
89         provides => {
90                 Baz => {
91                         file => 'lib/Baz.pm',
92                 },
93                 Quz => {
94                         file => 'lib/Quz.pm',
95                 },
96         },
97         dynamic_config => 1,
98         'meta-spec' => {
99                 url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
100                 version => 2,
101         },
102 );
103
104 my $merger = CPAN::Meta::Merge->new(default_version => '2');
105
106 my $first_result = $merger->merge(\%base, \%first);
107
108 is_deeply($first_result, \%first_expected, 'First result is as expected');
109
110 is_deeply($merger->merge(\%base, { abstract => 'This is a test' }), \%base, 'Can merge in identical abstract');
111 my $failure = eval { $merger->merge(\%base, { abstract => 'And now for something else' }) };
112 is($failure, undef, 'Trying to merge different author gives an exception');
113 like $@, qr/^Can't merge attribute abstract/, 'Exception looks right';
114
115 my $failure2 = eval { $merger->merge(\%base, { provides => { Baz => { file => 'Baz.pm' } } }) };
116 is($failure2, undef, 'Trying to merge different author gives an exception');
117 like $@, qr/^Duplication of element provides\.Baz /, 'Exception looks right';
118
119 # issue 67
120 @base{qw/name version release_status/} = qw/Foo-Bar 0.01 testing/;
121 my $base_obj = CPAN::Meta->create(\%base);
122 ok my $first_result_obj = $merger->merge($base_obj, \%first), 'merging CPAN::Meta objects succeeds';
123
124 done_testing();