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 Test::More tests => 9;
17 use Term::ProgressBar;
18 use POSIX qw<floor ceil>;
19 use Capture::Tiny qw(capture);
26 my $test_str = 'test';
30 my ($out, $err) = capture { $tp = Term::ProgressBar->new($test_str, $count); };
31 isa_ok $tp, 'Term::ProgressBar';
32 is $out, '', 'empty stdout';
33 is $err, "$test_str: ";
36 diag 'do half the stuff and check half the bar has printed';
37 my $halfway = floor($count / 2);
39 my ($out, $err) = capture { $tp->update foreach (0 .. $halfway - 1) };
40 is $out, '', 'empty stdout';
41 is $err, ('#' x floor(50 / 2));
44 # do the rest of the stuff and check the whole bar has printed
46 my ($out, $err) = capture { $tp->update foreach ($halfway .. $count - 1) };
47 is $out, '', 'empty stdout';
48 is $err, ('#' x ceil(50 / 2)) . "\n";
51 # try to do another item and check there is an error
55 is substr($err, 0, length(Term::ProgressBar::ALREADY_FINISHED)),
56 Term::ProgressBar::ALREADY_FINISHED;