=cut
use Data::Dumper qw( Dumper );
-use FindBin qw( $Bin );
use Test::More tests => 9;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
=head2 Test 1: compilation
my ($out, $err) = capture {
my $p;
- ok (evcheck(sub {
+ lives_ok {
$p = Term::ProgressBar->new({count => 10, name => 'fred',
ETA => 'linear'});
- }, 'Count 1-10 (1)' ),
- 'Count 1-10 (1)');
- ok (evcheck(sub { for (1..5) { $p->update($_); sleep 1 } },
- 'Count 1-10 (2)' ),
- 'Count 1-10 (2)');
- ok (evcheck(sub { $p->message('Hello Mum!') },
- 'Count 1-10 (3)' ),
- 'Count 1-10 (3)');
- ok (evcheck(sub { for (6..10) { $p->update($_); sleep 1 } },
- 'Count 1-10 (4)' ),
- 'Count 1-10 (4)');
+ } 'Count 1-10 (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;
my @lines = grep $_ ne '', split /[\n\r]+/, $err;
=cut
use Data::Dumper qw( Dumper );
-use FindBin qw( $Bin );
use Test::More tests => 18;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
use constant MESSAGE1 => 'The Gospel of St. Jude';
use constant NAME1 => 'Algenon';
{
my $p;
my ($out, $err) = capture {
- ok (evcheck(sub {
+ lives_ok {
$p = Term::ProgressBar->new({count => 10, name => NAME1});
- }, 'Count 1-10 ( 1)'),
- 'Count 1-10 ( 1)');
- ok (evcheck(sub { $p->update($_) for 1..3 }, 'Count 1-10 ( 2)'),
- 'Count 1-10 ( 2)');
+ } 'Count 1-10 ( 1)';
+ lives_ok { $p->update($_) for 1..3 } 'Count 1-10 ( 2)';
};
print $out;
($out, $err) = capture {
- ok (evcheck(sub { $p->message(MESSAGE1) }, 'Count 1-10 ( 5)'),
- 'Count 1-10 ( 5)');
- ok (evcheck(sub { $p->update($_) for 6..10 }, 'Count 1-10 ( 6)'),
- 'Count 1-10 ( 6)');
+ lives_ok { $p->message(MESSAGE1) } 'Count 1-10 ( 5)';
+ lives_ok { $p->update($_) for 6..10 } 'Count 1-10 ( 6)';
};
print $out;
{
my $p;
my ($out, $err) = capture {
- ok (evcheck(sub { $p = Term::ProgressBar->new(NAME2, 10); },
- 'Count 1-10 ( 1)'),
- 'Count 1-10 ( 1)');
- ok (evcheck(sub { $p->update($_) for 1..3 }, 'Count 1-10 ( 2)'),
- 'Count 1-10 ( 2)');
+ 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;
ok $ok;
($out, $err) = capture {
- ok (evcheck(sub { $p->message(MESSAGE1) }, 'Count 1-10 ( 5)'),
- 'Count 1-10 ( 5)');
- ok (evcheck(sub { $p->update($_) for 6..10 }, 'Count 1-10 ( 6)'),
- 'Count 1-10 ( 6)');
+ 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;
+++ /dev/null
-# (X)Emacs mode: -*- cperl -*-
-
-package test;
-
-=head1 NAME
-
-test - tools for helping in test suites (not including running externalprograms).
-
-=head1 SYNOPSIS
-
- ok evcheck(sub {
- open my $fh, '>', 'foo';
- print $fh "$_\n"
- for 'Bulgaria', 'Cholet';
- close $fh;
- }, 'write foo'), 1, 'write foo';
-
-=head1 DESCRIPTION
-
-This package provides some variables, and sets up an environment, for test
-scripts, such as those used in F<t/>.
-
-This package does not including running external programs; that is provided by
-C<test2.pm>. This is so that suites not needing that can include only
-test.pm, and so not require the presence of C<IPC::Run>.
-
-Setting up the environment includes:
-
-=over 4
-
-=item Prepending F<blib/script> onto the path
-
-=item Pushing the module F<lib/> dir onto the @INC var
-
-For internal C<use> calls.
-
-=item Changing directory to a temporary directory
-
-To avoid cluttering the local dir, and/or allowing the local directory
-structure to affect matters.
-
-=item Cleaning up the temporary directory afterwards
-
-Unless TEST_DEBUG is set in the environment.
-
-=back
-
-=cut
-
-# ----------------------------------------------------------------------------
-
-# Pragmas -----------------------------
-
-use 5.00503;
-use strict;
-use vars qw( @EXPORT_OK );
-
-# Inheritance -------------------------
-
-use base qw( Exporter );
-
-=head2 EXPORTS
-
-The following symbols are exported upon request:
-
-=over 4
-
-=item evcheck
-
-=back
-
-=cut
-
-@EXPORT_OK = qw( evcheck );
-
-# Utility -----------------------------
-
-use Carp qw( carp );
-
-
-$| = 1;
-
-# -------------------------------------
-# PACKAGE FUNCTIONS
-# -------------------------------------
-
-=head2 evcheck
-
-Eval code, return status
-
-=over 4
-
-=item ARGUMENTS
-
-=over 4
-
-=item code
-
-Coderef to eval
-
-=item name
-
-Name to use in error messages
-
-=back
-
-=item RETURNS
-
-=over 4
-
-=item okay
-
-1 if eval was okay, 0 if not.
-
-=back
-
-=back
-
-=cut
-
-sub evcheck {
- my ($code, $name) = @_;
-
- my $ok = 0;
-
- eval {
- &$code;
- $ok = 1;
- }; if ( $@ ) {
- carp "Code $name failed: $@\n"
- if $ENV{TEST_DEBUG};
- $ok = 0;
- }
-
- return $ok;
-}
-
-# -------------------------------------
-
-# defined further up to use in constants
-
-# ----------------------------------------------------------------------------
-
-=head1 EXAMPLES
-
-Z<>
-
-=head1 BUGS
-
-Z<>
-
-=head1 REPORTING BUGS
-
-Email the author.
-
-=head1 AUTHOR
-
-Martyn J. Pearce C<fluffy@cpan.org>
-
-=head1 COPYRIGHT
-
-Copyright (c) 2001, 2002, 2004 Martyn J. Pearce. This program is free
-software; you can redistribute it and/or modify it under the same terms as
-Perl itself.
-
-=head1 SEE ALSO
-
-Z<>
-
-=cut
-
-1; # keep require happy.
-
-__END__
=cut
use Data::Dumper qw( Dumper );
-use FindBin qw( $Bin );
use Test::More tests => 8;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
use constant MESSAGE1 => 'Walking on the Milky Way';
my ($out, $err) = capture {
my $p;
- ok (evcheck(sub { $p = Term::ProgressBar->new('bob', 10); },
- 'Count 1-10 (1)' ),
- 'Count 1-10 (1)');
- ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-10 (2)' ),
- 'Count 1-10 (2)');
- ok (evcheck(sub { $p->message(MESSAGE1) }, 'Count 1-10 (3)' ),
- 'Count 1-10 (3)');
- ok (evcheck(sub { $p->update($_) for 6..10 }, 'Count 1-10 (4)' ),
- 'Count 1-10 (4)');
+ 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;
=cut
use Data::Dumper 2.101 qw( Dumper );
-use FindBin 1.42 qw( $Bin );
use Test::More tests => 11;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
use constant MESSAGE1 => 'Walking on the Milky Way';
my ($out, $err) = capture {
my $p;
- ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-10 (1)' ),
- 'Count 1-10 (1)');
- ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-10 (2)' ),
- 'Count 1-10 (2)');
- ok (evcheck(sub { $p->message(MESSAGE1) }, 'Count 1-10 (3)' ),
- 'Count 1-10 (3)');
- ok (evcheck(sub { $p->update($_) for 6..10 }, 'Count 1-10 (4)' ),
- 'Count 1-10 (4)');
+ 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;
($out, $err) = capture {
my $p;
- ok (evcheck(sub { $p = Term::ProgressBar->new(100); }, 'Message Check ( 1)'),
- 'Message Check ( 1)');
- ok (evcheck(sub { for (0..100) { $p->update($_); $p->message("Hello") } },
- 'Message Check ( 2)',),
- 'Message Check ( 2)');
+ 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;
=cut
use Data::Dumper qw( Dumper );
-use FindBin qw( $Bin );
use Test::More tests => 7;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
use Capture::Tiny qw(capture);
my ($out, $err) = capture {
my $p;
- ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-20 (1)' ),
- 'Count 1-20 (1)');
- ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-20 (2)' ),
- 'Count 1-20 (2)');
- ok (evcheck(sub { $p->target(20) }, 'Count 1-20 (3)' ),
- 'Count 1-20 (3)');
- ok (evcheck(sub { $p->update($_) for 11..20 }, 'Count 1-20 (4)' ),
- 'Count 1-20 (4)');
+ lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-20 (1)';
+ lives_ok { $p->update($_) for 1..5 } 'Count 1-20 (2)';
+ lives_ok { $p->target(20) } 'Count 1-20 (3)';
+ lives_ok { $p->update($_) for 11..20 } 'Count 1-20 (4)';
};
print $out;
=cut
use Data::Dumper qw( Dumper );
-use FindBin qw( $Bin );
use Test::More tests => 31;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
use Capture::Tiny qw(capture);
my $p;
my ($out, $err) = capture {
- ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-10 (1)' ),
- 'Count 1-10 (1)');
- ok (evcheck(sub { $p->update($_) for 1..10 }, 'Count 1-10 (2)' ),
- 'Count 1-10 (2)');
+ 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;
my $p;
my ($out, $err) = capture {
- ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-9 (1)' ),
- 'Count 1-9 (1)');
- ok (evcheck(sub { $p->update($_) for 1..9 }, 'Count 1-9 (2)' ),
- 'Count 1-9 (2)');
+ lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-9 (1)';
+ lives_ok { $p->update($_) for 1..9 } 'Count 1-9 (2)';
};
print $out;
=cut
use Data::Dumper qw( Dumper );
-use FindBin qw( $Bin );
use Test::More tests => 9;
+use Test::Exception;
use Capture::Tiny qw(capture);
-use lib $Bin;
-use test qw( evcheck );
-
use_ok 'Term::ProgressBar';
Term::ProgressBar->__force_term (50);
my $name;
my ($out, $err) = capture {
$name = 'doing nothing';
- ok (evcheck(sub { $p = Term::ProgressBar->new($name, 0); },
- 'V1 mode ( 1)' ),
- 'V1 mode ( 1)');
- ok (evcheck(sub { $p->update($_) for 1..10 },'V1 mode ( 2)'),
- 'V1 mode ( 2)');
+ 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;
my $p;
my $name = 'zero';
my ($out, $err) = capture {
- ok (evcheck(sub { $p = Term::ProgressBar->new({ count => 0,
- name => $name }); },
- 'V2 mode ( 1)' ),
- 'V2 mode ( 1)');
- ok (evcheck(sub { $p->update($_) for 1..10 },'V2 mode ( 2)'),
- 'V2 mode ( 2)');
+ 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;