X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=t%2Fv2-simple.t;h=37f9d6079fca7a2d1a9e44faf279416dedd6cd79;hb=34ac983862368c022af1ffe37fe80de1abdec2a8;hp=4816ab989ad012fad2015a1053989572f93cf676;hpb=14647cabb5bbb54629de8545e080519bd0be430f;p=term-progressbar.git diff --git a/t/v2-simple.t b/t/v2-simple.t index 4816ab9..37f9d60 100644 --- a/t/v2-simple.t +++ b/t/v2-simple.t @@ -1,6 +1,7 @@ # (X)Emacs mode: -*- cperl -*- use strict; +use warnings; =head1 Unit Test Package for Term::ProgressBar @@ -8,11 +9,10 @@ This package tests the basic functionality of Term::ProgressBar. =cut -use Data::Dumper qw( Dumper ); use Test::More tests => 31; use Test::Exception; -use Capture::Tiny qw(capture); +use Capture::Tiny qw(capture_stderr); use_ok 'Term::ProgressBar'; @@ -33,15 +33,14 @@ Update it it from 1 to 10. =cut { - my $p; - -my ($out, $err) = capture { - 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; - print Dumper \@lines + 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)'; + }; + + my @lines = grep {$_ ne ''} split /\r/, $err; + diag explain \@lines if $ENV{TEST_DEBUG}; like $lines[-1], qr/\[=+\]/, 'Count 1-10 (3)'; like $lines[-1], qr/^\s*100%/, 'Count 1-10 (4)'; @@ -64,16 +63,14 @@ Update it it from 1 to 9. =cut { - my $p; - -my ($out, $err) = capture { - 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 $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)'; + }; my @lines = grep $_ ne '', split /\r/, $err; - print Dumper \@lines + diag explain \@lines if $ENV{TEST_DEBUG}; like $lines[-1], qr/\[=+ +\]/, 'Count 1-9 (3)'; like $lines[-1], qr/^\s*90%/, 'Count 1-9 (4)'; @@ -90,13 +87,13 @@ percentage or displayed bar). =cut { -my ($out, $err) = capture { - my $b = Term::ProgressBar->new(1000000); - $b->update($_) foreach (0, 1); -}; -print $out; - my @lines = grep $_ ne '', split /\r/, $err; - print Dumper \@lines + my $err = capture_stderr { + my $tp = Term::ProgressBar->new(1000000); + $tp->update($_) foreach (0, 1); + }; + + my @lines = grep {$_ ne ''} split /\r/, $err; + diag explain \@lines if $ENV{TEST_DEBUG}; is scalar @lines, 1; }