# Utility -----------------------------
-use Data::Dumper qw( );
use Test::More tests => 9;
use Term::ProgressBar;
# (X)Emacs mode: -*- cperl -*-
use strict;
+use warnings;
=head1 Unit Test Package for Term::ProgressBar
=cut
-use Data::Dumper qw( Dumper );
use Test::More tests => 9;
use Test::Exception;
-=head2 Test 1: compilation
-
-This test confirms that the test script and the modules it calls compiled
-successfully.
-
-=cut
+use Capture::Tiny qw(capture);
use Term::ProgressBar;
=cut
-use Capture::Tiny qw(capture);
-
-my ($out, $err) = capture {
- my $p;
- lives_ok {
+{
+ my ($out, $err) = capture {
+ my $p;
+ lives_ok {
$p = Term::ProgressBar->new({count => 10, name => 'fred',
ETA => 'linear'});
} 'Count 1-10 (1)';
- lives_ok { for (1..5) { $p->update($_); sleep 1 } }
+ lives_ok { for (1..5) { $p->update($_); sleep 1 } }
'Count 1-10 (2)';
- lives_ok { $p->message('Hello Mum!') } 'Count 1-10 (3)';
- lives_ok { for (6..10) { $p->update($_); sleep 1 } } 'Count 1-10 (4)';
-};
-print $out;
+ lives_ok { $p->message('Hello Mum!') } 'Count 1-10 (3)';
+ lives_ok { for (6..10) { $p->update($_); sleep 1 } } 'Count 1-10 (4)';
+ };
+ print $out;
+
my @lines = grep $_ ne '', split /[\n\r]+/, $err;
- print Dumper \@lines
+ diag explain \@lines
if $ENV{TEST_DEBUG};
ok grep $_ eq 'Hello Mum!', @lines;
- like $lines[-1], qr/\[=+\]/, 'Count 1-10 (6)';
- like $lines[-1], qr/^fred: \s*100%/, 'Count 1-10 (7)';
- like $lines[-1], qr/D[ \d]\dh\d{2}m\d{2}s$/, 'Count 1-10 (8)';
- like $lines[-2], qr/ Left$/, 'Count 1-10 (9)';
-
+ like $lines[-1], qr/\[=+\]/, 'Count 1-10 (6)';
+ like $lines[-1], qr/^fred: \s*100%/, 'Count 1-10 (7)';
+ like $lines[-1], qr/D[ \d]\dh\d{2}m\d{2}s$/, 'Count 1-10 (8)';
+ like $lines[-2], qr/ Left$/, 'Count 1-10 (9)';
+}
# ----------------------------------------------------------------------------
# (X)Emacs mode: -*- cperl -*-
use strict;
+use warnings;
=head1 Unit Test Package for Term::ProgressBar
=cut
-use Data::Dumper qw( Dumper );
-use Test::More tests => 18;
+use Test::More tests => 20;
use Test::Exception;
-use constant MESSAGE1 => 'The Gospel of St. Jude';
-use constant NAME1 => 'Algenon';
-use constant NAME2 => 'Smegma';
-
-
-=head2 Test 1: compilation
-
-This test confirms that the test script and the modules it calls compiled
-successfully.
+use Capture::Tiny qw(capture);
-=cut
+my $MESSAGE1 = 'The Gospel of St. Jude';
+my $NAME1 = 'Algenon';
+my $NAME2 = 'Smegma';
use_ok 'Term::ProgressBar';
=cut
-use Capture::Tiny qw(capture);
-
{
my $p;
-my ($out, $err) = capture {
- lives_ok {
- $p = Term::ProgressBar->new({count => 10, name => NAME1});
+ my ($out, $err) = capture {
+ lives_ok {
+ $p = Term::ProgressBar->new({count => 10, name => $NAME1});
} 'Count 1-10 ( 1)';
- lives_ok { $p->update($_) for 1..3 } 'Count 1-10 ( 2)';
-};
-print $out;
+ lives_ok { $p->update($_) for 1..3 } 'Count 1-10 ( 2)';
+ };
+ print $out;
$err =~ s!^.*\r!!gm;
- print STDERR "ERR (1) :\n$err\nlength: ", length($err), "\n"
+ diag "ERR (1) :\n$err\nlength: " . length($err)
if $ENV{TEST_DEBUG};
my @lines = split /\n/, $err;
- like $lines[-1], qr/^@{[NAME1()]}: \s*\b30%/, 'Count 1-10 ( 3)';
+ like $lines[-1], qr/^@{[$NAME1]}: \s*\b30%/, 'Count 1-10 ( 3)';
my ($bar, $space) = $lines[-1] =~ /\[(=*)(\s*)\]/;
my $length = length($bar) + length($space);
print STDERR
("LENGTHS (1) :BAR:", length($bar), ":SPACE:", length($space), "\n")
if $ENV{TEST_DEBUG};
my $barexpect = $length * 0.3;
- my $ok = length($bar) > $barexpect -1 && length($bar) < $barexpect+1;
- ok $ok;
+ cmp_ok length($bar), '>', $barexpect -1;
+ cmp_ok length($bar), '<', $barexpect+1;
-($out, $err) = capture {
- lives_ok { $p->message(MESSAGE1) } 'Count 1-10 ( 5)';
- lives_ok { $p->update($_) for 6..10 } 'Count 1-10 ( 6)';
-};
-print $out;
+ ($out, $err) = capture {
+ lives_ok { $p->message($MESSAGE1) } 'Count 1-10 ( 5)';
+ lives_ok { $p->update($_) for 6..10 } 'Count 1-10 ( 6)';
+ };
+ print $out;
$err =~ s!^.*\r!!gm;
- print STDERR "ERR (2) :\n$err\nlength: ", length($err), "\n"
+ diag "ERR (2) :\n$err\nlength: " . length($err)
if $ENV{TEST_DEBUG};
@lines = split /\n/, $err;
- is $lines[0], MESSAGE1, 'Count 1-10 ( 7)';
+ is $lines[0], $MESSAGE1, 'Count 1-10 ( 7)';
like $lines[-1], qr/\[=+\]/, 'Count 1-10 ( 8)';
- like $lines[-1], qr/^@{[NAME1()]}: \s*100%/, 'Count 1-10 ( 9)';
+ like $lines[-1], qr/^@{[$NAME1]}: \s*100%/, 'Count 1-10 ( 9)';
}
# -------------------------------------
{
my $p;
-my ($out, $err) = capture {
- lives_ok { $p = Term::ProgressBar->new(NAME2, 10); } 'Count 1-10 ( 1)';
- lives_ok { $p->update($_) for 1..3 } 'Count 1-10 ( 2)';
-};
-print $out;
+ my ($out, $err) = capture {
+ lives_ok { $p = Term::ProgressBar->new($NAME2, 10); } 'Count 1-10 ( 1)';
+ lives_ok { $p->update($_) for 1..3 } 'Count 1-10 ( 2)';
+ };
+ print $out;
$err =~ s!^.*\r!!gm;
- print STDERR "ERR (1) :\n$err\nlength: ", length($err), "\n"
+ diag "ERR (1) :\n$err\nlength: " . length($err)
if $ENV{TEST_DEBUG};
my @lines = split /\n/, $err;
- like $lines[-1], qr/^@{[NAME2()]}: \s*\b30%/, 'Count 1-10 ( 3)';
+ like $lines[-1], qr/^@{[$NAME2]}: \s*\b30%/, 'Count 1-10 ( 3)';
my ($bar, $space) = $lines[-1] =~ /(\#*)(\s*)/;
my $length = length($bar) + length($space);
- print STDERR
- ("LENGTHS (1) :BAR:", length($bar), ":SPACE:", length($space), "\n")
- if $ENV{TEST_DEBUG};
+ diag
+ ("LENGTHS (1) :BAR:" . length($bar) . ":SPACE:" . length($space))
+ if $ENV{TEST_DEBUG};
my $barexpect = $length * 0.3;
- my $ok = length($bar) > $barexpect -1 && length($bar) < $barexpect+1;
- ok $ok;
+ cmp_ok length($bar), '>', $barexpect -1;
+ cmp_ok length($bar), '<', $barexpect+1;
-($out, $err) = capture {
- lives_ok { $p->message(MESSAGE1) } 'Count 1-10 ( 5)';
- lives_ok { $p->update($_) for 6..10 } 'Count 1-10 ( 6)';
-};
-print $out;
+ ($out, $err) = capture {
+ lives_ok { $p->message($MESSAGE1) } 'Count 1-10 ( 5)';
+ lives_ok { $p->update($_) for 6..10 } 'Count 1-10 ( 6)';
+ };
+ print $out;
+
$err =~ s!^.*\r!!gm;
- print STDERR "ERR (2) :\n$err\nlength: ", length($err), "\n"
+ diag "ERR (2) :\n$err\nlength: " . length($err)
if $ENV{TEST_DEBUG};
@lines = split /\n/, $err;
- like $lines[-1], qr/^@{[NAME2()]}: \s*\d+% \#*$/, 'Count 1-10 ( 8)';
- like $lines[-1], qr/^@{[NAME2()]}: \s*100%/, 'Count 1-10 ( 9)';
+ like $lines[-1], qr/^@{[$NAME2]}: \s*\d+% \#*$/, 'Count 1-10 ( 8)';
+ like $lines[-1], qr/^@{[$NAME2]}: \s*100%/, 'Count 1-10 ( 9)';
}
# -------------------------------------
# (X)Emacs mode: -*- cperl -*-
use strict;
+use warnings;
=head1 Unit Test Package for Term::ProgressBar
=cut
-use Data::Dumper qw( Dumper );
use Test::More tests => 8;
use Test::Exception;
-use constant MESSAGE1 => 'Walking on the Milky Way';
-
-=head2 Test 1: compilation
+use Capture::Tiny qw(capture);
-This test confirms that the test script and the modules it calls compiled
-successfully.
-
-=cut
+my $MESSAGE1 = 'Walking on the Milky Way';
use_ok 'Term::ProgressBar';
(6) Check bar number is 100%
=cut
-use Capture::Tiny qw(capture);
-my ($out, $err) = capture {
- my $p;
- lives_ok { $p = Term::ProgressBar->new('bob', 10); } 'Count 1-10 (1)';
- lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)';
- lives_ok { $p->message(MESSAGE1) } 'Count 1-10 (3)';
- lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)';
-};
-print $out;
+{
+ my ($out, $err) = capture {
+ my $p;
+ lives_ok { $p = Term::ProgressBar->new('bob', 10); } 'Count 1-10 (1)';
+ lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)';
+ lives_ok { $p->message($MESSAGE1) } 'Count 1-10 (3)';
+ lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)';
+ };
+ print $out;
$err =~ s!^.*\r!!gm;
- print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
+ diag "ERR:\n$err\nlength: ", length($err)
if $ENV{TEST_DEBUG};
my @lines = split /\n/, $err;
- is $lines[0], MESSAGE1;
+ is $lines[0], $MESSAGE1;
like $lines[-1], qr/bob:\s+\d+% \#+/, 'Count 1-10 (6)';
like $lines[-1], qr/^bob:\s+100%/, 'Count 1-10 (7)';
+}
# (X)Emacs mode: -*- cperl -*-
use strict;
+use warnings;
=head1 Unit Test Package for Term::ProgressBar
=cut
-use Data::Dumper 2.101 qw( Dumper );
use Test::More tests => 11;
use Test::Exception;
-use constant MESSAGE1 => 'Walking on the Milky Way';
-
use Capture::Tiny qw(capture);
+my $MESSAGE1 = 'Walking on the Milky Way';
=head2 Test 1: compilation
(7) Check bar number is 100%
=cut
-
-my ($out, $err) = capture {
- my $p;
- lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)';
- lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)';
- lives_ok { $p->message(MESSAGE1) } 'Count 1-10 (3)';
- lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)';
-};
-print $out;
+{
+ my ($out, $err) = capture {
+ my $p;
+ lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)';
+ lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)';
+ lives_ok { $p->message($MESSAGE1) } 'Count 1-10 (3)';
+ lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)';
+ };
+ print $out;
$err =~ s!^.*\r!!gm;
- print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
+ diag "ERR:\n$err\nlength: " . length($err)
if $ENV{TEST_DEBUG};
my @lines = split /\n/, $err;
- is $lines[0], MESSAGE1;
+ is $lines[0], $MESSAGE1;
like $lines[-1], qr/\[=+\]/, 'Count 1-10 (5)';
like $lines[-1], qr/^\s*100%/, 'Count 1-10 (6)';
+}
# -------------------------------------
=cut
-($out, $err) = capture {
- my $p;
- lives_ok { $p = Term::ProgressBar->new(100); } 'Message Check ( 1)';
- lives_ok { for (0..100) { $p->update($_); $p->message("Hello") } } 'Message Check ( 2)';
-};
-print $out;
+{
+ my ($out, $err) = capture {
+ my $p;
+ lives_ok { $p = Term::ProgressBar->new(100); } 'Message Check ( 1)';
+ lives_ok { for (0..100) { $p->update($_); $p->message("Hello") } } 'Message Check ( 2)';
+ };
+ print $out;
my @err_lines = split /\n/, $err;
(my $last_line = $err_lines[-1]) =~ tr/\r//d;
is substr($last_line, 0, 4), '100%', 'Message Check ( 3)';
+}
# ----------------------------------------------------------------------------
# (X)Emacs mode: -*- cperl -*-
use strict;
+use warnings;
=head1 Unit Test Package for Term::ProgressBar
=cut
-use Data::Dumper qw( Dumper );
use Test::More tests => 7;
use Test::Exception;
};
print $out;
- $err =~ s!^.*\r!!gm;
- print STDERR "ERR:\n$err\nlength: ", length($err), "\n"
+$err =~ s!^.*\r!!gm;
+diag "ERR:\n$err\nlength: " . length($err)
if $ENV{TEST_DEBUG};
- my @lines = split /\n/, $err;
+my @lines = split /\n/, $err;
- like $lines[-1], qr/\[=+\]/, 'Count 1-20 (5)';
- like $lines[-1], qr/^\s*100%/, 'Count 1-20 (6)';
+like $lines[-1], qr/\[=+\]/, 'Count 1-20 (5)';
+like $lines[-1], qr/^\s*100%/, 'Count 1-20 (6)';
# (X)Emacs mode: -*- cperl -*-
use strict;
+use warnings;
=head1 Unit Test Package for Term::ProgressBar
=cut
-use Data::Dumper qw( Dumper );
use Test::More tests => 31;
use Test::Exception;
=cut
{
- my $p;
-
-my ($out, $err) = capture {
- lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)';
- lives_ok { $p->update($_) for 1..10 } 'Count 1-10 (2)';
-};
-print $out;
- my @lines = grep $_ ne '', split /\r/, $err;
- print Dumper \@lines
+ my ($out, $err) = capture {
+ my $p;
+ lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)';
+ lives_ok { $p->update($_) for 1..10 } 'Count 1-10 (2)';
+ };
+ print $out;
+
+ my @lines = grep {$_ ne ''} split /\r/, $err;
+ diag explain \@lines
if $ENV{TEST_DEBUG};
like $lines[-1], qr/\[=+\]/, 'Count 1-10 (3)';
like $lines[-1], qr/^\s*100%/, 'Count 1-10 (4)';
=cut
{
- my $p;
-
-my ($out, $err) = capture {
- lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-9 (1)';
- lives_ok { $p->update($_) for 1..9 } 'Count 1-9 (2)';
-};
-print $out;
+ my ($out, $err) = capture {
+ my $p;
+ lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-9 (1)';
+ lives_ok { $p->update($_) for 1..9 } 'Count 1-9 (2)';
+ };
+ print $out;
my @lines = grep $_ ne '', split /\r/, $err;
- print Dumper \@lines
+ diag explain \@lines
if $ENV{TEST_DEBUG};
like $lines[-1], qr/\[=+ +\]/, 'Count 1-9 (3)';
like $lines[-1], qr/^\s*90%/, 'Count 1-9 (4)';
=cut
{
-my ($out, $err) = capture {
- my $b = Term::ProgressBar->new(1000000);
- $b->update($_) foreach (0, 1);
-};
-print $out;
- my @lines = grep $_ ne '', split /\r/, $err;
- print Dumper \@lines
+ my ($out, $err) = capture {
+ my $tp = Term::ProgressBar->new(1000000);
+ $tp->update($_) foreach (0, 1);
+ };
+ #print $out;
+
+ my @lines = grep {$_ ne ''} split /\r/, $err;
+ diag explain \@lines
if $ENV{TEST_DEBUG};
is scalar @lines, 1;
}
# (X)Emacs mode: -*- cperl -*-
use strict;
+use warnings;
=head1 Unit Test Package for Term::ProgressBar
=cut
-use Data::Dumper qw( Dumper );
use Test::More tests => 9;
use Test::Exception;
{
my $p;
- my $name;
-my ($out, $err) = capture {
- $name = 'doing nothing';
- lives_ok { $p = Term::ProgressBar->new($name, 0); } 'V1 mode ( 1)';
- lives_ok { $p->update($_) for 1..10 } 'V1 mode ( 2)';
-};
-print $out;
- my @lines = grep $_ ne '', split /\r/, $err;
- print Dumper \@lines
+ my $name = 'doing nothing';
+ my ($out, $err) = capture {
+ lives_ok { $p = Term::ProgressBar->new($name, 0); } 'V1 mode ( 1)';
+ lives_ok { $p->update($_) for 1..10 } 'V1 mode ( 2)';
+ };
+ print $out;
+
+ my @lines = grep { $_ ne ''} split /\r/, $err;
+ diag explain @lines
if $ENV{TEST_DEBUG};
like $lines[-1], qr/^$name:/, 'V1 mode ( 3)';
like $lines[-1], qr/\(nothing to do\)/, 'V1 mode ( 4)';
{
my $p;
my $name = 'zero';
-my ($out, $err) = capture {
- lives_ok { $p = Term::ProgressBar->new({ count => 0, name => $name }); } 'V2 mode ( 1)';
- lives_ok { $p->update($_) for 1..10 } 'V2 mode ( 2)';
-};
-print $out;
- my @lines = grep $_ ne '', split /\r/, $err;
- print Dumper \@lines
+ my ($out, $err) = capture {
+ lives_ok { $p = Term::ProgressBar->new({ count => 0, name => $name }); } 'V2 mode ( 1)';
+ lives_ok { $p->update($_) for 1..10 } 'V2 mode ( 2)';
+ };
+ print $out;
+
+ my @lines = grep {$_ ne ''} split /\r/, $err;
+ diag explain @lines
if $ENV{TEST_DEBUG};
- like $lines[-1], qr/^$name:/, 'V2 mode ( 3)';
- like $lines[-1], qr/\(nothing to do\)/, 'V2 mode ( 4)';
+ like $lines[-1], qr/^$name:/, 'V2 mode ( 3)';
+ like $lines[-1], qr/\(nothing to do\)/, 'V2 mode ( 4)';
}
# ----------------------------------------------------------------------------