1 # (X)Emacs mode: -*- cperl -*-
5 =head1 Unit Test Package for Term::ProgressBar
7 This package tests the basic functionality of Term::ProgressBar.
11 use Data::Dumper qw( Dumper );
12 use FindBin qw( $Bin );
13 use Test::More tests => 31;
16 use test qw( evcheck );
18 use Capture::Tiny qw(capture);
20 use_ok 'Term::ProgressBar';
22 Term::ProgressBar->__force_term (50);
24 # -------------------------------------
26 =head2 Tests 2--16: Count 1-10
28 Create a progress bar with 10 things.
29 Update it it from 1 to 10.
31 (1) Check no exception thrown on creation
32 (2) Check no exception thrown on update
33 (3) Check bar is complete
34 (4) Check bar number is 100%
35 (5--15) Check bar has no minor characters at any point
41 my ($out, $err) = capture {
42 ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-10 (1)' ),
44 ok (evcheck(sub { $p->update($_) for 1..10 }, 'Count 1-10 (2)' ),
48 my @lines = grep $_ ne '', split /\r/, $err;
51 like $lines[-1], qr/\[=+\]/, 'Count 1-10 (3)';
52 like $lines[-1], qr/^\s*100%/, 'Count 1-10 (4)';
53 like $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-10 (%d)', 5+$_)
56 # -------------------------------------
58 =head2 Tests 17--30: Count 1-9
60 Create a progress bar with 10 things.
61 Update it it from 1 to 9.
63 (1) Check no exception thrown on creation
64 (2) Check no exception thrown on update
65 (3) Check bar is incomplete
66 (4) Check bar number is 90%
67 (5--14) Check bar has no minor characters at any point
74 my ($out, $err) = capture {
75 ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-9 (1)' ),
77 ok (evcheck(sub { $p->update($_) for 1..9 }, 'Count 1-9 (2)' ),
82 my @lines = grep $_ ne '', split /\r/, $err;
85 like $lines[-1], qr/\[=+ +\]/, 'Count 1-9 (3)';
86 like $lines[-1], qr/^\s*90%/, 'Count 1-9 (4)';
87 like $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-9 (%d)', 5+$_)
90 # -------------------------------------
94 Make sure the same progress bar text is not printed twice to the
95 terminal (in the case of an update that is too little to affect the
96 percentage or displayed bar).
100 my ($out, $err) = capture {
101 my $b = Term::ProgressBar->new(1000000);
102 $b->update($_) foreach (0, 1);
105 my @lines = grep $_ ne '', split /\r/, $err;