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 Test::More tests => 9;
15 use Capture::Tiny qw(capture);
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
38 my ($out, $err) = capture {
39 $name = 'doing nothing';
40 lives_ok { $p = Term::ProgressBar->new($name, 0); } 'V1 mode ( 1)';
41 lives_ok { $p->update($_) for 1..10 } 'V1 mode ( 2)';
44 my @lines = grep $_ ne '', split /\r/, $err;
47 like $lines[-1], qr/^$name:/, 'V1 mode ( 3)';
48 like $lines[-1], qr/\(nothing to do\)/, 'V1 mode ( 4)';
51 # -------------------------------------
53 =head2 Tests 6--9: V2 mode
55 Create a progress bar with 0 things.
56 Update it it from 1 to 10.
58 (1) Check no exception thrown on creation
59 (2) Check no exception thrown on update
60 (3) Check bar displays name
61 (4) Check bar says nothing to do
68 my ($out, $err) = capture {
69 lives_ok { $p = Term::ProgressBar->new({ count => 0, name => $name }); } 'V2 mode ( 1)';
70 lives_ok { $p->update($_) for 1..10 } 'V2 mode ( 2)';
73 my @lines = grep $_ ne '', split /\r/, $err;
76 like $lines[-1], qr/^$name:/, 'V2 mode ( 3)';
77 like $lines[-1], qr/\(nothing to do\)/, 'V2 mode ( 4)';
80 # ----------------------------------------------------------------------------