]> git.donarmstrong.com Git - term-progressbar.git/blob - t/v1-message.t
switch to useint Test::Exception instead of the home made code, remote test.pm
[term-progressbar.git] / t / v1-message.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 => 8;
13 use Test::Exception;
14
15 use constant MESSAGE1 => 'Walking on the Milky Way';
16
17 =head2 Test 1: compilation
18
19 This test confirms that the test script and the modules it calls compiled
20 successfully.
21
22 =cut
23
24 use_ok 'Term::ProgressBar';
25
26
27 Term::ProgressBar->__force_term (50);
28
29 # -------------------------------------
30
31 =head2 Tests 2--8: Count 1-10
32
33 Create a progress bar with 10 things, and a name 'bob'.
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 send
39 (4) Check no exception thrown on update (6..10)
40 (5) Check message output.
41 (5) Check bar is complete
42 (6) Check bar number is 100%
43
44 =cut
45 use Capture::Tiny qw(capture);
46
47 my ($out, $err) = capture {
48   my $p;
49   lives_ok { $p = Term::ProgressBar->new('bob', 10); } 'Count 1-10 (1)';
50   lives_ok { $p->update($_) for 1..5  } 'Count 1-10 (2)';
51   lives_ok { $p->message(MESSAGE1)    } 'Count 1-10 (3)';
52   lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)';
53 };
54 print $out;
55
56   $err =~ s!^.*\r!!gm;
57   print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
58     if $ENV{TEST_DEBUG};
59
60   my @lines = split /\n/, $err;
61
62   is $lines[0], MESSAGE1;
63   like $lines[-1], qr/bob:\s+\d+% \#+/,            'Count 1-10 (6)';
64   like $lines[-1], qr/^bob:\s+100%/,               'Count 1-10 (7)';