Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite some test spec code with test2 #809

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .perlcriticrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ verbose = %f:%l:%c:[%p] %m => %r\n

only = 1
include = RequireUseStrict ProhibitUnusedVariables ProhibitUnreachableCode ProhibitUnusedConstant ProhibitUnusedInclude ProhibitUnusedImport ProhibitDuplicateHashKeys ProhibitExcessiveColons ProhibitDuplicatedSub ProhibitTrailingWhitespace

[TestingAndDebugging::RequireUseStrict]
equivalent_modules = Test2::V0
2 changes: 1 addition & 1 deletion t/18.release-detail-perl-remote.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ok !$error, 'no error';
ok defined( $rd->{tarball_url} ), 'tarball_url is defined';
ok defined( $rd->{tarball_name} ), 'tarball_url is defined';

is $rd->{tarball_url}, "https://www.cpan.org/src/5.0/perl-5.18.2.tar.bz2",
is $rd->{tarball_url}, "https://www.cpan.org/src/5.0/perl-5.18.2.tar.bz2",
'tarball_url is correct';
is $rd->{tarball_name}, "perl-5.18.2.tar.bz2",
'tarball_name is correct';
Expand Down
61 changes: 24 additions & 37 deletions t/command-help.t
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test2::V0;
use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
require "test_helpers.pl";

use Test::Spec;
require "test2_helpers.pl";

my $bin_perlbrew = file(__FILE__)->dirname->dirname->child("script")->child("perlbrew");
my $perl = $^X;
Expand All @@ -16,45 +13,35 @@ my $perl = $^X;
# that's why we use backtick to test.
#


describe "`perlbrew`" => sub {
it "should print some nice message and instruct user to read help for individual commands" => sub {
my $out = `$perl -Ilib $bin_perlbrew help`;
like $out, qr/perlbrew help <command>/si;
};
subtest "`perlbrew` should print some nice message and instruct user to read help for individual commands" => sub {
my $out = `$perl -Ilib $bin_perlbrew help`;
like $out, qr/perlbrew help <command>/si;
};

describe "`perlbrew -h`" => sub {
it "should print short version of help message and instruct user to read longer version" => sub {
my $out1 = `$perl -Ilib $bin_perlbrew --help`;
my $out2 = `$perl -Ilib $bin_perlbrew -h`;
subtest "`perlbrew -h` should print short version of help message and instruct user to read longer version" => sub {
my $out1 = `$perl -Ilib $bin_perlbrew --help`;
my $out2 = `$perl -Ilib $bin_perlbrew -h`;

is $out2, $out1;
like $out1, qr/^ See `perlbrew help` for the full documentation/m;
unlike $out1, qr/^CONFIGURATION$/m;
};
is $out2, $out1;
like $out1, qr/^ See `perlbrew help` for the full documentation/m;
unlike $out1, qr/^CONFIGURATION$/m;
};

describe "`perlbrew help`" => sub {
it "should should the lengthy version " => sub {
my $out = `$perl -Ilib $bin_perlbrew help`;
like $out, qr/^CONFIGURATION$/m;
};

it "should instruct user to read help for individual commands." => sub {
my $out = `$perl -Ilib $bin_perlbrew help`;
like $out, qr/perlbrew help <command>/si;
};
subtest "`perlbrew help` should should the lengthy version " => sub {
my $out = `$perl -Ilib $bin_perlbrew help`;
like $out, qr/^CONFIGURATION$/m;
};

describe "`help install`" => sub {
it "should show the options for install command" => sub {
my $out = `$perl -Ilib $bin_perlbrew help install`;
like $out, qr/^Options for "install" command:/msi;
like $out, qr/--force/si;
like $out, qr/--notest/si;
};
subtest "`perlbrew help` should instruct user to read help for individual commands." => sub {
my $out = `$perl -Ilib $bin_perlbrew help`;
like $out, qr/perlbrew help <command>/si;
};

runtests unless caller;
subtest "`perlbrew help install` should show the options for install command" => sub {
my $out = `$perl -Ilib $bin_perlbrew help install`;
like $out, qr/^Options for "install" command:/msi;
like $out, qr/--force/si;
like $out, qr/--notest/si;
};

done_testing;
10 changes: 5 additions & 5 deletions t/command-list.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe "list command," => sub {
my $app = App::perlbrew->new("list");
my $events = intercept { $app->run() };
like $events,
[
[
{info => [{tag => 'STDOUT', details => qr/^(\s|\*)\sc?perl-?\d\.\d{1,3}[_.]\d{1,2}\s+/}]}
],
'Cannot find Perl in output';
Expand All @@ -54,7 +54,7 @@ describe "list command," => sub {
my $app = App::perlbrew->new("list");
my $events = intercept { $app->run() };
like $events,
[
[
{info => [{tag => 'STDOUT', details => qr/^(\s|\*)\sc?perl-?\d\.\d{1,3}[_.]\d{1,2}(@\w+)?/}]}
],
'Cannot find Perl with libraries in output';
Expand All @@ -65,7 +65,7 @@ describe "list command," => sub {
my $app = App::perlbrew->new("list");
my $events = intercept { $app->run() };
like $events,
[
[
{info => [{tag => 'STDOUT', details => qr/^(\s|\*)\sc?perl-?\d\.\d{1,3}[_.]\d{1,2}(\@nobita)?/}]}
],
'Cannot find Perl with libraries in output';
Expand All @@ -79,7 +79,7 @@ describe "list command," => sub {
$app->run();
};
like $events,
[
[
{info => [{tag => 'STDOUT', details => qr/^perl-?\d\.\d{1,3}[_.]\d{1,2}(@\w+)?/}]}
],
'No decoration mark in the output';
Expand All @@ -91,7 +91,7 @@ describe "list command," => sub {
my $app = App::perlbrew->new("list", "--no-decoration");
my $events = intercept { $app->run() };
like $events,
[
[
{info => [{tag => 'STDOUT', details => qr/^perl-?\d\.\d{1,3}[_.]\d{1,2}(@\w+)?/}]}
],
'No decoration mark in the output';
Expand Down
43 changes: 11 additions & 32 deletions t/home.t
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test2::V0;
use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
require "test_helpers.pl";

use Test::Deep qw[];
use Test::Spec;
require "test2_helpers.pl";

sub looks_like_perlbrew_home;

local $App::perlbrew::PERLBREW_HOME = '/perlbrew/home';
local $ENV{PERLBREW_HOME} = '/env/home';
local $ENV{HOME} = '/home';

describe "App::perlbrew#home method" => sub {
it "should return \$App::perlbrew::PERLBREW_HOME if provided" => sub {
subtest "App::perlbrew#home method" => sub {
subtest "it should return \$App::perlbrew::PERLBREW_HOME if provided" => sub {
my $app = App::perlbrew->new;

looks_like_perlbrew_home $app->home, '/perlbrew/home';
};

it "should default to \$ENV{PERLBREW_HOME} if provided" => sub {
subtest "it should default to \$ENV{PERLBREW_HOME} if provided" => sub {
local $App::perlbrew::PERLBREW_HOME;

my $app = App::perlbrew->new;

looks_like_perlbrew_home $app->home, '/env/home';
};

it "should default to \$ENV{HOME} subpath" => sub {
subtest "it should default to \$ENV{HOME} subpath" => sub {
local $App::perlbrew::PERLBREW_HOME;
local $ENV{PERLBREW_HOME};

Expand All @@ -39,37 +35,20 @@ describe "App::perlbrew#home method" => sub {
looks_like_perlbrew_home $app->home, '/home/.perlbrew';
};

it "should return the instance property of 'home' if set" => sub {
subtest "it should return the instance property of 'home' if set" => sub {
my $app = App::perlbrew->new;
$app->home("/fnord");

looks_like_perlbrew_home $app->home, "/fnord";
};
};

runtests unless caller;
done_testing;

sub looks_like_perlbrew_home {
my ($got, $expected) = @_;

my ($ok, $stack);

($ok, $stack) = Test::Deep::cmp_details "$got", "$expected";
unless ($ok) {
fail;
diag "Return value comparison failed";
diag Test::Deep::deep_diag $stack;
return;
}

($ok, $stack) = Test::Deep::cmp_details "$got", "$App::perlbrew::PERLBREW_HOME";
unless ($ok) {
fail;
diag "Global \$PERLBREW_HOME comparison failed";
diag Test::Deep::deep_diag $stack;
return;
}

return Test::Deep::cmp_deeply $got, Isa('App::Perlbrew::Path');
isa_ok $got, 'App::Perlbrew::Path';
is "$got", "$expected";
is "$got", "$App::perlbrew::PERLBREW_HOME";
}

2 changes: 1 addition & 1 deletion t/http-program-control.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for my $prog (qw(curl wget fetch)) {

subtest "something not supported", sub {
local $App::Perlbrew::HTTP::HTTP_USER_AGENT_PROGRAM = "something-that-is-not-recognized";
ok dies { http_user_agent_program() },
ok dies { http_user_agent_program() },
"should die when asked to use unrecognized http UA program";
};

Expand Down
Loading