1 # (X)Emacs mode: -*- cperl -*-
6 =head1 Unit Test Package for Term::ProgressBar
8 This package tests the zero-progress handling of progress bar.
12 use Test::More tests => 9;
15 use Capture::Tiny qw(capture_stderr);
17 use_ok 'Term::ProgressBar';
19 Term::ProgressBar->__force_term (50);
21 # -------------------------------------
23 =head2 Tests 2--5: V1 mode
25 Create a progress bar with 0 things.
26 Update it it from 1 to 10.
28 (1) Check no exception thrown on creation
29 (2) Check no exception thrown on update
30 (3) Check bar displays name
31 (3) Check bar says nothing to do
37 my $name = 'doing nothing';
38 my $err = capture_stderr {
39 lives_ok { $p = Term::ProgressBar->new($name, 0); } 'V1 mode ( 1)';
40 lives_ok { $p->update($_) for 1..10 } 'V1 mode ( 2)';
43 my @lines = grep { $_ ne ''} split /\r/, $err;
46 like $lines[-1], qr/^$name:/, 'V1 mode ( 3)';
47 like $lines[-1], qr/\(nothing to do\)/, 'V1 mode ( 4)';
50 # -------------------------------------
52 =head2 Tests 6--9: V2 mode
54 Create a progress bar with 0 things.
55 Update it it from 1 to 10.
57 (1) Check no exception thrown on creation
58 (2) Check no exception thrown on update
59 (3) Check bar displays name
60 (4) Check bar says nothing to do
67 my $err = capture_stderr {
68 lives_ok { $p = Term::ProgressBar->new({ count => 0, name => $name }); } 'V2 mode ( 1)';
69 lives_ok { $p->update($_) for 1..10 } 'V2 mode ( 2)';
72 my @lines = grep {$_ ne ''} split /\r/, $err;
75 like $lines[-1], qr/^$name:/, 'V2 mode ( 3)';
76 like $lines[-1], qr/\(nothing to do\)/, 'V2 mode ( 4)';
79 # ----------------------------------------------------------------------------