use Data::Dumper qw( Dumper );
use FindBin qw( $Bin );
-use Test qw( ok plan );
+use Test::More tests => 7;
use lib $Bin;
-use test qw( evcheck restore_output save_output );
+use test qw( evcheck );
-BEGIN {
- # 1 for compilation test,
- plan tests => 7,
- todo => [],
-}
+use Capture::Tiny qw(capture);
-=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);
=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)');
+ 'Count 1-20 (1)');
ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-20 (2)' ),
- 1, 'Count 1-20 (2)');
+ 'Count 1-20 (2)');
ok (evcheck(sub { $p->target(20) }, 'Count 1-20 (3)' ),
- 1, 'Count 1-20 (3)');
+ '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');
+ 'Count 1-20 (4)');
+};
+print $out;
$err =~ s!^.*\r!!gm;
print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
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)';