App-cpan2arch
view release on metacpan or search on metacpan
t/02-online.t view on Meta::CPAN
{
my $temp = Path::Tiny->tempdir;
my $cache_path = $temp->child($path)->stringify;
my $cache_key =
$path eq 'mcpan_cache' ? 'cache_mcpan_path'
: $path eq 'arch_cache' ? 'cache_arch_path'
: ();
my %env = (
user_agent => "$DEFS{class}/$DEFS{ver}",
$cache_key => $cache_path,
cache_expiration => '1d',
cache_ignore => $t =~ /\Ano_cache/ ? true : false,
#debug => true,
);
return ( \%env, $cache_path );
}
subtest 'Metadata' => sub {
#skip_all;
subtest 'Get metadata' => sub {
#skip_all;
my $MOD = 'File::KDBX';
my $DIST = 'File-KDBX';
my $VER = $expected->{$DIST}{version};
my $BOGUS_END = 'https://bogus/';
my %TESTS_META = (
'normal_mod' => $MOD,
'normal_dist' => $DIST,
'no_cache_mod' => $MOD,
'no_cache_dist' => $DIST,
'bogus_mod' => 'Bogus::Module',
'bogus_dist' => 'Bogus-Dist',
'bogus_mod_end' => $MOD,
'bogus_rel_end' => $DIST,
);
foreach my ( $t, $name ) (%TESTS_META) {
next if $t =~ /\Ano_cache/ && !$has_cache_mods;
subtest "$t ($name)" => sub {
my $c2a = App::cpan2arch->new;
my $cache_path;
if ($has_cache_mods) {
( my $env, $cache_path ) = get_env_cache( $t, 'mcpan_cache' );
$c2a->set_env( $env->%* );
}
my @argv = $name;
push @argv, $VER if $t eq 'normal_dist' || $t eq 'no_cache_dist';
$c2a->_process_opts( \@argv );
# Error
if ( $t =~ /\Abogus_/ ) {
my %endpoints = $c2a->endpoints;
if ( $t eq 'bogus_mod_end' ) {
$endpoints{module} = $BOGUS_END;
$c2a->set_endpoints(%endpoints);
}
elsif ( $t eq 'bogus_rel_end' ) {
$endpoints{release} = $BOGUS_END;
$c2a->set_endpoints(%endpoints);
}
my ( $stderr, @ret ) = capture_stderr {
return $c2a->get_metadata;
};
is(
$ret[0], number(1),
'return value (error)',
);
return;
}
my $ret = $c2a->get_metadata;
my %optionals = $c2a->optionals;
my %meta = $c2a->meta;
# Cache
if ($has_cache_mods) {
if ( $t =~ /\Ano_cache_/ ) {
is(
!-d $cache_path, T(),
'has no cache',
);
}
else {
my @caches = path($cache_path)->child('Default')->children;
#system( 'tree', '-a', $cache_path );
is(
scalar @caches, number_gt(0),
'has cache',
);
# Clear cache
$c2a->_process_opts( [ qw< --clear >, $DIST ] );
$c2a->_get_mua('mcpan');
my @cl_caches = path($cache_path)->children;
#system( 'tree', '-a', $cache_path );
is(
scalar @caches, number_gt( scalar @cl_caches ),
'has cleared cache',
);
}
}
# Module (normal_mod) only fetches the latest release, so it cannot
# be tested reliably like the versioned dist.
if ( $t eq 'normal_dist' || $t eq 'no_cache_dist' ) {
is(
%optionals, $expected->{$DIST}{optionals}->%*,
'optionals match',
);
is(
%meta, $expected->{$DIST}{meta}->%*,
'metadata match',
);
t/02-online.t view on Meta::CPAN
subtest "$t ($name)" => sub {
my $TODO;
my $c2a = App::cpan2arch->new;
$c2a->_init_mua_mcpan;
if ( $t =~ /\Abogus_/ ) {
$TODO = todo 'This test fails when IO::Uncompress::UnXz is installed'
if $t eq 'bogus_tar';
my ( $stderr, @ret ) = capture_stderr {
return $c2a->_find_files( $DIST, $name );
};
is(
$ret[0], number(1),
'return value (error)',
);
return;
}
my $ret = $c2a->_find_files( $DIST, $name );
is(
$ret, \%FILES,
'files match',
);
};
}
};
};
subtest 'Merge prereqs' => sub {
#skip_all;
my $DIST = 'Regexp-Debugger';
my %TESTS_MERGE = (
'normal' => $DIST,
'no_cache' => $DIST,
'bogus_url' => 'https://bogus',
);
foreach my ( $t, $name ) (%TESTS_MERGE) {
next if $t eq 'no_cache' && !$has_cache_mods;
subtest "$t ($name)" => sub {
my $c2a = App::cpan2arch->new;
my $cache_path;
if ($has_cache_mods) {
( my $env, $cache_path ) = get_env_cache( $t, 'mcpan_cache' );
$c2a->set_env( $env->%* );
}
$c2a->_init_mua_mcpan;
$c2a->set_meta( $expected->{$DIST}{meta}->%* );
if ( $t eq 'bogus_url' ) {
my %endpoints = $c2a->endpoints;
$endpoints{download} = $name;
$c2a->set_endpoints(%endpoints);
my ( $stderr, @ret ) = capture_stderr {
return $c2a->merge_prereqs;
};
my @fetch_errors = $c2a->fetch_errors;
is(
scalar @fetch_errors, number_gt(0),
'has error message',
);
is(
$ret[0], number(1),
'return value (error)',
);
return;
}
my $ret = $c2a->merge_prereqs;
my %cpan_prereqs = $c2a->cpan_prereqs;
if ($has_cache_mods) {
if ( $t eq 'no_cache' ) {
is(
!-d $cache_path, T(),
'has no cache',
);
}
else {
my @caches = path($cache_path)->child('Default')->children;
is(
scalar @caches, number_gt(0),
'has cache',
);
# Clear cache
$c2a->_process_opts( [ qw< --clear-mcpan >, $DIST ] );
$c2a->_get_mua('mcpan');
my @cl_caches = path($cache_path)->children;
is(
scalar @caches, number_gt( scalar @cl_caches ),
'has cleared cache',
);
}
}
is(
%cpan_prereqs, $expected->{$DIST}{cpan_prereqs}->%*,
'prereqs match',
);
is(
$ret, number(0),
'return value (success)',
);
};
}
( run in 3.006 seconds using v1.01-cache-2.11-cpan-2e0ccfb7a10 )