1 # (X)Emacs mode: -*- cperl -*-
5 =head1 Unit Test Package for Term::ProgressBar
7 This package tests the basic 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 );
19 use constant MESSAGE1 => 'Walking on the Milky Way';
22 # 1 for compilation test,
27 =head2 Test 1: compilation
29 This test confirms that the test script and the modules it calls compiled
34 use Term::ProgressBar;
36 ok 1, 1, 'compilation';
38 Term::ProgressBar->__force_term (50);
40 # -------------------------------------
42 =head2 Tests 2--8: Count 1-10
44 Create a progress bar with 10 things, and a name 'bob'.
45 Update it it from 1 to 10.
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 message send
50 (4) Check no exception thrown on update (6..10)
51 (5) Check message output.
52 (5) Check bar is complete
53 (6) Check bar number is 100%
59 save_output('stderr', *STDERR{IO});
60 ok (evcheck(sub { $p = Term::ProgressBar->new('bob', 10); },
63 ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-10 (2)' ),
65 ok (evcheck(sub { $p->message(MESSAGE1) }, 'Count 1-10 (3)' ),
67 ok (evcheck(sub { $p->update($_) for 6..10 }, 'Count 1-10 (4)' ),
69 my $err = restore_output('stderr');
72 print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
75 my @lines = split /\n/, $err;
77 ok $lines[0], MESSAGE1;
78 ok $lines[-1], qr/bob:\s+\d+% \#+/, 'Count 1-10 (6)';
79 ok $lines[-1], qr/^bob:\s+100%/, 'Count 1-10 (7)';