From ec17913104d295ab478b716b9420fcd96cb688ac Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Fri, 30 Aug 2024 10:17:18 +0900 Subject: [PATCH 1/9] replace Test::Output::stdout_like with the one redefined using Test2 --- t/command-available.t | 13 ++++++++----- t/test2_helpers.pl | 13 +++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/t/command-available.t b/t/command-available.t index d9223925..c2a1e6d3 100644 --- a/t/command-available.t +++ b/t/command-available.t @@ -2,9 +2,12 @@ use Test2::V0; use Test2::Tools::Spec; use File::Temp qw( tempdir ); -use Test::Output; +use FindBin; +use lib $FindBin::Bin; use App::perlbrew; +require "test2_helpers.pl"; + $App::perlbrew::PERLBREW_ROOT = my $perlbrew_root = tempdir( CLEANUP => 1 ); $App::perlbrew::PERLBREW_HOME = my $perlbrew_home = tempdir( CLEANUP => 1 ); @@ -40,7 +43,7 @@ describe "available command output, when nothing installed locally," => sub { it "should display a list of perl versions" => sub { my ($mock, $app) = mocked_perlbrew( "available", "--verbose" ); - stdout_like sub { + stdout_like(sub { $app->run(); }, qr{ \A @@ -58,7 +61,7 @@ describe "available command output, when nothing installed locally," => sub { \n )+ \z - }sx; + }sx); }; }; @@ -75,7 +78,7 @@ describe "available command output, when something installed locally," => sub { "installed_perls" => sub { @installed_perls } ); - stdout_like sub { + stdout_like(sub { $app->run(); }, qr{ \A @@ -96,7 +99,7 @@ describe "available command output, when something installed locally," => sub { \n )+ \z - }sx; + }sx); }; }; diff --git a/t/test2_helpers.pl b/t/test2_helpers.pl index 8d41ff69..18faf7c0 100644 --- a/t/test2_helpers.pl +++ b/t/test2_helpers.pl @@ -15,9 +15,13 @@ =cut use Test2::V0; +use Test2::Plugin::IOEvents; use IO::All; use File::Temp qw( tempdir ); +use App::Perlbrew::Path; +use App::Perlbrew::Path::Root; + no warnings 'redefine'; sub dir { App::Perlbrew::Path->new(@_); @@ -100,6 +104,15 @@ sub mock_perlbrew_lib_create { App::Perlbrew::Path->new($App::perlbrew::PERLBREW_HOME, "libs", $name)->mkpath; } +# Replacements of Test::Output made by using Test2::Plugin::IOEvents + +sub stdout_like { + my ($cb, $re, $desc) = @_; + my $events = intercept { $cb->() }; + my $out = join "", map { $_->details } map { @{ $_->facets->{info} } }@$events; + like($out, $re, $desc); +} + # Wrappers around Test2::Tools::Mock, a replacement of Test::Spec, more or less. sub mocked { From ce8c08fabf1eefc7103050fd16b23b2a0d484d2d Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Fri, 30 Aug 2024 10:19:32 +0900 Subject: [PATCH 2/9] replace Test::Output::stdout_like with the one redefined using Test2 --- t/command-info.t | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/t/command-info.t b/t/command-info.t index feacd7fa..67ca5b51 100644 --- a/t/command-info.t +++ b/t/command-info.t @@ -1,11 +1,13 @@ #!/usr/bin/env perl use Test2::V0; use Test2::Tools::Spec; -use Test::Output; use File::Spec; use Config; +use FindBin; +use lib $FindBin::Bin; use App::perlbrew; +require "test2_helpers.pl"; describe "info command" => sub { it "should display info if under perlbrew perl" => sub { @@ -43,9 +45,9 @@ perlbrew: PERLBREW_MANPATH: perlbrew_manpath_value OUT - stdout_like sub { + stdout_like(sub { $app->run(); - }, qr/$expected/; + }, qr/$expected/); }; it "should display info if under system perl" => sub { my $app = App::perlbrew->new("info"); @@ -78,9 +80,9 @@ perlbrew: PERLBREW_MANPATH: perlbrew_manpath_value OUT - stdout_like sub { + stdout_like(sub { $app->run(); - }, qr/$expected/; + }, qr/$expected/); }; it "should display info for a module if the module is installed" => sub { @@ -128,10 +130,10 @@ Module: \Q$module_name\E Version: [\\d\\._]+ OUT - stdout_like sub { + stdout_like(sub { $app->{args} = [ "info", $module_name]; $app->run(); - }, qr/$expected/; + }, qr/$expected/); }; it "should display a message that the module can't be found if the module isn't installed" => sub { @@ -173,10 +175,10 @@ perlbrew: Module: $module_name could not be found, is it installed?.* OUT - stdout_like sub { + stdout_like(sub { $app->{args} = [ "info", $module_name]; $app->run(); - }, qr/$expected/; + }, qr/$expected/); }; }; From bd202ec2ca6f2f58710ddd3254cb2cd22f09470e Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Fri, 30 Aug 2024 18:50:10 +0900 Subject: [PATCH 3/9] make a module to place test helpers. subroutine-importing works better with `use`. `require` does not seem to make those subs defined in test2_heplers.pl be recognized as subroutines in the caller of require like what `use`. When calling subroutines from test2_elpers, we always have to add parenthesis, which might look sub-optimal. --- t/PerlbrewTestHelpers.pm | 18 ++++++++++++++++++ t/command-available.t | 10 ++++++---- t/command-info.t | 17 +++++++++-------- t/test2_helpers.pl | 9 --------- 4 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 t/PerlbrewTestHelpers.pm diff --git a/t/PerlbrewTestHelpers.pm b/t/PerlbrewTestHelpers.pm new file mode 100644 index 00000000..17bb785c --- /dev/null +++ b/t/PerlbrewTestHelpers.pm @@ -0,0 +1,18 @@ +package PerlbrewTestHelpers; +use Test2::V0; +use Test2::Plugin::IOEvents; + +use Exporter 'import'; +our @EXPORT_OK = qw(stdout_like); + +# Replacements of Test::Output made by using Test2::Plugin::IOEvents + +sub stdout_like { + my ($cb, $re, $desc) = @_; + my $events = intercept { $cb->() }; + my $out = join "", map { $_->details } map { @{ $_->facets->{info} } }@$events; + like($out, $re, $desc); +} + + +1; diff --git a/t/command-available.t b/t/command-available.t index c2a1e6d3..d6a29011 100644 --- a/t/command-available.t +++ b/t/command-available.t @@ -8,6 +8,8 @@ use lib $FindBin::Bin; use App::perlbrew; require "test2_helpers.pl"; +use PerlbrewTestHelpers qw(stdout_like); + $App::perlbrew::PERLBREW_ROOT = my $perlbrew_root = tempdir( CLEANUP => 1 ); $App::perlbrew::PERLBREW_HOME = my $perlbrew_home = tempdir( CLEANUP => 1 ); @@ -43,7 +45,7 @@ describe "available command output, when nothing installed locally," => sub { it "should display a list of perl versions" => sub { my ($mock, $app) = mocked_perlbrew( "available", "--verbose" ); - stdout_like(sub { + stdout_like sub { $app->run(); }, qr{ \A @@ -61,7 +63,7 @@ describe "available command output, when nothing installed locally," => sub { \n )+ \z - }sx); + }sx; }; }; @@ -78,7 +80,7 @@ describe "available command output, when something installed locally," => sub { "installed_perls" => sub { @installed_perls } ); - stdout_like(sub { + stdout_like sub { $app->run(); }, qr{ \A @@ -99,7 +101,7 @@ describe "available command output, when something installed locally," => sub { \n )+ \z - }sx); + }sx; }; }; diff --git a/t/command-info.t b/t/command-info.t index 67ca5b51..78fd116b 100644 --- a/t/command-info.t +++ b/t/command-info.t @@ -8,6 +8,7 @@ use FindBin; use lib $FindBin::Bin; use App::perlbrew; require "test2_helpers.pl"; +use PerlbrewTestHelpers qw(stdout_like); describe "info command" => sub { it "should display info if under perlbrew perl" => sub { @@ -45,9 +46,9 @@ perlbrew: PERLBREW_MANPATH: perlbrew_manpath_value OUT - stdout_like(sub { + stdout_like sub { $app->run(); - }, qr/$expected/); + }, qr/$expected/; }; it "should display info if under system perl" => sub { my $app = App::perlbrew->new("info"); @@ -80,9 +81,9 @@ perlbrew: PERLBREW_MANPATH: perlbrew_manpath_value OUT - stdout_like(sub { + stdout_like sub { $app->run(); - }, qr/$expected/); + }, qr/$expected/; }; it "should display info for a module if the module is installed" => sub { @@ -130,10 +131,10 @@ Module: \Q$module_name\E Version: [\\d\\._]+ OUT - stdout_like(sub { + stdout_like sub { $app->{args} = [ "info", $module_name]; $app->run(); - }, qr/$expected/); + }, qr/$expected/; }; it "should display a message that the module can't be found if the module isn't installed" => sub { @@ -175,10 +176,10 @@ perlbrew: Module: $module_name could not be found, is it installed?.* OUT - stdout_like(sub { + stdout_like sub { $app->{args} = [ "info", $module_name]; $app->run(); - }, qr/$expected/); + }, qr/$expected/; }; }; diff --git a/t/test2_helpers.pl b/t/test2_helpers.pl index 18faf7c0..4708b9bf 100644 --- a/t/test2_helpers.pl +++ b/t/test2_helpers.pl @@ -104,15 +104,6 @@ sub mock_perlbrew_lib_create { App::Perlbrew::Path->new($App::perlbrew::PERLBREW_HOME, "libs", $name)->mkpath; } -# Replacements of Test::Output made by using Test2::Plugin::IOEvents - -sub stdout_like { - my ($cb, $re, $desc) = @_; - my $events = intercept { $cb->() }; - my $out = join "", map { $_->details } map { @{ $_->facets->{info} } }@$events; - like($out, $re, $desc); -} - # Wrappers around Test2::Tools::Mock, a replacement of Test::Spec, more or less. sub mocked { From e367c909c006bf6be4cba1c08a3c0a82825eee41 Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Sat, 31 Aug 2024 10:09:27 +0900 Subject: [PATCH 4/9] replace stdout_is with the one from PerlbrewTestHelpers --- t/PerlbrewTestHelpers.pm | 21 ++++++++++++++++----- t/command-env.t | 5 ++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/t/PerlbrewTestHelpers.pm b/t/PerlbrewTestHelpers.pm index 17bb785c..6241bae3 100644 --- a/t/PerlbrewTestHelpers.pm +++ b/t/PerlbrewTestHelpers.pm @@ -3,15 +3,26 @@ use Test2::V0; use Test2::Plugin::IOEvents; use Exporter 'import'; -our @EXPORT_OK = qw(stdout_like); +our @EXPORT_OK = qw(stdout_is stdout_like); # Replacements of Test::Output made by using Test2::Plugin::IOEvents -sub stdout_like { - my ($cb, $re, $desc) = @_; +sub capture_stdout { + my ($cb) = @_; my $events = intercept { $cb->() }; - my $out = join "", map { $_->details } map { @{ $_->facets->{info} } }@$events; - like($out, $re, $desc); + + + return join "", map { $_->details } grep { $_->tag eq 'STDOUT' } map { @{ $_->facets->{info} } }@$events; +} + +sub stdout_is (&$;$) { + my ($cb, $expected, $desc) = @_; + is(capture_stdout($cb), $expected, $desc); +} + +sub stdout_like (&$;$) { + my ($cb, $re, $desc) = @_; + like(capture_stdout($cb), $re, $desc); } diff --git a/t/command-env.t b/t/command-env.t index 1be3e4e5..48e8f61d 100644 --- a/t/command-env.t +++ b/t/command-env.t @@ -1,6 +1,7 @@ #!/usr/bin/env perl use Test2::V0; use Test2::Tools::Spec; +use Config; BEGIN { $ENV{SHELL} = "/bin/bash" } @@ -8,9 +9,7 @@ use FindBin; use lib $FindBin::Bin; use App::perlbrew; require "test2_helpers.pl"; - -use Test::Output; -use Config; +use PerlbrewTestHelpers qw(stdout_is); mock_perlbrew_install("perl-5.14.1"); mock_perlbrew_lib_create('perl-5.14.1@nobita'); From dfba19ba9d50a42d79f5a2338040f610dc9caafe Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Sat, 31 Aug 2024 10:16:35 +0900 Subject: [PATCH 5/9] replace stdout_from with the one from PerlbrewTestHelpers --- t/PerlbrewTestHelpers.pm | 10 ++++------ t/command-compgen.t | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/t/PerlbrewTestHelpers.pm b/t/PerlbrewTestHelpers.pm index 6241bae3..71e08c73 100644 --- a/t/PerlbrewTestHelpers.pm +++ b/t/PerlbrewTestHelpers.pm @@ -3,26 +3,24 @@ use Test2::V0; use Test2::Plugin::IOEvents; use Exporter 'import'; -our @EXPORT_OK = qw(stdout_is stdout_like); +our @EXPORT_OK = qw(stdout_from stdout_is stdout_like); # Replacements of Test::Output made by using Test2::Plugin::IOEvents -sub capture_stdout { +sub stdout_from (&) { my ($cb) = @_; my $events = intercept { $cb->() }; - - return join "", map { $_->details } grep { $_->tag eq 'STDOUT' } map { @{ $_->facets->{info} } }@$events; } sub stdout_is (&$;$) { my ($cb, $expected, $desc) = @_; - is(capture_stdout($cb), $expected, $desc); + is(stdout_from(sub { $cb->() }), $expected, $desc); } sub stdout_like (&$;$) { my ($cb, $re, $desc) = @_; - like(capture_stdout($cb), $re, $desc); + like(stdout_from(sub { $cb->() }), $re, $desc); } diff --git a/t/command-compgen.t b/t/command-compgen.t index d4affa3c..be39f5de 100644 --- a/t/command-compgen.t +++ b/t/command-compgen.t @@ -6,8 +6,7 @@ use FindBin; use lib $FindBin::Bin; use App::perlbrew; require "test2_helpers.pl"; - -use Test::Output qw( stdout_from ); +use PerlbrewTestHelpers qw( stdout_from ); $ENV{PERLBREW_DEBUG_COMPLETION} = 0; From f43ed596b99bf573351dbdc5ce6f5f4f320f354e Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Sat, 31 Aug 2024 11:00:58 +0900 Subject: [PATCH 6/9] replace stderr_is and stderr_like with the ones from PerlbrewTestHelpers --- t/PerlbrewTestHelpers.pm | 26 ++++++++++++++++++++++++-- t/command-alias.t | 5 ++--- t/command-exec.t | 3 +-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/t/PerlbrewTestHelpers.pm b/t/PerlbrewTestHelpers.pm index 71e08c73..51c89db7 100644 --- a/t/PerlbrewTestHelpers.pm +++ b/t/PerlbrewTestHelpers.pm @@ -3,14 +3,36 @@ use Test2::V0; use Test2::Plugin::IOEvents; use Exporter 'import'; -our @EXPORT_OK = qw(stdout_from stdout_is stdout_like); +our @EXPORT_OK = qw(stderr_from stderr_is stderr_like stdout_from stdout_is stdout_like); # Replacements of Test::Output made by using Test2::Plugin::IOEvents +sub ioevents_from { + my ($cb) = @_; + return grep { $_->tag eq 'STDOUT' || $_->tag eq 'STDERR' } + map { @{ $_->facets->{info} } } + @{ intercept(sub { $cb->() }) }; +} + +sub stderr_from (&) { + my ($cb) = @_; + join "", map { $_->details } grep { $_->tag eq 'STDERR' } ioevents_from($cb); +} + +sub stderr_is (&$;$) { + my ($cb, $expected, $desc) = @_; + is(stderr_from(sub { $cb->() }), $expected, $desc); +} + +sub stderr_like (&$;$) { + my ($cb, $re, $desc) = @_; + like(stderr_from(sub { $cb->() }), $re, $desc); +} + sub stdout_from (&) { my ($cb) = @_; + return join "", map { $_->details } grep { $_->tag eq 'STDOUT' } ioevents_from($cb); my $events = intercept { $cb->() }; - return join "", map { $_->details } grep { $_->tag eq 'STDOUT' } map { @{ $_->facets->{info} } }@$events; } sub stdout_is (&$;$) { diff --git a/t/command-alias.t b/t/command-alias.t index 62b5e894..049625bb 100644 --- a/t/command-alias.t +++ b/t/command-alias.t @@ -1,6 +1,7 @@ #!/usr/bin/env perl use Test2::V0; use Test2::Tools::Spec; +use Config; BEGIN { $ENV{SHELL} = "/bin/bash" } @@ -8,9 +9,7 @@ use FindBin; use lib $FindBin::Bin; use App::perlbrew; require "test2_helpers.pl"; - -use Test::Output; -use Config; +use PerlbrewTestHelpers qw(stderr_like); mock_perlbrew_install("perl-5.14.1"); mock_perlbrew_lib_create('perl-5.14.1@nobita'); diff --git a/t/command-exec.t b/t/command-exec.t index 855e1b7d..47657c71 100644 --- a/t/command-exec.t +++ b/t/command-exec.t @@ -6,8 +6,7 @@ use FindBin; use lib $FindBin::Bin; use App::perlbrew; require 'test2_helpers.pl'; - -use Test::Output; +use PerlbrewTestHelpers qw(stderr_is); mock_perlbrew_install("perl-5.12.3"); mock_perlbrew_install("perl-5.12.4"); From 9b12207997a6a68093dd2536248ccab4aa747325 Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Sat, 31 Aug 2024 11:01:16 +0900 Subject: [PATCH 7/9] remove Test::Output from the list of dependencies --- cpanfile | 1 - 1 file changed, 1 deletion(-) diff --git a/cpanfile b/cpanfile index 7571b47d..e6eb8c73 100644 --- a/cpanfile +++ b/cpanfile @@ -17,7 +17,6 @@ on test => sub { requires 'Path::Class' => '0.33'; requires 'Test::More' => '1.001002'; requires 'Test::NoWarnings' => '1.04'; - requires 'Test::Output' => '1.03'; requires 'Test::Simple' => '1.001002'; requires 'Test::TempDir::Tiny' => '0.016'; requires 'Test2::V0' => '0.000163'; From 9fe91200842a85b2c1c5c0d31e08e526c23a3a9f Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Sat, 31 Aug 2024 11:08:23 +0900 Subject: [PATCH 8/9] Remove an unreachable statement --- t/PerlbrewTestHelpers.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/t/PerlbrewTestHelpers.pm b/t/PerlbrewTestHelpers.pm index 51c89db7..b7cb0ccc 100644 --- a/t/PerlbrewTestHelpers.pm +++ b/t/PerlbrewTestHelpers.pm @@ -32,7 +32,6 @@ sub stderr_like (&$;$) { sub stdout_from (&) { my ($cb) = @_; return join "", map { $_->details } grep { $_->tag eq 'STDOUT' } ioevents_from($cb); - my $events = intercept { $cb->() }; } sub stdout_is (&$;$) { From 1390a0639b9b9ac6ba5c90f643a683145130b9c0 Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Sat, 31 Aug 2024 11:14:12 +0900 Subject: [PATCH 9/9] `mbtiny regenerate` --- Build.PL | 2 +- META.json | 5 ++--- META.yml | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Build.PL b/Build.PL index 886b160f..8d2ec618 100644 --- a/Build.PL +++ b/Build.PL @@ -1,4 +1,4 @@ -# This Build.PL for App-perlbrew was generated by mbtiny 0.041. +# This Build.PL for App-perlbrew was generated by mbtiny 0.047. use 5.008; use Module::Build::Tiny 0.039; Build_PL(); diff --git a/META.json b/META.json index 70ccac25..565133d6 100644 --- a/META.json +++ b/META.json @@ -4,7 +4,7 @@ "Kang-min Liu C<< >>" ], "dynamic_config" : 0, - "generated_by" : "App::ModuleBuildTiny version 0.041", + "generated_by" : "App::ModuleBuildTiny version 0.047", "license" : [ "mit" ], @@ -21,7 +21,7 @@ }, "develop" : { "requires" : { - "App::ModuleBuildTiny" : "0.041", + "App::ModuleBuildTiny" : "0.047", "Pod::Markdown" : "2.002" } }, @@ -48,7 +48,6 @@ "Test2::V0" : "0.000163", "Test::More" : "1.001002", "Test::NoWarnings" : "1.04", - "Test::Output" : "1.03", "Test::Simple" : "1.001002", "Test::TempDir::Tiny" : "0.016" } diff --git a/META.yml b/META.yml index 2d5cbf97..1a29ea43 100644 --- a/META.yml +++ b/META.yml @@ -11,13 +11,12 @@ build_requires: Test2::V0: '0.000163' Test::More: '1.001002' Test::NoWarnings: '1.04' - Test::Output: '1.03' Test::Simple: '1.001002' Test::TempDir::Tiny: '0.016' configure_requires: Module::Build::Tiny: '0.039' dynamic_config: 0 -generated_by: 'App::ModuleBuildTiny version 0.041, CPAN::Meta::Converter version 2.150010' +generated_by: 'App::ModuleBuildTiny version 0.047, CPAN::Meta::Converter version 2.150010' license: mit meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html