File: compat.t

package info (click to toggle)
libterm-progressbar-perl 2.23-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 224 kB
  • sloc: perl: 596; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,371 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# (X)Emacs mode: -*- cperl -*-

use strict;
use warnings;

=head1 Unit Test Package for Term::ProgressBar v1.0 Compatibility

This script is based on the test script for Term::ProgressBar version 1.0,
and is intended to test compatibility with that version.

=cut

# Utility -----------------------------

use Test::More tests => 10;
use Test::Warnings;

use Term::ProgressBar;
use POSIX qw<floor ceil>;
use Capture::Tiny qw(capture);

$| = 1;

my $count = 100;

diag 'create a bar';
my $test_str = 'test';

my $tp;
{
  my ($out, $err) = capture { $tp = Term::ProgressBar->new($test_str, $count); };
  isa_ok $tp, 'Term::ProgressBar';
  is $out, '', 'empty stdout';
  is $err, "$test_str: ";
}

diag 'do half the stuff and check half the bar has printed';
my $halfway = floor($count / 2);
{
  my ($out, $err) = capture { $tp->update foreach (0 .. $halfway - 1) };
  is $out, '', 'empty stdout';
  is $err, ('#' x floor(50 / 2));
}

# do the rest of the stuff and check the whole bar has printed
{
   my ($out, $err) = capture { $tp->update foreach ($halfway .. $count - 1) };
   is $out, '', 'empty stdout';
   is $err, ('#' x ceil(50 / 2)) . "\n";
}

# try to do another item and check there is an error
eval { $tp->update };
my $err = $@;
ok defined($err);
is substr($err, 0, length(Term::ProgressBar::ALREADY_FINISHED)),
          Term::ProgressBar::ALREADY_FINISHED;