From: Gabor Szabo Date: Tue, 29 Nov 2011 21:24:51 +0000 (+0200) Subject: switch to useint Test::Exception instead of the home made code, remote test.pm X-Git-Url: https://git.donarmstrong.com/?p=term-progressbar.git;a=commitdiff_plain;h=14647cabb5bbb54629de8545e080519bd0be430f switch to useint Test::Exception instead of the home made code, remote test.pm --- diff --git a/t/eta-linear.t b/t/eta-linear.t index ea8410d..8c07d2d 100644 --- a/t/eta-linear.t +++ b/t/eta-linear.t @@ -9,11 +9,8 @@ This package tests the basic functionality of Term::ProgressBar. =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 @@ -49,20 +46,14 @@ use Capture::Tiny qw(capture); 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; diff --git a/t/name.t b/t/name.t index 565779f..ff4dfbf 100644 --- a/t/name.t +++ b/t/name.t @@ -9,11 +9,8 @@ This package tests the name functionality of Term::ProgressBar. =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'; @@ -55,12 +52,10 @@ use Capture::Tiny qw(capture); { 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; @@ -81,10 +76,8 @@ 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; @@ -122,11 +115,8 @@ Use v1 mode { 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; @@ -146,10 +136,8 @@ 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; diff --git a/t/test.pm b/t/test.pm deleted file mode 100644 index f72ae08..0000000 --- a/t/test.pm +++ /dev/null @@ -1,174 +0,0 @@ -# (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. - -This package does not including running external programs; that is provided by -C. This is so that suites not needing that can include only -test.pm, and so not require the presence of C. - -Setting up the environment includes: - -=over 4 - -=item Prepending F onto the path - -=item Pushing the module F dir onto the @INC var - -For internal C 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 - -=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__ diff --git a/t/v1-message.t b/t/v1-message.t index 0b43108..95ca985 100644 --- a/t/v1-message.t +++ b/t/v1-message.t @@ -9,11 +9,8 @@ This package tests the basic functionality of Term::ProgressBar. =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'; @@ -49,15 +46,10 @@ use Capture::Tiny qw(capture); 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; diff --git a/t/v2-message.t b/t/v2-message.t index c4036e3..6b68734 100644 --- a/t/v2-message.t +++ b/t/v2-message.t @@ -9,11 +9,8 @@ This package tests the basic functionality of Term::ProgressBar. =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'; @@ -50,14 +47,10 @@ Update it it from 1 to 10. Output a message halfway through. 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; @@ -86,11 +79,8 @@ This is to check that message preserves the progress bar value correctly. ($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; diff --git a/t/v2-mobile.t b/t/v2-mobile.t index 5021f2d..5176a52 100644 --- a/t/v2-mobile.t +++ b/t/v2-mobile.t @@ -9,11 +9,8 @@ This package tests the moving target functionality of Term::ProgressBar. =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); @@ -41,14 +38,10 @@ Update it from 11 to 20. 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; diff --git a/t/v2-simple.t b/t/v2-simple.t index 3bb54f7..4816ab9 100644 --- a/t/v2-simple.t +++ b/t/v2-simple.t @@ -9,11 +9,8 @@ This package tests the basic functionality of Term::ProgressBar. =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); @@ -39,10 +36,8 @@ Update it it from 1 to 10. 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; @@ -72,10 +67,8 @@ Update it it from 1 to 9. 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; diff --git a/t/zero.t b/t/zero.t index 8e6426b..ffabda9 100644 --- a/t/zero.t +++ b/t/zero.t @@ -9,14 +9,11 @@ This package tests the zero-progress handling of progress bar. =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); @@ -40,11 +37,8 @@ Update it it from 1 to 10. 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; @@ -72,12 +66,8 @@ Update it it from 1 to 10. 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;