summaryrefslogtreecommitdiffstats
path: root/t/02-conflicts.t
blob: f59777f57e0457a60b2b9d4398e1de1cc8f36511 (plain) (blame)
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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Test::Warn;
use lib 't/lib/02';

{
    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::Conflicts::Bad:\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::Conflicts::Bad:\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"
    );
}

{
    # conflicting module is utterly broken

    use_ok('Foo::Conflicts::Broken');

    my @conflicts;
    warning_like { @conflicts = Foo::Conflicts::Broken->calculate_conflicts }
        qr/Warning: Broken did not compile/,
        'Warning is issued when Broken fails to compile';

    is_deeply(
        \@conflicts,
        [
            { package => 'Broken', installed => 'unknown', required => '0.03' },
        ],
        "correct versions for all conflicts",
    );

    is(
        exception { Foo::Conflicts::Broken->check_conflicts },
        "Conflicts detected for Foo::Conflicts::Broken:\n  Broken is version unknown, but must be greater than version 0.03\n",
        "correct conflict error"
    );
}

done_testing;