Skip to content

Commit

Permalink
replace stderr_is and stderr_like with the ones from PerlbrewTestHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
gugod committed Aug 31, 2024
1 parent dfba19b commit f43ed59
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
26 changes: 24 additions & 2 deletions t/PerlbrewTestHelpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 (&$;$) {
Expand Down
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
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

0 comments on commit f43ed59

Please sign in to comment.