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 => 8;
15 use constant MESSAGE1 => 'Walking on the Milky Way';
17 =head2 Test 1: compilation
19 This test confirms that the test script and the modules it calls compiled
24 use_ok 'Term::ProgressBar';
27 Term::ProgressBar->__force_term (50);
29 # -------------------------------------
31 =head2 Tests 2--8: Count 1-10
33 Create a progress bar with 10 things, and a name 'bob'.
34 Update it it from 1 to 10.
36 (1) Check no exception thrown on creation
37 (2) Check no exception thrown on update (1..5)
38 (3) Check no exception thrown on message send
39 (4) Check no exception thrown on update (6..10)
40 (5) Check message output.
41 (5) Check bar is complete
42 (6) Check bar number is 100%
45 use Capture::Tiny qw(capture);
47 my ($out, $err) = capture {
49 lives_ok { $p = Term::ProgressBar->new('bob', 10); } 'Count 1-10 (1)';
50 lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)';
51 lives_ok { $p->message(MESSAGE1) } 'Count 1-10 (3)';
52 lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)';
57 print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
60 my @lines = split /\n/, $err;
62 is $lines[0], MESSAGE1;
63 like $lines[-1], qr/bob:\s+\d+% \#+/, 'Count 1-10 (6)';
64 like $lines[-1], qr/^bob:\s+100%/, 'Count 1-10 (7)';