Dist-Zilla-Plugin-DynamicPrereqs

 view release on metacpan or  search on metacpan

t/19-include-subs-requires.t  view on Meta::CPAN

use strict;
use warnings;

use Test::More 0.88;
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
use Test::DZil;
use Test::Fatal;
use Path::Tiny;
use Test::Deep;
use PadWalker 'closed_over';
use Dist::Zilla::Plugin::DynamicPrereqs;

use Test::File::ShareDir
    -share => { -module => { 'Dist::Zilla::Plugin::DynamicPrereqs' => 'share/DynamicPrereqs' } };

use lib 't/lib';
use Helper;

my $included_subs = closed_over(\&Dist::Zilla::Plugin::DynamicPrereqs::_build__sub_definitions)->{'%included_subs'};

foreach my $subs (
    [ 'requires' ],
    [ 'runtime_requires' ],
    [ 'test_requires', 'build_requires' ],
)
{
    my $tzil = Builder->from_config(
        { dist_root => 'does-not-exist' },
        {
            add_files => {
                path(qw(source dist.ini)) => simple_ini(
                    [ GatherDir => ],
                    [ MakeMaker => ],
                    [ DynamicPrereqs => {
                            '-condition' => '1 == 1',
                            -raw => [
                                map $_.q|('strict', '0.23');|, @$subs
                            ],
                        } ],
                ),
                path(qw(source lib Foo.pm)) => "package Foo;\n1;\n",
            },
        },
    );

    $tzil->chrome->logger->set_debug(1);
    is(
        exception { $tzil->build },
        undef,
        'build proceeds normally',
    );

    cmp_deeply(
        $tzil->distmeta,
        superhashof({
            dynamic_config => 1,
            prereqs => {
                configure => {
                    requires => {
                        'ExtUtils::MakeMaker' => ignore,
                    }
                },
            },
        }),
        'no prereqs added for included subs',
    )
    or diag 'found metadata: ', explain $tzil->distmeta;

    my $build_dir = path($tzil->tempdir)->child('build');
    my $file = $build_dir->child('Makefile.PL');



( run in 0.468 second using v1.01-cache-2.11-cpan-39bf76dae61 )