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); };
34 is $err, "$test_str: ";
37 # print Data::Dumper->Dump([$b, $out, $err], [qw( b o e)])
38 # if $ENV{TEST_DEBUG};
40 diag 'do half the stuff and check half the bar has printed';
41 my $halfway = floor($count / 2);
43 my ($out, $err) = capture { update $tp foreach (0 .. $halfway - 1) };
45 is $err, ('#' x floor(50 / 2));
47 # print Data::Dumper->Dump([$o], [qw( o )])
48 # if $ENV{TEST_DEBUG};
51 # do the rest of the stuff and check the whole bar has printed
53 my ($out, $err) = capture { update $tp foreach ($halfway .. $count - 1) };
55 is $err, ('#' x ceil(50 / 2)) . "\n";
56 # print Data::Dumper->Dump([$o], [qw( o )])
57 # if $ENV{TEST_DEBUG};
61 # try to do another item and check there is an error
64 is substr($@, 0, length(Term::ProgressBar::ALREADY_FINISHED)),
65 Term::ProgressBar::ALREADY_FINISHED;
66 # print Data::Dumper->Dump([$@], [qw( @ )])
67 # if $ENV{TEST_DEBUG};