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 );
16 use test qw( evcheck restore_output save_output );
19 # 1 for compilation test,
24 =head2 Test 1: compilation
26 This test confirms that the test script and the modules it calls compiled
31 use Term::ProgressBar;
33 ok 1, 1, 'compilation';
35 Term::ProgressBar->__force_term (50);
37 # -------------------------------------
39 =head2 Tests 2--5: V1 mode
41 Create a progress bar with 0 things.
42 Update it it from 1 to 10.
44 (1) Check no exception thrown on creation
45 (2) Check no exception thrown on update
46 (3) Check bar displays name
47 (3) Check bar says nothing to do
53 save_output('stderr', *STDERR{IO});
54 my $name = 'doing nothing';
55 ok (evcheck(sub { $p = Term::ProgressBar->new($name, 0); },
58 ok (evcheck(sub { $p->update($_) for 1..10 },'V1 mode ( 2)'),
60 my $err = restore_output('stderr');
61 my @lines = grep $_ ne '', split /\r/, $err;
64 ok $lines[-1], qr/^$name:/, 'V1 mode ( 3)';
65 ok $lines[-1], qr/\(nothing to do\)/, 'V1 mode ( 4)';
68 # -------------------------------------
70 =head2 Tests 6--9: V2 mode
72 Create a progress bar with 0 things.
73 Update it it from 1 to 10.
75 (1) Check no exception thrown on creation
76 (2) Check no exception thrown on update
77 (3) Check bar displays name
78 (4) Check bar says nothing to do
84 save_output('stderr', *STDERR{IO});
86 ok (evcheck(sub { $p = Term::ProgressBar->new({ count => 0,
90 ok (evcheck(sub { $p->update($_) for 1..10 },'V2 mode ( 2)'),
92 my $err = restore_output('stderr');
93 my @lines = grep $_ ne '', split /\r/, $err;
96 ok $lines[-1], qr/^$name:/, 'V2 mode ( 3)';
97 ok $lines[-1], qr/\(nothing to do\)/, 'V2 mode ( 4)';
100 # ----------------------------------------------------------------------------