X-Git-Url: https://git.donarmstrong.com/?p=term-progressbar.git;a=blobdiff_plain;f=t%2Fzero.t;h=ee51f2b9b4e4f2127ede1198063cfa287c139def;hp=7461163054fb3bf1cf0bf346715d471b63418b72;hb=c3f8be419c0674c8a6fdb64bddd841a0957adf28;hpb=c117fc5047ab77ee6df1d6a7c6a595a3ebc87d00 diff --git a/t/zero.t b/t/zero.t index 7461163..ee51f2b 100644 --- a/t/zero.t +++ b/t/zero.t @@ -1,6 +1,7 @@ # (X)Emacs mode: -*- cperl -*- use strict; +use warnings; =head1 Unit Test Package for Term::ProgressBar @@ -8,31 +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 Capture::Tiny qw(capture); +use Capture::Tiny qw(capture_stderr); -use lib $Bin; -use test qw( evcheck ); - -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); @@ -52,21 +34,17 @@ Update it it from 1 to 10. { my $p; - my $name; -my ($out, $err) = capture { - $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)'); -}; -print $out; - my @lines = grep $_ ne '', split /\r/, $err; - print Dumper \@lines + my $name = 'doing nothing'; + 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)'; + }; + + my @lines = grep { $_ ne ''} split /\r/, $err; + diag explain @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)'; } # ------------------------------------- @@ -86,20 +64,16 @@ Update it it from 1 to 10. { my $p; my $name = 'zero'; -my ($out, $err) = capture { - 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)'); -}; -print $out; - my @lines = grep $_ ne '', split /\r/, $err; - print Dumper \@lines + 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)'; + }; + + my @lines = grep {$_ ne ''} split /\r/, $err; + diag explain @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)'; } # ----------------------------------------------------------------------------