X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=t%2Feta-linear.t;h=5a80016e894a7190ebb2b602363833d199d6c362;hb=34ac983862368c022af1ffe37fe80de1abdec2a8;hp=ea8410d27c8b3e85212e28b9ee2721dbf98b5343;hpb=8f87af0520c5dbcedbfe74dd6ef6e7826f200263;p=term-progressbar.git diff --git a/t/eta-linear.t b/t/eta-linear.t index ea8410d..5a80016 100644 --- a/t/eta-linear.t +++ b/t/eta-linear.t @@ -1,6 +1,7 @@ # (X)Emacs mode: -*- cperl -*- use strict; +use warnings; =head1 Unit Test Package for Term::ProgressBar @@ -8,19 +9,10 @@ This package tests the basic functionality of Term::ProgressBar. =cut -use Data::Dumper qw( Dumper ); -use FindBin qw( $Bin ); use Test::More tests => 9; +use Test::Exception; -use lib $Bin; -use test qw( evcheck ); - -=head2 Test 1: compilation - -This test confirms that the test script and the modules it calls compiled -successfully. - -=cut +use Capture::Tiny qw(capture_stderr); use Term::ProgressBar; @@ -45,34 +37,27 @@ Update it it from 1 to 10. =cut -use Capture::Tiny qw(capture); - -my ($out, $err) = capture { - my $p; - ok (evcheck(sub { +{ + my $err = capture_stderr { + my $p; + lives_ok { $p = Term::ProgressBar->new({count => 10, name => 'fred', ETA => 'linear'}); - }, 'Count 1-10 (1)' ), - 'Count 1-10 (1)'); - ok (evcheck(sub { for (1..5) { $p->update($_); sleep 1 } }, - 'Count 1-10 (2)' ), - 'Count 1-10 (2)'); - ok (evcheck(sub { $p->message('Hello Mum!') }, - 'Count 1-10 (3)' ), - 'Count 1-10 (3)'); - ok (evcheck(sub { for (6..10) { $p->update($_); sleep 1 } }, - 'Count 1-10 (4)' ), - 'Count 1-10 (4)'); -}; -print $out; + } 'Count 1-10 (1)'; + lives_ok { for (1..5) { $p->update($_); sleep 1 } } + 'Count 1-10 (2)'; + lives_ok { $p->message('Hello Mum!') } 'Count 1-10 (3)'; + lives_ok { for (6..10) { $p->update($_); sleep 1 } } 'Count 1-10 (4)'; + }; + my @lines = grep $_ ne '', split /[\n\r]+/, $err; - print Dumper \@lines + diag explain \@lines if $ENV{TEST_DEBUG}; ok grep $_ eq 'Hello Mum!', @lines; - like $lines[-1], qr/\[=+\]/, 'Count 1-10 (6)'; - like $lines[-1], qr/^fred: \s*100%/, 'Count 1-10 (7)'; - like $lines[-1], qr/D[ \d]\dh\d{2}m\d{2}s$/, 'Count 1-10 (8)'; - like $lines[-2], qr/ Left$/, 'Count 1-10 (9)'; - + like $lines[-1], qr/\[=+\]/, 'Count 1-10 (6)'; + like $lines[-1], qr/^fred: \s*100%/, 'Count 1-10 (7)'; + like $lines[-1], qr/D[ \d]\dh\d{2}m\d{2}s$/, 'Count 1-10 (8)'; + like $lines[-2], qr/ Left$/, 'Count 1-10 (9)'; +} # ----------------------------------------------------------------------------