Skip to content

Commit

Permalink
Update t/command-list.t to use Test2
Browse files Browse the repository at this point in the history
  • Loading branch information
lukec committed Jun 13, 2024
1 parent 26773e3 commit 946972f
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions t/command-list.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test2::V0;
use Test2::Plugin::IOEvents;
use Test2::Tools::Spec;

BEGIN {
delete $ENV{PERLBREW_HOME};
Expand All @@ -12,11 +13,9 @@ use FindBin;
use lib $FindBin::Bin;

use App::perlbrew;
require "test_helpers.pl";
require "test2_helpers.pl";

use File::Spec::Functions qw( catdir );
use Test::Spec;
use Test::Output qw( stdout_like );

mock_perlbrew_install("perl-5.12.3");
mock_perlbrew_install("perl-5.12.4");
Expand All @@ -32,12 +31,17 @@ describe "list command," => sub {
describe "when there no libs under PERLBREW_HOME,", sub {
it "displays a list of perl installation names", sub {
my $app = App::perlbrew->new("list");
stdout_like sub { $app->run(); }, qr/^(\s|\*)\sc?perl-?\d\.\d{1,3}[_.]\d{1,2}\s+/, 'Cannot find Perl in output'
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';
};
};

describe "when there are lib under PERLBREW_HOME,", sub {
before each => sub {
before_each setup_dirs => sub {
unless ( -d catdir($App::perlbrew::PERLBREW_HOME, "libs", 'perl-5.12.3@nobita') ) {
App::perlbrew->new("lib", "create", "nobita")->run;
}
Expand All @@ -48,28 +52,50 @@ describe "list command," => sub {

it "displays lib names" => sub {
my $app = App::perlbrew->new("list");
stdout_like sub { $app->run(); }, qr/^(\s|\*)\sc?perl-?\d\.\d{1,3}[_.]\d{1,2}(@\w+)?/, 'Cannot find Perl with libraries in output'
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';
};

it "marks currently activated lib", sub {
$ENV{PERLBREW_LIB} = "nobita";
my $app = App::perlbrew->new("list");
stdout_like sub { $app->run(); }, qr/^(\s|\*)\sc?perl-?\d\.\d{1,3}[_.]\d{1,2}(\@nobita)?/, 'Cannot find Perl with libraries in output'

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';
};
describe "when `--no-decoration` is given", sub {
it "does not mark anything", sub {
$ENV{PERLBREW_LIB} = "nobita";
my $app = App::perlbrew->new("list", "--no-decoration");
stdout_like sub { $app->run(); }, qr/^perl-?\d\.\d{1,3}[_.]\d{1,2}(@\w+)?/, 'No decoration mark in the output';
};
my $app;
my $events = intercept {
$app = App::perlbrew->new("list", "--no-decoration");
$app->run();
};
like $events,
[
{info => [{tag => 'STDOUT', details => qr/^perl-?\d\.\d{1,3}[_.]\d{1,2}(@\w+)?/}]}
],
'No decoration mark in the output';
};
};
};

describe "when `--no-decoration` is given", sub {
my $app = App::perlbrew->new("list", "--no-decoration");
stdout_like sub { $app->run(); }, qr/^perl-?\d\.\d{1,3}[_.]\d{1,2}(@\w+)?/, 'No decoration mark in the output';
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';
};
};

runtests unless caller;
done_testing;

0 comments on commit 946972f

Please sign in to comment.