App-perlimports

 view release on metacpan or  search on metacpan

t/Sandbox.t  view on Meta::CPAN

use strict;
use warnings;

use lib 't/lib', 'test-data/lib';

use App::perlimports::Sandbox ();
use TestHelper                qw( doc );
use Test::Differences         qw( eq_or_diff );
use Test::More import => [qw( cmp_ok diag done_testing ok subtest )];

my $pkg1 = App::perlimports::Sandbox::pkg_for('fakeblock');
my $pkg2 = App::perlimports::Sandbox::pkg_for('fakeblock');

ok( $pkg1, 'first pkg' );
ok( $pkg2, 'second pkg' );

cmp_ok( $pkg1, 'ne', $pkg2, 'names are not the same' );

subtest 'Carp' => sub {
    my $eval = App::perlimports::Sandbox::eval_pkg(
        'Carp',
        'use Carp qw( croak );',
    );

    ok( !$eval, 'no problems with eval' );
};

subtest 'missing module' => sub {
    my $eval = App::perlimports::Sandbox::eval_pkg(
        'Local::ZZZ::XXX',
        'use Local::ZZZ::XXX ();',
    );

    ok( $eval, 'eval failure' );
};

subtest 'local module' => sub {
    my $eval = App::perlimports::Sandbox::eval_pkg(
        'Local::ImportException',
        'use Local::ImportException ();',
    );

    ok( !$eval, 'no eval failure' );
};

subtest 'local module with exception' => sub {
    my $eval = App::perlimports::Sandbox::eval_pkg(
        'Local::ImportException',
        'use Local::ImportException qw( exceptional );',
    );

    ok( $eval, 'eval failure' );
};

subtest 'real trial-load warning is suppressed' => sub {

    # End-to-end check: trial-load a dependency-free module that has no
    # import() method while passing a non-empty import list -- the same shape
    # as the original report, "use LWP::UserAgent qw( new );". With no import()
    # to hand the list to, Perl emits its actual "Attempt to call
    # undefined/missing import method" warning (the symbol name is irrelevant;
    # only the non-empty list matters -- a bare "use" stays silent). eval_pkg
    # must swallow it so nothing reaches this outer handler, verifying
    # suppression against whatever wording this Perl version uses (see GH #181).
    my @leaked;
    local $SIG{__WARN__} = sub { push @leaked, @_ };

    my $error = App::perlimports::Sandbox::eval_pkg(



( run in 1.320 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )