]> git.donarmstrong.com Git - term-progressbar.git/blob - t/zero.t
ffabda91e980f4a98ac924043c7f8a73799a81d0
[term-progressbar.git] / t / zero.t
1 # (X)Emacs mode: -*- cperl -*-
2
3 use strict;
4
5 =head1 Unit Test Package for Term::ProgressBar
6
7 This package tests the zero-progress handling of progress bar.
8
9 =cut
10
11 use Data::Dumper qw( Dumper );
12 use Test::More tests => 9;
13 use Test::Exception;
14
15 use Capture::Tiny qw(capture);
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;
38 my ($out, $err)  = capture {
39   $name = 'doing nothing';
40   lives_ok { $p = Term::ProgressBar->new($name, 0); } 'V1 mode ( 1)';
41   lives_ok { $p->update($_) for 1..10 } 'V1 mode ( 2)';
42 };
43 print $out;
44   my @lines = grep $_ ne '', split /\r/, $err;
45   print Dumper \@lines
46     if $ENV{TEST_DEBUG};
47   like $lines[-1], qr/^$name:/,                                  'V1 mode ( 3)';
48   like $lines[-1], qr/\(nothing to do\)/,                        'V1 mode ( 4)';
49 }
50
51 # -------------------------------------
52
53 =head2 Tests 6--9: V2 mode
54
55 Create a progress bar with 0 things.
56 Update it it from 1 to 10.
57
58 (1) Check no exception thrown on creation
59 (2) Check no exception thrown on update
60 (3) Check bar displays name
61 (4) Check bar says nothing to do
62
63 =cut
64
65 {
66   my $p;
67   my $name = 'zero';
68 my ($out, $err) = capture {
69   lives_ok { $p = Term::ProgressBar->new({ count => 0, name => $name }); } 'V2 mode ( 1)';
70   lives_ok { $p->update($_) for 1..10 } 'V2 mode ( 2)';
71 };
72 print $out;
73   my @lines = grep $_ ne '', split /\r/, $err;
74   print Dumper \@lines
75     if $ENV{TEST_DEBUG};
76   like $lines[-1], qr/^$name:/,                                  'V2 mode ( 3)';
77   like $lines[-1], qr/\(nothing to do\)/,                        'V2 mode ( 4)';
78 }
79
80 # ----------------------------------------------------------------------------