File: prereqs-merge.t

package info (click to toggle)
libcpan-meta-perl 2.142690-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 820 kB
  • ctags: 128
  • sloc: perl: 2,635; makefile: 2
file content (106 lines) | stat: -rw-r--r-- 1,983 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use strict;
use warnings;
use Test::More 0.88;

use CPAN::Meta::Prereqs;

delete $ENV{$_} for qw/PERL_JSON_BACKEND PERL_YAML_BACKEND/; # use defaults

my $prereq_struct_1 = {
  runtime => {
    requires => {
      'Config' => 0,
      'Cwd'    => 0,
      'perl'   => '5.005_03',
    },
    recommends => {
      'Pod::Text' => 0,
      'YAML'      => 0.35,
    },
  },
  build => {
    requires => {
      'Test' => 0,
    },
  }
};

my $prereq_1 = CPAN::Meta::Prereqs->new($prereq_struct_1);

isa_ok($prereq_1, 'CPAN::Meta::Prereqs', 'first prereq');

is_deeply($prereq_1->as_string_hash, $prereq_struct_1, '...and it round trips');

my $prereq_struct_2 = {
  develop => {
    requires => {
      'Dist::Mothra' => '1.230',
    },
    suggests => {
      'Blort::Blortex' => '== 10.20',
    },
  },
  runtime => {
    requires => {
      'Config' => 1,
      'perl'       => '< 6',
    },
  },
  build => {
    suggests => {
      'Module::Build::Bob' => '20100101',
    },
  }
};

my $prereq_2 = CPAN::Meta::Prereqs->new($prereq_struct_2);

isa_ok($prereq_2, 'CPAN::Meta::Prereqs', 'second prereq');

is_deeply($prereq_1->as_string_hash, $prereq_struct_1, '...and it round trips');

my $merged = $prereq_1->with_merged_prereqs($prereq_2);

my $want = {
  develop => {
    requires => {
      'Dist::Mothra' => '1.230',
    },
    suggests => {
      'Blort::Blortex' => '== 10.20',
    },
  },
  runtime => {
    requires => {
      'Config' => 1,
      'Cwd'    => 0,
      'perl'   => '>= 5.005_03, < 6',
    },
    recommends => {
      'Pod::Text' => 0,
      'YAML'      => 0.35,
    },
  },
  build => {
    requires => {
      'Test' => 0,
    },
    suggests => {
      'Module::Build::Bob' => '20100101',
    },
  },
};

is_deeply(
  $merged->as_string_hash,
  $want,
  "we get the right result of merging two prereqs",
);

is_deeply(
  $prereq_2->with_merged_prereqs($prereq_1)->as_string_hash,
  $want,
  "...and the merge works the same in reverse",
);

done_testing;