1 # (X)Emacs mode: -*- cperl -*-
6 =head1 Unit Test Package for Term::ProgressBar v1.0 Compatibility
8 This script is based on the test script for Term::ProgressBar version 1.0,
9 and is intended to test compatibility with that version.
13 # Utility -----------------------------
15 use Data::Dumper qw( );
16 use Test::More tests => 9;
18 use Term::ProgressBar;
19 use POSIX qw<floor ceil>;
20 use Capture::Tiny qw(capture);
27 my $test_str = 'test';
31 my ($out, $err) = capture { $tp = Term::ProgressBar->new($test_str, $count); };
32 isa_ok $tp, 'Term::ProgressBar';
33 is $out, '', 'empty stdout';
34 is $err, "$test_str: ";
37 diag 'do half the stuff and check half the bar has printed';
38 my $halfway = floor($count / 2);
40 my ($out, $err) = capture { $tp->update foreach (0 .. $halfway - 1) };
41 is $out, '', 'empty stdout';
42 is $err, ('#' x floor(50 / 2));
45 # do the rest of the stuff and check the whole bar has printed
47 my ($out, $err) = capture { $tp->update foreach ($halfway .. $count - 1) };
48 is $out, '', 'empty stdout';
49 is $err, ('#' x ceil(50 / 2)) . "\n";
52 # try to do another item and check there is an error
56 is substr($err, 0, length(Term::ProgressBar::ALREADY_FINISHED)),
57 Term::ProgressBar::ALREADY_FINISHED;