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 );
17 evcheck restore_output save_output );
20 # 1 for compilation test,
25 =head2 Test 1: compilation
27 This test confirms that the test script and the modules it calls compiled
32 use Term::ProgressBar;
34 ok 1, 1, 'compilation';
36 Term::ProgressBar->__force_term (50);
38 # -------------------------------------
40 =head2 Tests 2--10: Count 1-10
42 Create a progress bar with 10 things. Invoke ETA and name on it.
43 Update it it from 1 to 10.
45 (1) Check no exception thrown on creation
46 (2) Check no exception thrown on update 1..5
47 (3) Check no exception thrown on message issued
48 (4) Check no exception thrown on update 6..10
49 (5) Check message seen
50 (6) Check bar is complete
51 (7) Check bar number is 100%
52 (8) Check --DONE-- issued
53 (9) Check estimation done
59 save_output('stderr', *STDERR{IO});
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 } },
74 my $err = restore_output('stderr');
75 # $err =~ s!^.*\r!!gm;
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 # ----------------------------------------------------------------------------