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 Test::More tests => 9;
15 =head2 Test 1: compilation
17 This test confirms that the test script and the modules it calls compiled
22 use Term::ProgressBar;
24 Term::ProgressBar->__force_term (50);
26 # -------------------------------------
28 =head2 Tests 2--10: Count 1-10
30 Create a progress bar with 10 things. Invoke ETA and name on it.
31 Update it it from 1 to 10.
33 (1) Check no exception thrown on creation
34 (2) Check no exception thrown on update 1..5
35 (3) Check no exception thrown on message issued
36 (4) Check no exception thrown on update 6..10
37 (5) Check message seen
38 (6) Check bar is complete
39 (7) Check bar number is 100%
40 (8) Check --DONE-- issued
41 (9) Check estimation done
45 use Capture::Tiny qw(capture);
47 my ($out, $err) = capture {
50 $p = Term::ProgressBar->new({count => 10, name => 'fred',
53 lives_ok { for (1..5) { $p->update($_); sleep 1 } }
55 lives_ok { $p->message('Hello Mum!') } 'Count 1-10 (3)';
56 lives_ok { for (6..10) { $p->update($_); sleep 1 } } 'Count 1-10 (4)';
59 my @lines = grep $_ ne '', split /[\n\r]+/, $err;
62 ok grep $_ eq 'Hello Mum!', @lines;
63 like $lines[-1], qr/\[=+\]/, 'Count 1-10 (6)';
64 like $lines[-1], qr/^fred: \s*100%/, 'Count 1-10 (7)';
65 like $lines[-1], qr/D[ \d]\dh\d{2}m\d{2}s$/, 'Count 1-10 (8)';
66 like $lines[-2], qr/ Left$/, 'Count 1-10 (9)';
69 # ----------------------------------------------------------------------------