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