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 qw( ok plan );
16 use test qw( evcheck );
18 use Capture::Tiny qw(capture);
21 # 1 for compilation test,
26 =head2 Test 1: compilation
28 This test confirms that the test script and the modules it calls compiled
33 use Term::ProgressBar;
35 ok 1, 1, 'compilation';
37 Term::ProgressBar->__force_term (50);
39 # -------------------------------------
41 =head2 Tests 2--7: Count 1-20
43 Create a progress bar with 10 things.
44 Update it it from 1 to 5.
46 Update it from 11 to 20.
48 (1) Check no exception thrown on creation
49 (2) Check no exception thrown on update (1..5)
50 (3) Check no exception thrown on target update
51 (4) Check no exception thrown on update (6..10)
52 (5) Check bar is complete
53 (6) Check bar number is 100%
57 my ($out, $err) = capture {
59 ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-20 (1)' ),
61 ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-20 (2)' ),
63 ok (evcheck(sub { $p->target(20) }, 'Count 1-20 (3)' ),
65 ok (evcheck(sub { $p->update($_) for 11..20 }, 'Count 1-20 (4)' ),
71 print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
74 my @lines = split /\n/, $err;
76 ok $lines[-1], qr/\[=+\]/, 'Count 1-20 (5)';
77 ok $lines[-1], qr/^\s*100%/, 'Count 1-20 (6)';