App-CPAN-Get

 view release on metacpan or  search on metacpan

t/App-CPAN-Get/04-run.t  view on Meta::CPAN

use strict;
use warnings;

use App::CPAN::Get;
use Cwd;
use English;
use Error::Pure::Utils qw(clean);
use File::Object;
use File::Spec::Functions qw(abs2rel catfile);
use File::Temp qw(tempdir);
use HTTP::Response;
use Perl6::Slurp qw(slurp);
use Test::LWP::UserAgent;
use Test::More 'tests' => 8;
use Test::NoWarnings;
use Test::Output;
use Test::Warn;

# Test.
@ARGV = (
	'-h',
);
my $right_ret = help();
stderr_is(
	sub {
		App::CPAN::Get->new->run;
		return;
	},
	$right_ret,
	'Run help (-h).',
);

# Test.
@ARGV = ();
$right_ret = help();
stderr_is(
	sub {
		App::CPAN::Get->new->run;
		return;
	},
	$right_ret,
	'Run help (no module name).',
);

# Test.
@ARGV = (
	'-x',
);
$right_ret = help();
stderr_is(
	sub {
		warning_is { App::CPAN::Get->new->run; } "Unknown option: x\n",
			'Warning about bad argument';
		return;
	},
	$right_ret,
	'Run help (-x - bad option).',
);

# Test.
@ARGV = (
	'App::CPAN::Search',
);
$right_ret = <<'END';
Module 'App::CPAN::Search' doesn't exist.
END
eval {
	App::CPAN::Get->new(
		'lwp_user_agent' => Test::LWP::UserAgent->new,
	)->run;
};
is($EVAL_ERROR, "Module 'App::CPAN::Search' doesn't exist.\n",
	"Module 'App::CPAN::Search' doesn't exist.");
clean();

# Test.
@ARGV = (
	'App::CPAN::Search',
);
my $user_agent = Test::LWP::UserAgent->new;
my $content = <<'END';
{
   "release" : "App-CPAN-Search-0.09",
   "checksum_sha256" : "7239ce1154a4002b9b461e5ad80a50ac21b9477b7f000a6a89f924e546e7a63d",
   "version" : "0.09",
   "status" : "latest",
   "date" : "2023-01-23T17:24:56",
   "download_url" : "https://cpan.metacpan.org/authors/id/S/SK/SKIM/App-CPAN-Search-0.09.tar.gz",
   "checksum_md5" : "798a40ee72e0078a8f960186d94eb4b4"
}
END
$user_agent->map_response(
	qr(https://fastapi\.metacpan\.org/v1/download_url/App::CPAN::Search),
	HTTP::Response->new('200', 'OK', ['Content-Type' => 'application/json; charset=utf-8'], $content),
);
$user_agent->map_response(
	qr{https://cpan\.metacpan\.org/authors/id/S/SK/SKIM/App-CPAN-Search-0\.09\.tar\.gz},
	HTTP::Response->new('200', 'OK', ['Content-Type' => 'application/x-gzip'], 'test content'),
);
$right_ret = <<'END';
Package on 'https://cpan.metacpan.org/authors/id/S/SK/SKIM/App-CPAN-Search-0.09.tar.gz' was downloaded.
END
my $tmp_dir = tempdir('CLEANUP' => 1);
my $act_dir = getcwd();
chdir $tmp_dir;
stdout_is(
	sub {
		App::CPAN::Get->new(
			'lwp_user_agent' => $user_agent,
		)->run;



( run in 2.487 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )