File: feature.t

package info (click to toggle)
libmodule-cpanfile-perl 1.1004-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 196 kB
  • sloc: perl: 531; makefile: 2
file content (89 lines) | stat: -rw-r--r-- 2,246 bytes parent folder | download | duplicates (2)
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
use strict;
use Module::CPANfile;
use Test::More;
use lib ".";
use t::Utils;

{
    my $r = write_cpanfile(<<FILE);
on test => sub {
  requires 'Test::More', '0.90';
};

feature 'sqlite' => sub {
  on runtime => sub { requires 'DBD::SQLite' },
};
FILE
    my $cpanfile = Module::CPANfile->load;
    my @features = $cpanfile->features;
    is $features[0]->identifier, 'sqlite';
    is $features[0]->description, 'sqlite';
}

{
    my $r = write_cpanfile(<<FILE);
on test => sub {
  requires 'Test::More', '0.90';
};

feature 'sqlite', 'SQLite support' => sub {
  on runtime => sub { requires 'DBD::SQLite' },
};
FILE
    my $cpanfile = Module::CPANfile->load;

    my @features = $cpanfile->features;
    is @features, 1;
    ok $features[0]->isa('CPAN::Meta::Feature');
    is $features[0]->identifier, 'sqlite';
    is $features[0]->description, 'SQLite support';
    ok $features[0]->prereqs;

    is_deeply $features[0]->prereqs->as_string_hash, { runtime => { requires => { 'DBD::SQLite' => '0' } } };

    {
        my $prereqs = $cpanfile->prereqs;
        is_deeply $prereqs->as_string_hash, {
            test => { requires => { 'Test::More' => '0.90' } },
        };
    }

    {
        my $prereqs = $cpanfile->effective_prereqs;
        is_deeply $prereqs->as_string_hash, {
            test => { requires => { 'Test::More' => '0.90' } },
        };
    }

    {
        my $prereqs = $cpanfile->prereqs_with('sqlite');
        is_deeply $prereqs->as_string_hash, {
            test => { requires => { 'Test::More' => '0.90' } },
            runtime => { requires => { 'DBD::SQLite' => '0' } },
        };
    }

    {
        my $prereqs = $cpanfile->effective_prereqs(['sqlite']);
        is_deeply $prereqs->as_string_hash, {
            test => { requires => { 'Test::More' => '0.90' } },
            runtime => { requires => { 'DBD::SQLite' => '0' } },
        };
    }

    {
        eval { my $prereqs = $cpanfile->prereqs_with('foobar') };
        like $@, qr/Unknown feature 'foobar'/;
    }

    {
        # no features, it's ok
        eval { my $prereqs = $cpanfile->prereqs_with() };
        ok !$@, $@;
    }

    like $cpanfile->to_string, qr/feature/;
    like $cpanfile->to_string, qr/DBD::SQLite/;
}

done_testing;