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 => 8;
16 use test qw( evcheck );
18 use constant MESSAGE1 => 'Walking on the Milky Way';
20 =head2 Test 1: compilation
22 This test confirms that the test script and the modules it calls compiled
27 use_ok 'Term::ProgressBar';
30 Term::ProgressBar->__force_term (50);
32 # -------------------------------------
34 =head2 Tests 2--8: Count 1-10
36 Create a progress bar with 10 things, and a name 'bob'.
37 Update it it from 1 to 10.
39 (1) Check no exception thrown on creation
40 (2) Check no exception thrown on update (1..5)
41 (3) Check no exception thrown on message send
42 (4) Check no exception thrown on update (6..10)
43 (5) Check message output.
44 (5) Check bar is complete
45 (6) Check bar number is 100%
48 use Capture::Tiny qw(capture);
50 my ($out, $err) = capture {
52 ok (evcheck(sub { $p = Term::ProgressBar->new('bob', 10); },
55 ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-10 (2)' ),
57 ok (evcheck(sub { $p->message(MESSAGE1) }, 'Count 1-10 (3)' ),
59 ok (evcheck(sub { $p->update($_) for 6..10 }, 'Count 1-10 (4)' ),
65 print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
68 my @lines = split /\n/, $err;
70 is $lines[0], MESSAGE1;
71 like $lines[-1], qr/bob:\s+\d+% \#+/, 'Count 1-10 (6)';
72 like $lines[-1], qr/^bob:\s+100%/, 'Count 1-10 (7)';