]> git.donarmstrong.com Git - term-progressbar.git/blob - t/v1-message.t
upgrade Capture::Tiny and use the new capture_stderr
[term-progressbar.git] / t / v1-message.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 => 8;
13 use Test::Exception;
14
15 use Capture::Tiny qw(capture_stderr);
16
17 my $MESSAGE1 = 'Walking on the Milky Way';
18
19 use_ok 'Term::ProgressBar';
20
21
22 Term::ProgressBar->__force_term (50);
23
24 # -------------------------------------
25
26 =head2 Tests 2--8: Count 1-10
27
28 Create a progress bar with 10 things, and a name 'bob'.
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 (1..5)
33 (3) Check no exception thrown on message send
34 (4) Check no exception thrown on update (6..10)
35 (5) Check message output.
36 (5) Check bar is complete
37 (6) Check bar number is 100%
38
39 =cut
40
41 {
42   my $err = capture_stderr {
43     my $p;
44     lives_ok { $p = Term::ProgressBar->new('bob', 10); } 'Count 1-10 (1)';
45     lives_ok { $p->update($_) for 1..5  } 'Count 1-10 (2)';
46     lives_ok { $p->message($MESSAGE1)    } 'Count 1-10 (3)';
47     lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)';
48   };
49
50   $err =~ s!^.*\r!!gm;
51   diag "ERR:\n$err\nlength: ", length($err)
52     if $ENV{TEST_DEBUG};
53
54   my @lines = split /\n/, $err;
55
56   is $lines[0], $MESSAGE1;
57   like $lines[-1], qr/bob:\s+\d+% \#+/,            'Count 1-10 (6)';
58   like $lines[-1], qr/^bob:\s+100%/,               'Count 1-10 (7)';
59 }