xref: /openbsd-src/gnu/usr.bin/perl/cpan/Test-Simple/t/Test2/modules/API/Breakage.t (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1use strict;
2use warnings;
3
4use Test2::IPC;
5use Test2::Tools::Tiny;
6use Test2::API::Breakage;
7my $CLASS = 'Test2::API::Breakage';
8
9for my $meth (qw/upgrade_suggested upgrade_required known_broken/) {
10    my @list = $CLASS->$meth;
11    ok(!(@list % 2), "Got even list ($meth)");
12    ok(!(grep {!defined($_)} @list), "No undefined items ($meth)");
13}
14
15{
16    no warnings 'redefine';
17    local *Test2::API::Breakage::upgrade_suggested = sub {
18        return ('T2Test::UG1' => '1.0', 'T2Test::UG2' => '0.5');
19    };
20
21    local *Test2::API::Breakage::upgrade_required = sub {
22        return ('T2Test::UR1' => '1.0', 'T2Test::UR2' => '0.5');
23    };
24
25    local *Test2::API::Breakage::known_broken = sub {
26        return ('T2Test::KB1' => '1.0', 'T2Test::KB2' => '0.5');
27    };
28    use warnings 'redefine';
29
30    ok(!$CLASS->report, "Nothing to report");
31    ok(!$CLASS->report(1), "Still nothing to report");
32
33    {
34        local %INC = (
35            %INC,
36            'T2Test/UG1.pm' => 1,
37            'T2Test/UG2.pm' => 1,
38            'T2Test/UR1.pm' => 1,
39            'T2Test/UR2.pm' => 1,
40            'T2Test/KB1.pm' => 1,
41            'T2Test/KB2.pm' => 1,
42        );
43        local $T2Test::UG1::VERSION = '0.9';
44        local $T2Test::UG2::VERSION = '0.9';
45        local $T2Test::UR1::VERSION = '0.9';
46        local $T2Test::UR2::VERSION = '0.9';
47        local $T2Test::KB1::VERSION = '0.9';
48        local $T2Test::KB2::VERSION = '0.9';
49
50        my @report = $CLASS->report;
51
52        is_deeply(
53            [sort @report],
54            [
55                sort
56                " * Module 'T2Test::UG1' is outdated, we recommed updating above 1.0.",
57                " * Module 'T2Test::UR1' is outdated and known to be broken, please update to 1.0 or higher.",
58                " * Module 'T2Test::KB1' is known to be broken in version 1.0 and below, newer versions have not been tested. You have: 0.9",
59                " * Module 'T2Test::KB2' is known to be broken in version 0.5 and below, newer versions have not been tested. You have: 0.9",
60            ],
61            "Got expected report items"
62        );
63    }
64
65    my %look;
66    unshift @INC => sub {
67        my ($this, $file) = @_;
68        $look{$file}++ if $file =~ m{T2Test};
69        return;
70    };
71    ok(!$CLASS->report, "Nothing to report");
72    is_deeply(\%look, {}, "Did not try to load anything");
73
74    ok(!$CLASS->report(1), "Nothing to report");
75    is_deeply(
76        \%look,
77        {
78            'T2Test/UG1.pm' => 1,
79            'T2Test/UG2.pm' => 1,
80            'T2Test/UR1.pm' => 1,
81            'T2Test/UR2.pm' => 1,
82            'T2Test/KB1.pm' => 1,
83            'T2Test/KB2.pm' => 1,
84        },
85        "Tried to load modules"
86    );
87}
88
89done_testing;
90