X-Git-Url: https://git.donarmstrong.com/?p=term-progressbar.git;a=blobdiff_plain;f=t%2Fzero.t;h=ffabda91e980f4a98ac924043c7f8a73799a81d0;hp=737f5088b77120ad33cb565c6c6d4f9b2c391e68;hb=14647cabb5bbb54629de8545e080519bd0be430f;hpb=3797cda1b0da9caa24c7ff35e910e1f318c77918 diff --git a/t/zero.t b/t/zero.t index 737f508..ffabda9 100644 --- a/t/zero.t +++ b/t/zero.t @@ -9,29 +9,12 @@ This package tests the zero-progress handling of progress bar. =cut use Data::Dumper qw( Dumper ); -use FindBin qw( $Bin ); -use Test qw( ok plan ); +use Test::More tests => 9; +use Test::Exception; -use lib $Bin; -use test qw( DATA_DIR - evcheck restore_output save_output ); +use Capture::Tiny qw(capture); -BEGIN { - # 1 for compilation test, - plan tests => 9, - 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); @@ -51,19 +34,18 @@ Update it it from 1 to 10. { my $p; - save_output('stderr', *STDERR{IO}); - my $name = 'doing nothing'; - ok (evcheck(sub { $p = Term::ProgressBar->new($name, 0); }, - 'V1 mode ( 1)' ), - 1, 'V1 mode ( 1)'); - ok (evcheck(sub { $p->update($_) for 1..10 },'V1 mode ( 2)'), - 1, 'V1 mode ( 2)'); - my $err = restore_output('stderr'); + my $name; +my ($out, $err) = capture { + $name = 'doing nothing'; + 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; print Dumper \@lines if $ENV{TEST_DEBUG}; - ok $lines[-1], qr/^$name:/, 'V1 mode ( 3)'; - ok $lines[-1], qr/\(nothing to do\)/, 'V1 mode ( 4)'; + like $lines[-1], qr/^$name:/, 'V1 mode ( 3)'; + like $lines[-1], qr/\(nothing to do\)/, 'V1 mode ( 4)'; } # ------------------------------------- @@ -82,20 +64,17 @@ Update it it from 1 to 10. { my $p; - save_output('stderr', *STDERR{IO}); my $name = 'zero'; - ok (evcheck(sub { $p = Term::ProgressBar->new({ count => 0, - name => $name }); }, - 'V2 mode ( 1)' ), - 1, 'V2 mode ( 1)'); - ok (evcheck(sub { $p->update($_) for 1..10 },'V2 mode ( 2)'), - 1, 'V2 mode ( 2)'); - my $err = restore_output('stderr'); +my ($out, $err) = capture { + 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; print Dumper \@lines if $ENV{TEST_DEBUG}; - ok $lines[-1], qr/^$name:/, 'V2 mode ( 3)'; - ok $lines[-1], qr/\(nothing to do\)/, 'V2 mode ( 4)'; + like $lines[-1], qr/^$name:/, 'V2 mode ( 3)'; + like $lines[-1], qr/\(nothing to do\)/, 'V2 mode ( 4)'; } # ----------------------------------------------------------------------------