1 # (X)Emacs mode: -*- cperl -*-
5 =head1 Unit Test Package for Term::ProgressBar
7 This package tests the moving target functionality of Term::ProgressBar.
11 use Data::Dumper qw( Dumper );
12 use FindBin qw( $Bin );
13 use Test::More tests => 7;
16 use test qw( evcheck );
18 use Capture::Tiny qw(capture);
20 use_ok 'Term::ProgressBar';
22 Term::ProgressBar->__force_term (50);
24 # -------------------------------------
26 =head2 Tests 2--7: Count 1-20
28 Create a progress bar with 10 things.
29 Update it it from 1 to 5.
31 Update it from 11 to 20.
33 (1) Check no exception thrown on creation
34 (2) Check no exception thrown on update (1..5)
35 (3) Check no exception thrown on target update
36 (4) Check no exception thrown on update (6..10)
37 (5) Check bar is complete
38 (6) Check bar number is 100%
42 my ($out, $err) = capture {
44 ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-20 (1)' ),
46 ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-20 (2)' ),
48 ok (evcheck(sub { $p->target(20) }, 'Count 1-20 (3)' ),
50 ok (evcheck(sub { $p->update($_) for 11..20 }, 'Count 1-20 (4)' ),
56 print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
59 my @lines = split /\n/, $err;
61 like $lines[-1], qr/\[=+\]/, 'Count 1-20 (5)';
62 like $lines[-1], qr/^\s*100%/, 'Count 1-20 (6)';