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