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 );
17 evcheck restore_output save_output );
20 # 1 for compilation test,
25 =head2 Test 1: compilation
27 This test confirms that the test script and the modules it calls compiled
32 use Term::ProgressBar;
34 ok 1, 1, 'compilation';
36 Term::ProgressBar->__force_term (50);
38 # -------------------------------------
40 =head2 Tests 2--7: Count 1-20
42 Create a progress bar with 10 things.
43 Update it it from 1 to 5.
45 Update it from 11 to 20.
47 (1) Check no exception thrown on creation
48 (2) Check no exception thrown on update (1..5)
49 (3) Check no exception thrown on target update
50 (4) Check no exception thrown on update (6..10)
51 (5) Check bar is complete
52 (6) Check bar number is 100%
58 save_output('stderr', *STDERR{IO});
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)' ),
67 my $err = restore_output('stderr');
70 print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
73 my @lines = split /\n/, $err;
75 ok $lines[-1], qr/\[=+\]/, 'Count 1-20 (5)';
76 ok $lines[-1], qr/^\s*100%/, 'Count 1-20 (6)';