]> git.donarmstrong.com Git - term-progressbar.git/blob - t/v2-mobile.t
5176a52b8cfec437274dcd3f6ffec49793c36130
[term-progressbar.git] / t / v2-mobile.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 moving target functionality of Term::ProgressBar.
8
9 =cut
10
11 use Data::Dumper qw( Dumper );
12 use Test::More tests => 7;
13 use Test::Exception;
14
15 use Capture::Tiny qw(capture);
16
17 use_ok 'Term::ProgressBar';
18
19 Term::ProgressBar->__force_term (50);
20
21 # -------------------------------------
22
23 =head2 Tests 2--7: Count 1-20
24
25 Create a progress bar with 10 things.
26 Update it it from 1 to 5.
27 Change target to 20.
28 Update it from 11 to 20.
29
30 (1) Check no exception thrown on creation
31 (2) Check no exception thrown on update (1..5)
32 (3) Check no exception thrown on target update
33 (4) Check no exception thrown on update (6..10)
34 (5) Check bar is complete
35 (6) Check bar number is 100%
36
37 =cut
38
39 my ($out, $err) = capture {
40   my $p;
41   lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-20 (1)';
42   lives_ok { $p->update($_) for 1..5  }    'Count 1-20 (2)';
43   lives_ok { $p->target(20)    }           'Count 1-20 (3)';
44   lives_ok { $p->update($_) for 11..20 }   'Count 1-20 (4)';
45 };
46 print $out;
47
48   $err =~ s!^.*\r!!gm;
49   print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
50     if $ENV{TEST_DEBUG};
51
52   my @lines = split /\n/, $err;
53
54   like $lines[-1], qr/\[=+\]/,            'Count 1-20 (5)';
55   like $lines[-1], qr/^\s*100%/,          'Count 1-20 (6)';