]> git.donarmstrong.com Git - term-progressbar.git/blob - t/eta-linear.t
3d4f06b3c2bcc89e9330995d9d993a96ac7692ef
[term-progressbar.git] / t / eta-linear.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 basic functionality of Term::ProgressBar.
9
10 =cut
11
12 use Test::More tests => 9;
13 use Test::Exception;
14
15 use Capture::Tiny qw(capture);
16
17 use Term::ProgressBar;
18
19 Term::ProgressBar->__force_term (50);
20
21 # -------------------------------------
22
23 =head2 Tests 2--10: Count 1-10
24
25 Create a progress bar with 10 things.  Invoke ETA and name on it.
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 1..5
30 (3) Check no exception thrown on message issued
31 (4) Check no exception thrown on update 6..10
32 (5) Check message seen
33 (6) Check bar is complete
34 (7) Check bar number is 100%
35 (8) Check --DONE-- issued
36 (9) Check estimation done
37
38 =cut
39
40 {
41   my ($out, $err) = capture {
42     my $p;
43     lives_ok {
44                 $p = Term::ProgressBar->new({count => 10, name => 'fred',
45                                              ETA => 'linear'});
46               } 'Count 1-10 (1)';
47     lives_ok { for (1..5) { $p->update($_); sleep 1 } }
48               'Count 1-10 (2)';
49     lives_ok { $p->message('Hello Mum!') }  'Count 1-10 (3)';
50     lives_ok { for (6..10) { $p->update($_); sleep 1 } } 'Count 1-10 (4)';
51   };
52   print $out;
53
54   my @lines = grep $_ ne '', split /[\n\r]+/, $err;
55   diag explain \@lines
56     if $ENV{TEST_DEBUG};
57   ok grep $_ eq 'Hello Mum!', @lines;
58   like $lines[-1], qr/\[=+\]/,                  'Count 1-10 (6)';
59   like $lines[-1], qr/^fred: \s*100%/,          'Count 1-10 (7)';
60   like $lines[-1], qr/D[ \d]\dh\d{2}m\d{2}s$/,  'Count 1-10 (8)';
61   like $lines[-2], qr/ Left$/,                  'Count 1-10 (9)';
62 }
63
64 # ----------------------------------------------------------------------------