]> git.donarmstrong.com Git - term-progressbar.git/blob - t/v2-mobile.t
remove some unused constants
[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 FindBin      qw( $Bin );
13 use Test         qw( ok plan );
14
15 use lib $Bin;
16 use test qw( evcheck restore_output save_output );
17
18 BEGIN {
19   # 1 for compilation test,
20   plan tests  => 7,
21        todo   => [],
22 }
23
24 =head2 Test 1: compilation
25
26 This test confirms that the test script and the modules it calls compiled
27 successfully.
28
29 =cut
30
31 use Term::ProgressBar;
32
33 ok 1, 1, 'compilation';
34
35 Term::ProgressBar->__force_term (50);
36
37 # -------------------------------------
38
39 =head2 Tests 2--7: Count 1-20
40
41 Create a progress bar with 10 things.
42 Update it it from 1 to 5.
43 Change target to 20.
44 Update it from 11 to 20.
45
46 (1) Check no exception thrown on creation
47 (2) Check no exception thrown on update (1..5)
48 (3) Check no exception thrown on target update
49 (4) Check no exception thrown on update (6..10)
50 (5) Check bar is complete
51 (6) Check bar number is 100%
52
53 =cut
54
55 {
56   my $p;
57   save_output('stderr', *STDERR{IO});
58   ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-20 (1)' ),
59       1, 'Count 1-20 (1)');
60   ok (evcheck(sub { $p->update($_) for 1..5  },  'Count 1-20 (2)' ),
61       1, 'Count 1-20 (2)');
62   ok (evcheck(sub { $p->target(20)    },         'Count 1-20 (3)' ),
63       1, 'Count 1-20 (3)');
64   ok (evcheck(sub { $p->update($_) for 11..20 }, 'Count 1-20 (4)' ),
65       1, 'Count 1-20 (4)');
66   my $err = restore_output('stderr');
67
68   $err =~ s!^.*\r!!gm;
69   print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
70     if $ENV{TEST_DEBUG};
71
72   my @lines = split /\n/, $err;
73
74   ok $lines[-1], qr/\[=+\]/,            'Count 1-20 (5)';
75   ok $lines[-1], qr/^\s*100%/,          'Count 1-20 (6)';
76 }