[carton] 73/472: capture system output like cpanm in the tests
Lucas Kanashiro
kanashiro-guest at moszumanska.debian.org
Fri Jul 24 00:38:34 UTC 2015
This is an automated email from the git hooks/post-receive script.
kanashiro-guest pushed a commit to branch master
in repository carton.
commit f389280a8265a231a198c7b18b89a6909fd83f1b
Author: Tatsuhiko Miyagawa <miyagawa at bulknews.net>
Date: Tue Jun 28 11:48:54 2011 -0400
capture system output like cpanm in the tests
---
xt/CLI.pm | 15 ++++++++++++---
xt/cli/exec.t | 24 ++++++------------------
2 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/xt/CLI.pm b/xt/CLI.pm
index f1cd674..fcff297 100644
--- a/xt/CLI.pm
+++ b/xt/CLI.pm
@@ -3,7 +3,7 @@ use strict;
use base qw(Exporter);
our @EXPORT = qw(run cli);
-use Test::Requires qw( Directory::Scratch );
+use Test::Requires qw( Directory::Scratch Capture::Tiny );
sub cli {
my $dir = Directory::Scratch->new();
@@ -24,6 +24,8 @@ sub run {
package Carton::CLI::Tested;
use parent qw(Carton::CLI);
+use Capture::Tiny qw(capture_merged);
+
sub new {
my($class, %args) = @_;
@@ -44,9 +46,11 @@ sub print {
}
sub run {
- my $self = shift;
+ my($self, @args) = @_;
$self->{output} = '';
- $self->SUPER::run(@_);
+ $self->{system_output} = capture_merged {
+ $self->SUPER::run(@args);
+ };
}
sub output {
@@ -54,5 +58,10 @@ sub output {
$self->{output};
}
+sub system_output {
+ my $self = shift;
+ $self->{system_output};
+}
+
1;
diff --git a/xt/cli/exec.t b/xt/cli/exec.t
index bcac34a..223d1dd 100644
--- a/xt/cli/exec.t
+++ b/xt/cli/exec.t
@@ -2,33 +2,21 @@ use strict;
use Test::More;
use xt::CLI;
-use Test::Requires qw(Capture::Tiny);
-use Capture::Tiny qw(capture_merged);
-
{
my $app = cli();
- ok 1;
-
- my $out = capture_merged {
- $app->run("exec", "--system", "--", "perl", "-e", "use Try::Tiny");
- };
-
- like $out, qr/Can't locate Try\/Tiny.pm/;
+ $app->run("exec", "--system", "--", "perl", "-e", "use Try::Tiny");
+ like $app->system_output, qr/Can't locate Try\/Tiny.pm/;
$app->run("install", "Try::Tiny");
- $out = capture_merged {
- $app->run("exec", "--system", "--", "perl", "-e", 'use Try::Tiny; print "OK\n"');
- };
+ $app->run("exec", "--system", "--", "perl", "-e", 'use Try::Tiny; print "OK\n"');
- like $out, qr/OK/;
+ like $app->system_output, qr/OK/;
$app->run("install", "Mojolicious");
- $out = capture_merged {
- $app->run("exec", "--system", "--", "mojolicious", "version");
- };
+ $app->run("exec", "--system", "--", "mojolicious", "version");
- like $out, qr/Mojolicious/;
+ like $app->system_output, qr/Mojolicious/;
}
done_testing;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/carton.git
More information about the Pkg-perl-cvs-commits
mailing list