]> git.donarmstrong.com Git - term-progressbar.git/blob - t/zero.t
upgrade Capture::Tiny and use the new capture_stderr
[term-progressbar.git] / t / zero.t
1 # (X)Emacs mode: -*- cperl -*-
2
3 use strict;
4 use warnings;
5
6 =head1 Unit Test Package for Term::ProgressBar
7
8 This package tests the zero-progress handling of progress bar.
9
10 =cut
11
12 use Test::More tests => 9;
13 use Test::Exception;
14
15 use Capture::Tiny qw(capture_stderr);
16
17 use_ok 'Term::ProgressBar';
18
19 Term::ProgressBar->__force_term (50);
20
21 # -------------------------------------
22
23 =head2 Tests 2--5: V1 mode
24
25 Create a progress bar with 0 things.
26 Update it it from 1 to 10.
27
28 (1) Check no exception thrown on creation
29 (2) Check no exception thrown on update
30 (3) Check bar displays name
31 (3) Check bar says nothing to do
32
33 =cut
34
35 {
36   my $p;
37   my $name = 'doing nothing';
38   my $err  = capture_stderr {
39     lives_ok { $p = Term::ProgressBar->new($name, 0); } 'V1 mode ( 1)';
40     lives_ok { $p->update($_) for 1..10 } 'V1 mode ( 2)';
41   };
42
43   my @lines = grep { $_ ne ''} split /\r/, $err;
44   diag explain @lines
45     if $ENV{TEST_DEBUG};
46   like $lines[-1], qr/^$name:/,                                  'V1 mode ( 3)';
47   like $lines[-1], qr/\(nothing to do\)/,                        'V1 mode ( 4)';
48 }
49
50 # -------------------------------------
51
52 =head2 Tests 6--9: V2 mode
53
54 Create a progress bar with 0 things.
55 Update it it from 1 to 10.
56
57 (1) Check no exception thrown on creation
58 (2) Check no exception thrown on update
59 (3) Check bar displays name
60 (4) Check bar says nothing to do
61
62 =cut
63
64 {
65   my $p;
66   my $name = 'zero';
67   my $err = capture_stderr {
68     lives_ok { $p = Term::ProgressBar->new({ count => 0, name => $name }); } 'V2 mode ( 1)';
69     lives_ok { $p->update($_) for 1..10 } 'V2 mode ( 2)';
70   };
71
72   my @lines = grep {$_ ne ''} split /\r/, $err;
73   diag explain @lines
74     if $ENV{TEST_DEBUG};
75   like $lines[-1], qr/^$name:/,             'V2 mode ( 3)';
76   like $lines[-1], qr/\(nothing to do\)/,   'V2 mode ( 4)';
77 }
78
79 # ----------------------------------------------------------------------------