1 # (X)Emacs mode: -*- cperl -*-
5 =head1 Unit Test Package for Term::ProgressBar
7 This package tests the zero-progress handling of progress bar.
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--5: V1 mode
42 Create a progress bar with 0 things.
43 Update it it from 1 to 10.
45 (1) Check no exception thrown on creation
46 (2) Check no exception thrown on update
47 (3) Check bar displays name
48 (3) Check bar says nothing to do
54 save_output('stderr', *STDERR{IO});
55 my $name = 'doing nothing';
56 ok (evcheck(sub { $p = Term::ProgressBar->new($name, 0); },
59 ok (evcheck(sub { $p->update($_) for 1..10 },'V1 mode ( 2)'),
61 my $err = restore_output('stderr');
62 my @lines = grep $_ ne '', split /\r/, $err;
65 ok $lines[-1], qr/^$name:/, 'V1 mode ( 3)';
66 ok $lines[-1], qr/\(nothing to do\)/, 'V1 mode ( 4)';
69 # -------------------------------------
71 =head2 Tests 6--9: V2 mode
73 Create a progress bar with 0 things.
74 Update it it from 1 to 10.
76 (1) Check no exception thrown on creation
77 (2) Check no exception thrown on update
78 (3) Check bar displays name
79 (4) Check bar says nothing to do
85 save_output('stderr', *STDERR{IO});
87 ok (evcheck(sub { $p = Term::ProgressBar->new({ count => 0,
91 ok (evcheck(sub { $p->update($_) for 1..10 },'V2 mode ( 2)'),
93 my $err = restore_output('stderr');
94 my @lines = grep $_ ne '', split /\r/, $err;
97 ok $lines[-1], qr/^$name:/, 'V2 mode ( 3)';
98 ok $lines[-1], qr/\(nothing to do\)/, 'V2 mode ( 4)';
101 # ----------------------------------------------------------------------------