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

Replace Testt::Spec with Test2::Tools::Spec #813

Merged
merged 19 commits into from
Aug 30, 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
1 change: 0 additions & 1 deletion META.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"Test::NoWarnings" : "1.04",
"Test::Output" : "1.03",
"Test::Simple" : "1.001002",
"Test::Spec" : "0.49",
"Test::TempDir::Tiny" : "0.016"
}
}
Expand Down
1 change: 0 additions & 1 deletion META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ build_requires:
Test::NoWarnings: '1.04'
Test::Output: '1.03'
Test::Simple: '1.001002'
Test::Spec: '0.49'
Test::TempDir::Tiny: '0.016'
configure_requires:
Module::Build::Tiny: '0.039'
Expand Down
1 change: 0 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ on test => sub {
requires 'Test::NoWarnings' => '1.04';
requires 'Test::Output' => '1.03';
requires 'Test::Simple' => '1.001002';
requires 'Test::Spec' => '0.49';
requires 'Test::TempDir::Tiny' => '0.016';
requires 'Test2::V0' => '0.000163';
requires 'Test2::Plugin::NoWarnings' => '0.10';
Expand Down
48 changes: 19 additions & 29 deletions t/app-perlbrew-path-installation.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 Test2::Tools::Spec;

use File::Temp qw[];

use Test::Spec;
use Test::Deep;

use App::Perlbrew::Path::Root;
use App::Perlbrew::Path::Installation;
use App::Perlbrew::Path::Installations;
Expand All @@ -19,30 +16,27 @@ sub arrange_installation;

describe "App::Perlbrew::Path::Root" => sub {
describe "perls()" => sub {
context "without parameters" => sub {
describe "without parameters" => sub {
it "should return Instalations object" => sub {
local $ENV{HOME};
my $path = arrange_root->perls;

cmp_deeply $path, looks_like_perl_installations("~/.root/perls");
is $path, looks_like_perl_installations("~/.root/perls");
};
};

context "with one parameter" => sub {
describe "with one parameter" => sub {
it "should return Installation object" => sub {
local $ENV{HOME};
my $path = arrange_root->perls('blead');

cmp_deeply $path, looks_like_perl_installation("~/.root/perls/blead");
is $path, looks_like_perl_installation("~/.root/perls/blead");
};
};

context "with multiple paramters" => sub {
describe "with multiple paramters" => sub {
it "should return Path object" => sub {
local $ENV{HOME};
my $path = arrange_root->perls('blead', '.version');

cmp_deeply $path, looks_like_path("~/.root/perls/blead/.version");
is $path, looks_like_path("~/.root/perls/blead/.version");
};
}
};
Expand All @@ -58,7 +52,7 @@ describe "App::Perlbrew::Path::Installations" => sub {

my @list = $root->perls->list;

cmp_deeply \@list, [
is \@list, [
looks_like_perl_installation("~/.root/perls/perl-1"),
looks_like_perl_installation("~/.root/perls/perl-2"),
];
Expand All @@ -71,27 +65,24 @@ describe "App::Perlbrew::Path::Installation" => sub {
it "should return installation name" => sub {
local $ENV{HOME};
my $installation = arrange_installation('foo-bar');

cmp_deeply $installation->name, 'foo-bar';
is $installation->name, 'foo-bar';
};

it "should provide path to perl" => sub {
local $ENV{HOME};
my $perl = arrange_installation('foo-bar')->perl;

cmp_deeply $perl->stringify_with_tilde, '~/.root/perls/foo-bar/bin/perl';
is $perl->stringify_with_tilde, '~/.root/perls/foo-bar/bin/perl';
};

it "should provide path to version file" => sub {
local $ENV{HOME};
my $file = arrange_installation('foo-bar')->version_file;

cmp_deeply $file->stringify_with_tilde, '~/.root/perls/foo-bar/.version';
is $file->stringify_with_tilde, '~/.root/perls/foo-bar/.version';
};
};
};

runtests unless caller;
done_testing;

sub looks_like_path {
my ($path, @tests) = @_;
Expand All @@ -101,19 +92,18 @@ sub looks_like_path {
: 'stringify'
;

all(
methods($method => $path),
Isa('App::Perlbrew::Path'),
@tests,
);
object {
call $method => $path;
prop isa => 'App::Perlbrew::Path';
};
}

sub looks_like_perl_installation {
looks_like_path(@_, Isa('App::Perlbrew::Path::Installation'));
looks_like_path(@_, object { prop isa => 'App::Perlbrew::Path::Installation' });
}

sub looks_like_perl_installations {
looks_like_path(@_, Isa('App::Perlbrew::Path::Installations'));
looks_like_path(@_, object { prop isa => 'App::Perlbrew::Path::Installation' });
}

sub arrange_root {
Expand Down
12 changes: 5 additions & 7 deletions t/command-alias.t
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#!/usr/bin/env perl
#!/usr/bin/env perl
use strict;
use warnings;
use Test2::V0;
use Test2::Tools::Spec;

BEGIN { $ENV{SHELL} = "/bin/bash" }

use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
require "test_helpers.pl";
require "test2_helpers.pl";

use Test::Spec;
use Test::Output;
use Config;

mock_perlbrew_install("perl-5.14.1");
mock_perlbrew_lib_create('perl-5.14.1@nobita');

describe "alias command," => sub {
before each => sub {
before_each 'cleanup env' => sub {
delete $ENV{PERL_MB_OPT};
delete $ENV{PERL_MM_OPT};
delete $ENV{PERL_LOCAL_LIB_ROOT};
Expand All @@ -44,4 +42,4 @@ describe "alias command," => sub {
};
};

runtests unless caller;
done_testing;
24 changes: 15 additions & 9 deletions t/command-available.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::Spec;
use Test2::V0;
use Test2::Tools::Spec;
use File::Temp qw( tempdir );
use Test::Output;

Expand All @@ -28,13 +27,18 @@ my %available_perl_dists = (

sub mocked_perlbrew {
my $app = App::perlbrew->new( @_ );
$app->expects( 'available_perl_distributions' )->returns( \%available_perl_dists );
return $app;

my $mock = mock $app,
override => [
available_perl_distributions => sub { \%available_perl_dists }
];

return ($mock, $app);
}

describe "available command output, when nothing installed locally," => sub {
it "should display a list of perl versions" => sub {
my $app = mocked_perlbrew( "available", "--verbose" );
my ($mock, $app) = mocked_perlbrew( "available", "--verbose" );

stdout_like sub {
$app->run();
Expand All @@ -60,14 +64,16 @@ describe "available command output, when nothing installed locally," => sub {

describe "available command output, when something installed locally," => sub {
it "should display a list of perl versions, with markers on installed versions" => sub {
my $app = mocked_perlbrew( "available", "--verbose" );
my ($mock, $app) = mocked_perlbrew( "available", "--verbose" );

my @installed_perls = (
{ name => "perl-5.24.0" },
{ name => "perl-5.20.3" }
);

$app->expects("installed_perls")->returns(@installed_perls);
$mock->override(
"installed_perls" => sub { @installed_perls }
);

stdout_like sub {
$app->run();
Expand All @@ -94,4 +100,4 @@ describe "available command output, when something installed locally," => sub {
};
};

runtests unless caller;
done_testing;
20 changes: 11 additions & 9 deletions t/command-clone-modules.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test2::V0;
use Test2::Tools::Spec;

BEGIN { $ENV{SHELL} = "/bin/bash" }

use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
require "test_helpers.pl";

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

mock_perlbrew_install("perl-5.14.1");
mock_perlbrew_install("perl-5.16.0");
Expand All @@ -33,7 +31,7 @@ sub App::perlbrew::run_command_exec {
use warnings;

describe "clone-modules command," => sub {
before each => sub {
before_each 'cleanup env' => sub {
delete $ENV{PERL_MB_OPT};
delete $ENV{PERL_MM_OPT};
delete $ENV{PERL_LOCAL_LIB_ROOT};
Expand Down Expand Up @@ -71,26 +69,30 @@ describe "clone-modules command," => sub {
describe "when invoked with one argument X", sub {
it "should display clone modules from current-perl to X", sub {
my $app = App::perlbrew->new("clone-modules", "perl-5.14.1");
$app->expects("current_env")->returns("perl-5.16.0")->at_least(1);

my $mock = mocked($app)->expects("current_env")->returns("perl-5.16.0")->at_least(1);
$app->run;

is $__from, "perl-5.16.0";
is $__to, "perl-5.14.1";
ok(!defined($__notest));

$mock->verify;
};
};

describe "when invoked with one argument X, with `--notest`", sub {
it "should display clone modules from current-perl to X", sub {
my $app = App::perlbrew->new("clone-modules", "--notest", "perl-5.14.1");
$app->expects("current_env")->returns("perl-5.16.0")->at_least(1);
my $mock = mocked($app)->expects("current_env")->returns("perl-5.16.0")->at_least(1);
$app->run;

is $__from, "perl-5.16.0";
is $__to, "perl-5.14.1";
ok(defined($__notest));
$mock->verify;
};
};
};

runtests unless caller;
done_testing;
10 changes: 4 additions & 6 deletions t/command-compgen.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test2::V0;
use Test2::Tools::Spec;

use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
require "test_helpers.pl";
require "test2_helpers.pl";

use Test::Spec;
use Test::Output qw( stdout_from );

$ENV{PERLBREW_DEBUG_COMPLETION} = 0;
Expand Down Expand Up @@ -84,5 +83,4 @@ describe "compgen command," => sub {
}
};

runtests unless caller;

done_testing;
11 changes: 5 additions & 6 deletions t/command-env.t
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test2::V0;
use Test2::Tools::Spec;

BEGIN { $ENV{SHELL} = "/bin/bash" }

use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
require "test_helpers.pl";
require "test2_helpers.pl";

use Test::Spec;
use Test::Output;
use Config;

mock_perlbrew_install("perl-5.14.1");
mock_perlbrew_lib_create('perl-5.14.1@nobita');

describe "env command," => sub {
before each => sub {
before_each 'cleanup env' => sub {
delete $ENV{PERL_MB_OPT};
delete $ENV{PERL_MM_OPT};
delete $ENV{PERL_LOCAL_LIB_ROOT};
Expand Down Expand Up @@ -98,4 +97,4 @@ OUT
}
};

runtests unless caller;
done_testing;
Loading
Loading