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 );
19 # 1 for compilation test,
24 =head2 Test 1: compilation
26 This test confirms that the test script and the modules it calls compiled
31 use Term::ProgressBar;
33 ok 1, 1, 'compilation';
35 Term::ProgressBar->__force_term (50);
37 # -------------------------------------
39 =head2 Tests 2--10: Count 1-10
41 Create a progress bar with 10 things. Invoke ETA and name on it.
42 Update it it from 1 to 10.
44 (1) Check no exception thrown on creation
45 (2) Check no exception thrown on update 1..5
46 (3) Check no exception thrown on message issued
47 (4) Check no exception thrown on update 6..10
48 (5) Check message seen
49 (6) Check bar is complete
50 (7) Check bar number is 100%
51 (8) Check --DONE-- issued
52 (9) Check estimation done
56 use Capture::Tiny qw(capture);
58 my ($out, $err) = capture {
61 $p = Term::ProgressBar->new({count => 10, name => 'fred',
63 }, 'Count 1-10 (1)' ),
65 ok (evcheck(sub { for (1..5) { $p->update($_); sleep 1 } },
68 ok (evcheck(sub { $p->message('Hello Mum!') },
71 ok (evcheck(sub { for (6..10) { $p->update($_); sleep 1 } },
76 my @lines = grep $_ ne '', split /[\n\r]+/, $err;
79 ok grep $_ eq 'Hello Mum!', @lines;
80 ok $lines[-1], qr/\[=+\]/, 'Count 1-10 (6)';
81 ok $lines[-1], qr/^fred: \s*100%/, 'Count 1-10 (7)';
82 ok $lines[-1], qr/D[ \d]\dh\d{2}m\d{2}s$/, 'Count 1-10 (8)';
83 ok $lines[-2], qr/ Left$/, 'Count 1-10 (9)';
86 # ----------------------------------------------------------------------------