Dist-Zilla-Plugin-DynamicPrereqs

 view release on metacpan or  search on metacpan

t/23-inlined-module.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 PadWalker 'closed_over';
use Test::Deep;
use Test::File::ShareDir ();

# since we change directories during the build process, this must be absolute
use lib path('t/lib')->absolute->stringify;

sub tzil {
    my $tzil = Builder->from_config(
        { dist_root => 'does-not-exist' },
        {
            add_files => {
                path(qw(source dist.ini)) => simple_ini(
                    [ GatherDir => ],
                    [ MakeMaker => ],
                    [ DynamicPrereqs => {
                        -include_sub => [ 'foo' ],
                        -raw => [ 'foo();' ],
                      },
                    ],
                ),
                path(qw(source lib Foo.pm)) => "package Foo;\n1;\n",
                path(qw(source share include_subs foo)) => "sub foo {\n  1;\n}\n",
            },
        },
    );

    Test::File::ShareDir->import(
        -root => path($tzil->tempdir)->child('source')->stringify,
        -share => { -module => { 'Dist::Zilla::Plugin::DynamicPrereqs' => 'share' } },
    );

    return $tzil;
}

{
    my $tzil = tzil();

    my $sub_inc_dependencies = closed_over(\&Dist::Zilla::Plugin::DynamicPrereqs::gather_files)->{'%sub_inc_dependencies'};
    $sub_inc_dependencies->{foo} = { 'Does::Not::Exist' => '0' };

    $tzil->chrome->logger->set_debug(1);
    like(
        exception { $tzil->build },
        qr/(?:Could not find module|Can't locate) Does::Not::Exist/,
        'build fails when module to be inlined is not installed',
    ) or diag 'got log messages: ', explain $tzil->log_messages;

    diag 'got log messages: ', explain $tzil->log_messages
        if not Test::Builder->new->is_passing;
}

{
    my $tzil = tzil();

    my ($strict_version, $stricter_version) = (strict->VERSION, strict->VERSION * 2);

    my $sub_inc_dependencies = closed_over(\&Dist::Zilla::Plugin::DynamicPrereqs::gather_files)->{'%sub_inc_dependencies'};
    $sub_inc_dependencies->{foo} = { 'strict' => $stricter_version };

    $tzil->chrome->logger->set_debug(1);



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