From c3f8be419c0674c8a6fdb64bddd841a0957adf28 Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Fri, 2 Dec 2011 08:39:19 +0200 Subject: [PATCH 1/1] upgrade Capture::Tiny and use the new capture_stderr --- Makefile.PL | 2 +- t/eta-linear.t | 5 ++--- t/name.t | 14 +++++--------- t/v1-message.t | 5 ++--- t/v2-message.t | 8 +++----- t/v2-mobile.t | 5 ++--- t/v2-simple.t | 11 ++++------- t/zero.t | 8 +++----- 8 files changed, 22 insertions(+), 36 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 64d3e2b..85dc57c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,7 +12,7 @@ WriteMakefile ( 'Class::MethodMaker' => '1.02', 'Term::ReadKey' => '2.14',}, BUILD_REQUIRES => { - 'Capture::Tiny' => '0.11', + 'Capture::Tiny' => '0.12', 'Test::More' => '0.80', 'Test::Exception' => '0.31', 'File::Temp' => 0, diff --git a/t/eta-linear.t b/t/eta-linear.t index 3d4f06b..5a80016 100644 --- a/t/eta-linear.t +++ b/t/eta-linear.t @@ -12,7 +12,7 @@ This package tests the basic functionality of Term::ProgressBar. use Test::More tests => 9; use Test::Exception; -use Capture::Tiny qw(capture); +use Capture::Tiny qw(capture_stderr); use Term::ProgressBar; @@ -38,7 +38,7 @@ Update it it from 1 to 10. =cut { - my ($out, $err) = capture { + my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new({count => 10, name => 'fred', @@ -49,7 +49,6 @@ Update it it from 1 to 10. lives_ok { $p->message('Hello Mum!') } 'Count 1-10 (3)'; lives_ok { for (6..10) { $p->update($_); sleep 1 } } 'Count 1-10 (4)'; }; - print $out; my @lines = grep $_ ne '', split /[\n\r]+/, $err; diag explain \@lines diff --git a/t/name.t b/t/name.t index e89f486..d073516 100644 --- a/t/name.t +++ b/t/name.t @@ -12,7 +12,7 @@ This package tests the name functionality of Term::ProgressBar. use Test::More tests => 20; use Test::Exception; -use Capture::Tiny qw(capture); +use Capture::Tiny qw(capture_stderr); my $MESSAGE1 = 'The Gospel of St. Jude'; my $NAME1 = 'Algenon'; @@ -43,13 +43,12 @@ Update it it from 1 to 10. { my $p; - my ($out, $err) = capture { + my $err = capture_stderr { lives_ok { $p = Term::ProgressBar->new({count => 10, name => $NAME1}); } 'Count 1-10 ( 1)'; lives_ok { $p->update($_) for 1..3 } 'Count 1-10 ( 2)'; }; - print $out; $err =~ s!^.*\r!!gm; diag "ERR (1) :\n$err\nlength: " . length($err) @@ -67,11 +66,10 @@ Update it it from 1 to 10. cmp_ok length($bar), '<', $barexpect+1; - ($out, $err) = capture { + $err = capture_stderr { lives_ok { $p->message($MESSAGE1) } 'Count 1-10 ( 5)'; lives_ok { $p->update($_) for 6..10 } 'Count 1-10 ( 6)'; }; - print $out; $err =~ s!^.*\r!!gm; diag "ERR (2) :\n$err\nlength: " . length($err) @@ -106,11 +104,10 @@ Use v1 mode { my $p; - my ($out, $err) = capture { + my $err = capture_stderr { lives_ok { $p = Term::ProgressBar->new($NAME2, 10); } 'Count 1-10 ( 1)'; lives_ok { $p->update($_) for 1..3 } 'Count 1-10 ( 2)'; }; - print $out; $err =~ s!^.*\r!!gm; diag "ERR (1) :\n$err\nlength: " . length($err) @@ -127,11 +124,10 @@ Use v1 mode cmp_ok length($bar), '>', $barexpect -1; cmp_ok length($bar), '<', $barexpect+1; - ($out, $err) = capture { + $err = capture_stderr { lives_ok { $p->message($MESSAGE1) } 'Count 1-10 ( 5)'; lives_ok { $p->update($_) for 6..10 } 'Count 1-10 ( 6)'; }; - print $out; $err =~ s!^.*\r!!gm; diag "ERR (2) :\n$err\nlength: " . length($err) diff --git a/t/v1-message.t b/t/v1-message.t index 3428ff8..9a95824 100644 --- a/t/v1-message.t +++ b/t/v1-message.t @@ -12,7 +12,7 @@ This package tests the basic functionality of Term::ProgressBar. use Test::More tests => 8; use Test::Exception; -use Capture::Tiny qw(capture); +use Capture::Tiny qw(capture_stderr); my $MESSAGE1 = 'Walking on the Milky Way'; @@ -39,14 +39,13 @@ Update it it from 1 to 10. =cut { - my ($out, $err) = capture { + my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new('bob', 10); } 'Count 1-10 (1)'; lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)'; lives_ok { $p->message($MESSAGE1) } 'Count 1-10 (3)'; lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)'; }; - print $out; $err =~ s!^.*\r!!gm; diag "ERR:\n$err\nlength: ", length($err) diff --git a/t/v2-message.t b/t/v2-message.t index 10430b3..0b2b528 100644 --- a/t/v2-message.t +++ b/t/v2-message.t @@ -12,7 +12,7 @@ This package tests the basic functionality of Term::ProgressBar. use Test::More tests => 11; use Test::Exception; -use Capture::Tiny qw(capture); +use Capture::Tiny qw(capture_stderr); my $MESSAGE1 = 'Walking on the Milky Way'; @@ -44,14 +44,13 @@ Update it it from 1 to 10. Output a message halfway through. =cut { - my ($out, $err) = capture { + my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)'; lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)'; lives_ok { $p->message($MESSAGE1) } 'Count 1-10 (3)'; lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)'; }; - print $out; $err =~ s!^.*\r!!gm; diag "ERR:\n$err\nlength: " . length($err) @@ -78,12 +77,11 @@ This is to check that message preserves the progress bar value correctly. =cut { - my ($out, $err) = capture { + my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new(100); } 'Message Check ( 1)'; lives_ok { for (0..100) { $p->update($_); $p->message("Hello") } } 'Message Check ( 2)'; }; - print $out; my @err_lines = split /\n/, $err; (my $last_line = $err_lines[-1]) =~ tr/\r//d; diff --git a/t/v2-mobile.t b/t/v2-mobile.t index dd42ea3..342d06f 100644 --- a/t/v2-mobile.t +++ b/t/v2-mobile.t @@ -12,7 +12,7 @@ This package tests the moving target functionality of Term::ProgressBar. use Test::More tests => 7; use Test::Exception; -use Capture::Tiny qw(capture); +use Capture::Tiny qw(capture_stderr); use_ok 'Term::ProgressBar'; @@ -36,14 +36,13 @@ Update it from 11 to 20. =cut -my ($out, $err) = capture { +my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-20 (1)'; lives_ok { $p->update($_) for 1..5 } 'Count 1-20 (2)'; lives_ok { $p->target(20) } 'Count 1-20 (3)'; lives_ok { $p->update($_) for 11..20 } 'Count 1-20 (4)'; }; -print $out; $err =~ s!^.*\r!!gm; diag "ERR:\n$err\nlength: " . length($err) diff --git a/t/v2-simple.t b/t/v2-simple.t index 439594f..37f9d60 100644 --- a/t/v2-simple.t +++ b/t/v2-simple.t @@ -12,7 +12,7 @@ This package tests the basic functionality of Term::ProgressBar. use Test::More tests => 31; use Test::Exception; -use Capture::Tiny qw(capture); +use Capture::Tiny qw(capture_stderr); use_ok 'Term::ProgressBar'; @@ -33,12 +33,11 @@ Update it it from 1 to 10. =cut { - my ($out, $err) = capture { + my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)'; lives_ok { $p->update($_) for 1..10 } 'Count 1-10 (2)'; }; - print $out; my @lines = grep {$_ ne ''} split /\r/, $err; diag explain \@lines @@ -64,12 +63,11 @@ Update it it from 1 to 9. =cut { - my ($out, $err) = capture { + my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-9 (1)'; lives_ok { $p->update($_) for 1..9 } 'Count 1-9 (2)'; }; - print $out; my @lines = grep $_ ne '', split /\r/, $err; diag explain \@lines @@ -89,11 +87,10 @@ percentage or displayed bar). =cut { - my ($out, $err) = capture { + my $err = capture_stderr { my $tp = Term::ProgressBar->new(1000000); $tp->update($_) foreach (0, 1); }; - #print $out; my @lines = grep {$_ ne ''} split /\r/, $err; diag explain \@lines diff --git a/t/zero.t b/t/zero.t index fda3d35..ee51f2b 100644 --- a/t/zero.t +++ b/t/zero.t @@ -12,7 +12,7 @@ This package tests the zero-progress handling of progress bar. use Test::More tests => 9; use Test::Exception; -use Capture::Tiny qw(capture); +use Capture::Tiny qw(capture_stderr); use_ok 'Term::ProgressBar'; @@ -35,11 +35,10 @@ Update it it from 1 to 10. { my $p; my $name = 'doing nothing'; - my ($out, $err) = capture { + my $err = capture_stderr { lives_ok { $p = Term::ProgressBar->new($name, 0); } 'V1 mode ( 1)'; lives_ok { $p->update($_) for 1..10 } 'V1 mode ( 2)'; }; - print $out; my @lines = grep { $_ ne ''} split /\r/, $err; diag explain @lines @@ -65,11 +64,10 @@ Update it it from 1 to 10. { my $p; my $name = 'zero'; - my ($out, $err) = capture { + my $err = capture_stderr { lives_ok { $p = Term::ProgressBar->new({ count => 0, name => $name }); } 'V2 mode ( 1)'; lives_ok { $p->update($_) for 1..10 } 'V2 mode ( 2)'; }; - print $out; my @lines = grep {$_ ne ''} split /\r/, $err; diag explain @lines -- 2.39.2