1 # (X)Emacs mode: -*- cperl -*-
6 =head1 Unit Test Package for Term::ProgressBar
8 This package tests the basic functionality of Term::ProgressBar.
12 use Test::More tests => 31;
15 use Capture::Tiny qw(capture);
17 use_ok 'Term::ProgressBar';
19 Term::ProgressBar->__force_term (50);
21 # -------------------------------------
23 =head2 Tests 2--16: Count 1-10
25 Create a progress bar with 10 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 is complete
31 (4) Check bar number is 100%
32 (5--15) Check bar has no minor characters at any point
36 my ($out, $err) = capture {
38 lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)';
39 lives_ok { $p->update($_) for 1..10 } 'Count 1-10 (2)';
43 my @lines = grep {$_ ne ''} split /\r/, $err;
46 like $lines[-1], qr/\[=+\]/, 'Count 1-10 (3)';
47 like $lines[-1], qr/^\s*100%/, 'Count 1-10 (4)';
48 like $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-10 (%d)', 5+$_)
51 # -------------------------------------
53 =head2 Tests 17--30: Count 1-9
55 Create a progress bar with 10 things.
56 Update it it from 1 to 9.
58 (1) Check no exception thrown on creation
59 (2) Check no exception thrown on update
60 (3) Check bar is incomplete
61 (4) Check bar number is 90%
62 (5--14) Check bar has no minor characters at any point
67 my ($out, $err) = capture {
69 lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-9 (1)';
70 lives_ok { $p->update($_) for 1..9 } 'Count 1-9 (2)';
74 my @lines = grep $_ ne '', split /\r/, $err;
77 like $lines[-1], qr/\[=+ +\]/, 'Count 1-9 (3)';
78 like $lines[-1], qr/^\s*90%/, 'Count 1-9 (4)';
79 like $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-9 (%d)', 5+$_)
82 # -------------------------------------
86 Make sure the same progress bar text is not printed twice to the
87 terminal (in the case of an update that is too little to affect the
88 percentage or displayed bar).
92 my ($out, $err) = capture {
93 my $tp = Term::ProgressBar->new(1000000);
94 $tp->update($_) foreach (0, 1);
98 my @lines = grep {$_ ne ''} split /\r/, $err;