]> git.donarmstrong.com Git - term-progressbar.git/blob - t/zero.t
switch from Test to Test::More
[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 FindBin      qw( $Bin );
13 use Test::More tests => 9;
14
15 use Capture::Tiny qw(capture);
16
17 use lib $Bin;
18 use test qw( evcheck );
19
20 use_ok 'Term::ProgressBar';
21
22 Term::ProgressBar->__force_term (50);
23
24 # -------------------------------------
25
26 =head2 Tests 2--5: V1 mode
27
28 Create a progress bar with 0 things.
29 Update it it from 1 to 10.
30
31 (1) Check no exception thrown on creation
32 (2) Check no exception thrown on update
33 (3) Check bar displays name
34 (3) Check bar says nothing to do
35
36 =cut
37
38 {
39   my $p;
40   my $name;
41 my ($out, $err)  = capture {
42   $name = 'doing nothing';
43   ok (evcheck(sub { $p = Term::ProgressBar->new($name, 0); },
44          'V1 mode ( 1)' ),
45                                                              'V1 mode ( 1)');
46   ok (evcheck(sub { $p->update($_) for 1..10 },'V1 mode ( 2)'),
47                                                              'V1 mode ( 2)');
48 };
49 print $out;
50   my @lines = grep $_ ne '', split /\r/, $err;
51   print Dumper \@lines
52     if $ENV{TEST_DEBUG};
53   like $lines[-1], qr/^$name:/,                                  'V1 mode ( 3)';
54   like $lines[-1], qr/\(nothing to do\)/,                        'V1 mode ( 4)';
55 }
56
57 # -------------------------------------
58
59 =head2 Tests 6--9: V2 mode
60
61 Create a progress bar with 0 things.
62 Update it it from 1 to 10.
63
64 (1) Check no exception thrown on creation
65 (2) Check no exception thrown on update
66 (3) Check bar displays name
67 (4) Check bar says nothing to do
68
69 =cut
70
71 {
72   my $p;
73   my $name = 'zero';
74 my ($out, $err) = capture {
75   ok (evcheck(sub { $p = Term::ProgressBar->new({ count => 0,
76                                                   name => $name }); },
77          'V2 mode ( 1)' ),
78                                                             'V2 mode ( 1)');
79   ok (evcheck(sub { $p->update($_) for 1..10 },'V2 mode ( 2)'),
80                                                             'V2 mode ( 2)');
81 };
82 print $out;
83   my @lines = grep $_ ne '', split /\r/, $err;
84   print Dumper \@lines
85     if $ENV{TEST_DEBUG};
86   like $lines[-1], qr/^$name:/,                                  'V2 mode ( 3)';
87   like $lines[-1], qr/\(nothing to do\)/,                        'V2 mode ( 4)';
88 }
89
90 # ----------------------------------------------------------------------------