X-Git-Url: https://git.donarmstrong.com/?p=term-progressbar.git;a=blobdiff_plain;f=t%2Fv2-message.t;fp=t%2Fv2-message.t;h=10430b3a9ffc83fee7f4c280d6937104a024ea90;hp=6b687344f7edb18f6045ab6ccd1bbcdf60ac93fb;hb=834c61514d3dc3eb32aa31f14431c851a8cc62d3;hpb=2256bba0170029adbe6ce865c0b7c3edbededfe7 diff --git a/t/v2-message.t b/t/v2-message.t index 6b68734..10430b3 100644 --- a/t/v2-message.t +++ b/t/v2-message.t @@ -1,6 +1,7 @@ # (X)Emacs mode: -*- cperl -*- use strict; +use warnings; =head1 Unit Test Package for Term::ProgressBar @@ -8,14 +9,12 @@ This package tests the basic functionality of Term::ProgressBar. =cut -use Data::Dumper 2.101 qw( Dumper ); use Test::More tests => 11; use Test::Exception; -use constant MESSAGE1 => 'Walking on the Milky Way'; - use Capture::Tiny qw(capture); +my $MESSAGE1 = 'Walking on the Milky Way'; =head2 Test 1: compilation @@ -44,25 +43,26 @@ Update it it from 1 to 10. Output a message halfway through. (7) Check bar number is 100% =cut - -my ($out, $err) = capture { - my $p; - lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)'; - lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)'; - lives_ok { $p->message(MESSAGE1) } 'Count 1-10 (3)'; - lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)'; -}; -print $out; +{ + my ($out, $err) = capture { + my $p; + lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)'; + lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)'; + lives_ok { $p->message($MESSAGE1) } 'Count 1-10 (3)'; + lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)'; + }; + print $out; $err =~ s!^.*\r!!gm; - print STDERR "ERR:\n$err\nlength: ", length($err), "\n" + diag "ERR:\n$err\nlength: " . length($err) if $ENV{TEST_DEBUG}; my @lines = split /\n/, $err; - is $lines[0], MESSAGE1; + is $lines[0], $MESSAGE1; like $lines[-1], qr/\[=+\]/, 'Count 1-10 (5)'; like $lines[-1], qr/^\s*100%/, 'Count 1-10 (6)'; +} # ------------------------------------- @@ -77,15 +77,17 @@ This is to check that message preserves the progress bar value correctly. =cut -($out, $err) = capture { - my $p; - lives_ok { $p = Term::ProgressBar->new(100); } 'Message Check ( 1)'; - lives_ok { for (0..100) { $p->update($_); $p->message("Hello") } } 'Message Check ( 2)'; -}; -print $out; +{ + my ($out, $err) = capture { + my $p; + lives_ok { $p = Term::ProgressBar->new(100); } 'Message Check ( 1)'; + lives_ok { for (0..100) { $p->update($_); $p->message("Hello") } } 'Message Check ( 2)'; + }; + print $out; my @err_lines = split /\n/, $err; (my $last_line = $err_lines[-1]) =~ tr/\r//d; is substr($last_line, 0, 4), '100%', 'Message Check ( 3)'; +} # ----------------------------------------------------------------------------