X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=t%2Fv2-simple.t;h=439594f3534773f495369e4c594ca03593b21a14;hb=834c61514d3dc3eb32aa31f14431c851a8cc62d3;hp=a95d93da8d0856bb78bda2f8e914a162ee90c534;hpb=d199cca195c28dcac9fd01da5f1a668ed920c642;p=term-progressbar.git diff --git a/t/v2-simple.t b/t/v2-simple.t index a95d93d..439594f 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,29 +9,12 @@ This package tests the basic functionality of Term::ProgressBar. =cut -use Data::Dumper qw( Dumper ); -use FindBin qw( $Bin ); -use Test qw( ok plan ); +use Test::More tests => 31; +use Test::Exception; -use lib $Bin; -use test qw( evcheck restore_output save_output ); +use Capture::Tiny qw(capture); -BEGIN { - # 1 for compilation test, - plan tests => 31, - todo => [], -} - -=head2 Test 1: compilation - -This test confirms that the test script and the modules it calls compiled -successfully. - -=cut - -use Term::ProgressBar; - -ok 1, 1, 'compilation'; +use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); @@ -48,24 +32,22 @@ Update it it from 1 to 10. (5--15) Check bar has no minor characters at any point =cut - { - my $p; - save_output('stderr', *STDERR{IO}); - ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-10 (1)' ), - 1, 'Count 1-10 (1)'); - ok (evcheck(sub { $p->update($_) for 1..10 }, 'Count 1-10 (2)' ), - 1, 'Count 1-10 (2)'); - my $err = restore_output('stderr'); - my @lines = grep $_ ne '', split /\r/, $err; - print Dumper \@lines + my ($out, $err) = capture { + 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 if $ENV{TEST_DEBUG}; - ok $lines[-1], qr/\[=+\]/, 'Count 1-10 (3)'; - ok $lines[-1], qr/^\s*100%/, 'Count 1-10 (4)'; - ok $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-10 (%d)', 5+$_) + like $lines[-1], qr/\[=+\]/, 'Count 1-10 (3)'; + like $lines[-1], qr/^\s*100%/, 'Count 1-10 (4)'; + like $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-10 (%d)', 5+$_) for 0..10; } - # ------------------------------------- =head2 Tests 17--30: Count 1-9 @@ -82,22 +64,21 @@ Update it it from 1 to 9. =cut { - my $p; - save_output('stderr', *STDERR{IO}); - ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-9 (1)' ), - 1, 'Count 1-9 (1)'); - ok (evcheck(sub { $p->update($_) for 1..9 }, 'Count 1-9 (2)' ), - 1, 'Count 1-9 (2)'); - my $err = restore_output('stderr'); + my ($out, $err) = capture { + 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; - print Dumper \@lines + diag explain \@lines if $ENV{TEST_DEBUG}; - ok $lines[-1], qr/\[=+ +\]/, 'Count 1-9 (3)'; - ok $lines[-1], qr/^\s*90%/, 'Count 1-9 (4)'; - ok $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-9 (%d)', 5+$_) + like $lines[-1], qr/\[=+ +\]/, 'Count 1-9 (3)'; + like $lines[-1], qr/^\s*90%/, 'Count 1-9 (4)'; + like $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-9 (%d)', 5+$_) for 0..9; } - # ------------------------------------- =head2 Test 31 @@ -108,12 +89,14 @@ percentage or displayed bar). =cut { - save_output('stderr', *STDERR{IO}); - my $b = Term::ProgressBar->new(1000000); - $b->update($_) foreach (0, 1); - my $err = restore_output('stderr'); - my @lines = grep $_ ne '', split /\r/, $err; - print Dumper \@lines + my ($out, $err) = capture { + my $tp = Term::ProgressBar->new(1000000); + $tp->update($_) foreach (0, 1); + }; + #print $out; + + my @lines = grep {$_ ne ''} split /\r/, $err; + diag explain \@lines if $ENV{TEST_DEBUG}; - ok scalar @lines, 1; + is scalar @lines, 1; }