]> git.donarmstrong.com Git - term-progressbar.git/blob - t/silent.t
Merge pull request #4 from neilbowers/master
[term-progressbar.git] / t / silent.t
1 # (X)Emacs mode: -*- cperl -*-
2
3 use strict;
4 use warnings;
5 use Term::ProgressBar;
6
7 =head1 Unit Test Package for Term::ProgressBar
8
9 This package tests the basic functionality of Term::ProgressBar.
10
11 =cut
12
13 use Test::More tests => 8;
14 use Test::Exception;
15
16 use Capture::Tiny qw(capture_stderr);
17
18 my $MESSAGE1 = 'Walking on the Milky Way';
19
20 # -------------------------------------
21
22 =head2 Test
23
24 Create a progress bar with 10 things.
25 Update it it from 1 to 10.  Verify that it has no output.
26
27 =cut
28 {
29   my $err = capture_stderr {
30     my $p;
31     lives_ok { $p = Term::ProgressBar->new({ count => 10, silent => 1}); } 'Count 1-10 (1)';
32     lives_ok { $p->update($_) for 1..5  }         'Count 1-10 (2)';
33     lives_ok { $p->message($MESSAGE1)    }         'Count 1-10 (3)';
34     lives_ok { $p->update($_) for 6..10 }         'Count 1-10 (4)';
35   };
36
37   diag "ERR:\n$err\nlength: " . length($err)
38     if $ENV{TEST_DEBUG};
39   ok !$err, 'We should have no output';
40 }
41
42 # -------------------------------------
43
44 =head2 Tests 9--11: Message Check
45
46 Run a progress bar from 0 to 100, each time calling a message after an update.
47 Check that we still have no output.
48
49 =cut
50
51 {
52   my $err = capture_stderr {
53     my $p;
54     lives_ok { $p = Term::ProgressBar->new({ count => 100, silent => 1}); } 'Message Check ( 1)';
55     lives_ok { for (0..100) { $p->update($_); $p->message("Hello") } }  'Message Check ( 2)';
56   };
57
58   ok !$err, 'We should sill have no output';
59 }
60
61 # ----------------------------------------------------------------------------