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 qw( ok plan );
16 use test qw( evcheck );
18 use Capture::Tiny qw(capture);
21 # 1 for compilation test,
26 =head2 Test 1: compilation
28 This test confirms that the test script and the modules it calls compiled
33 use Term::ProgressBar;
35 ok 1, 1, 'compilation';
37 Term::ProgressBar->__force_term (50);
39 # -------------------------------------
41 =head2 Tests 2--16: Count 1-10
43 Create a progress bar with 10 things.
44 Update it it from 1 to 10.
46 (1) Check no exception thrown on creation
47 (2) Check no exception thrown on update
48 (3) Check bar is complete
49 (4) Check bar number is 100%
50 (5--15) Check bar has no minor characters at any point
56 my ($out, $err) = capture {
57 ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-10 (1)' ),
59 ok (evcheck(sub { $p->update($_) for 1..10 }, 'Count 1-10 (2)' ),
63 my @lines = grep $_ ne '', split /\r/, $err;
66 ok $lines[-1], qr/\[=+\]/, 'Count 1-10 (3)';
67 ok $lines[-1], qr/^\s*100%/, 'Count 1-10 (4)';
68 ok $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-10 (%d)', 5+$_)
71 # -------------------------------------
73 =head2 Tests 17--30: Count 1-9
75 Create a progress bar with 10 things.
76 Update it it from 1 to 9.
78 (1) Check no exception thrown on creation
79 (2) Check no exception thrown on update
80 (3) Check bar is incomplete
81 (4) Check bar number is 90%
82 (5--14) Check bar has no minor characters at any point
89 my ($out, $err) = capture {
90 ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-9 (1)' ),
92 ok (evcheck(sub { $p->update($_) for 1..9 }, 'Count 1-9 (2)' ),
97 my @lines = grep $_ ne '', split /\r/, $err;
100 ok $lines[-1], qr/\[=+ +\]/, 'Count 1-9 (3)';
101 ok $lines[-1], qr/^\s*90%/, 'Count 1-9 (4)';
102 ok $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-9 (%d)', 5+$_)
105 # -------------------------------------
109 Make sure the same progress bar text is not printed twice to the
110 terminal (in the case of an update that is too little to affect the
111 percentage or displayed bar).
115 my ($out, $err) = capture {
116 my $b = Term::ProgressBar->new(1000000);
117 $b->update($_) foreach (0, 1);
120 my @lines = grep $_ ne '', split /\r/, $err;