X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=t%2Fv2-mobile.t;h=5176a52b8cfec437274dcd3f6ffec49793c36130;hb=ee92123a8fb2bca08dba2132e5ff39404e2b7703;hp=6f8f67ce8bea2703b9c4630725a59c8129262ee2;hpb=d199cca195c28dcac9fd01da5f1a668ed920c642;p=term-progressbar.git diff --git a/t/v2-mobile.t b/t/v2-mobile.t index 6f8f67c..5176a52 100644 --- a/t/v2-mobile.t +++ b/t/v2-mobile.t @@ -9,28 +9,12 @@ This package tests the moving target functionality of Term::ProgressBar. =cut use Data::Dumper qw( Dumper ); -use FindBin qw( $Bin ); -use Test qw( ok plan ); +use Test::More tests => 7; +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 => 7, - 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,18 +36,14 @@ Update it from 11 to 20. =cut -{ +my ($out, $err) = capture { my $p; - save_output('stderr', *STDERR{IO}); - ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-20 (1)' ), - 1, 'Count 1-20 (1)'); - ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-20 (2)' ), - 1, 'Count 1-20 (2)'); - ok (evcheck(sub { $p->target(20) }, 'Count 1-20 (3)' ), - 1, 'Count 1-20 (3)'); - ok (evcheck(sub { $p->update($_) for 11..20 }, 'Count 1-20 (4)' ), - 1, 'Count 1-20 (4)'); - my $err = restore_output('stderr'); + lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-20 (1)'; + lives_ok { $p->update($_) for 1..5 } 'Count 1-20 (2)'; + lives_ok { $p->target(20) } 'Count 1-20 (3)'; + lives_ok { $p->update($_) for 11..20 } 'Count 1-20 (4)'; +}; +print $out; $err =~ s!^.*\r!!gm; print STDERR "ERR:\n$err\nlength: ", length($err), "\n" @@ -71,6 +51,5 @@ Update it from 11 to 20. my @lines = split /\n/, $err; - ok $lines[-1], qr/\[=+\]/, 'Count 1-20 (5)'; - ok $lines[-1], qr/^\s*100%/, 'Count 1-20 (6)'; -} + like $lines[-1], qr/\[=+\]/, 'Count 1-20 (5)'; + like $lines[-1], qr/^\s*100%/, 'Count 1-20 (6)';