Skip to content

Commit

Permalink
Merge pull request #814 from gugod/replace-test-output
Browse files Browse the repository at this point in the history
Replace Test::Output
  • Loading branch information
gugod authored Aug 31, 2024
2 parents 9a786cd + 1390a06 commit 32b4d65
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Build.PL
Original file line number Diff line number Diff line change
@@ -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();
5 changes: 2 additions & 3 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Kang-min Liu C<< <[email protected]> >>"
],
"dynamic_config" : 0,
"generated_by" : "App::ModuleBuildTiny version 0.041",
"generated_by" : "App::ModuleBuildTiny version 0.047",
"license" : [
"mit"
],
Expand All @@ -21,7 +21,7 @@
},
"develop" : {
"requires" : {
"App::ModuleBuildTiny" : "0.041",
"App::ModuleBuildTiny" : "0.047",
"Pod::Markdown" : "2.002"
}
},
Expand All @@ -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"
}
Expand Down
3 changes: 1 addition & 2 deletions META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
48 changes: 48 additions & 0 deletions t/PerlbrewTestHelpers.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package PerlbrewTestHelpers;
use Test2::V0;
use Test2::Plugin::IOEvents;

use Exporter 'import';
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);
}

sub stdout_is (&$;$) {
my ($cb, $expected, $desc) = @_;
is(stdout_from(sub { $cb->() }), $expected, $desc);
}

sub stdout_like (&$;$) {
my ($cb, $re, $desc) = @_;
like(stdout_from(sub { $cb->() }), $re, $desc);
}


1;
5 changes: 2 additions & 3 deletions t/command-alias.t
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/env perl
use Test2::V0;
use Test2::Tools::Spec;
use Config;

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

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');
Expand Down
7 changes: 6 additions & 1 deletion t/command-available.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
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";

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 );

Expand Down
3 changes: 1 addition & 2 deletions t/command-compgen.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 2 additions & 3 deletions t/command-env.t
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/env perl
use Test2::V0;
use Test2::Tools::Spec;
use Config;

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

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');
Expand Down
3 changes: 1 addition & 2 deletions t/command-exec.t
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 4 additions & 1 deletion t/command-info.t
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/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";
use PerlbrewTestHelpers qw(stdout_like);

describe "info command" => sub {
it "should display info if under perlbrew perl" => sub {
Expand Down
4 changes: 4 additions & 0 deletions t/test2_helpers.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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(@_);
Expand Down

0 comments on commit 32b4d65

Please sign in to comment.