]> git.donarmstrong.com Git - term-progressbar.git/commitdiff
switch to useint Test::Exception instead of the home made code, remote test.pm
authorGabor Szabo <gabor@szabgab.com>
Tue, 29 Nov 2011 21:24:51 +0000 (23:24 +0200)
committerGabor Szabo <gabor@szabgab.com>
Tue, 29 Nov 2011 21:24:51 +0000 (23:24 +0200)
t/eta-linear.t
t/name.t
t/test.pm [deleted file]
t/v1-message.t
t/v2-message.t
t/v2-mobile.t
t/v2-simple.t
t/zero.t

index ea8410d27c8b3e85212e28b9ee2721dbf98b5343..8c07d2dd98a9e96e32fe2eaa2d0c1234621e41b3 100644 (file)
@@ -9,11 +9,8 @@ This package tests the basic functionality of Term::ProgressBar.
 =cut
 
 use Data::Dumper  qw( Dumper );
 =cut
 
 use Data::Dumper  qw( Dumper );
-use FindBin       qw( $Bin );
 use Test::More tests => 9;
 use Test::More tests => 9;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
 
 =head2 Test 1: compilation
 
 
 =head2 Test 1: compilation
 
@@ -49,20 +46,14 @@ use Capture::Tiny qw(capture);
 
 my ($out, $err) = capture {
   my $p;
 
 my ($out, $err) = capture {
   my $p;
-  ok (evcheck(sub {
+  lives_ok {
                 $p = Term::ProgressBar->new({count => 10, name => 'fred',
                                              ETA => 'linear'});
                 $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;
 };
 print $out;
   my @lines = grep $_ ne '', split /[\n\r]+/, $err;
index 565779fcd8c3f06f742467766d69b4f2317e97aa..ff4dfbfe31c6223bc4988cd2b75c1a788e4812fb 100644 (file)
--- 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 );
 =cut
 
 use Data::Dumper  qw( Dumper );
-use FindBin       qw( $Bin );
 use Test::More tests => 18;
 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';
 
 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 {
 {
   my $p;
 my ($out, $err) = capture {
-  ok (evcheck(sub {
+  lives_ok {
                 $p = Term::ProgressBar->new({count => 10, name => NAME1});
                 $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;
 
 };
 print $out;
 
@@ -81,10 +76,8 @@ print $out;
 
 ($out, $err) = capture {
 
 
 ($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;
 
 };
 print $out;
 
@@ -122,11 +115,8 @@ Use v1 mode
 {
   my $p;
 my ($out, $err) = capture {
 {
   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;
 
 };
 print $out;
 
@@ -146,10 +136,8 @@ print $out;
   ok $ok;
   
 ($out, $err) = capture {
   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;
 };
 print $out;
   $err =~ s!^.*\r!!gm;
diff --git a/t/test.pm b/t/test.pm
deleted file mode 100644 (file)
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<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__
index 0b43108094d8f0fca03969025bcf91beb65525ec..95ca985c6c06ea35e720d268c934e7104f272f3d 100644 (file)
@@ -9,11 +9,8 @@ This package tests the basic functionality of Term::ProgressBar.
 =cut
 
 use Data::Dumper qw( Dumper );
 =cut
 
 use Data::Dumper qw( Dumper );
-use FindBin      qw( $Bin );
 use Test::More tests => 8;
 use Test::More tests => 8;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
 
 use constant MESSAGE1 => 'Walking on the Milky Way';
 
 
 use constant MESSAGE1 => 'Walking on the Milky Way';
 
@@ -49,15 +46,10 @@ use Capture::Tiny qw(capture);
 
 my ($out, $err) = capture {
   my $p;
 
 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;
 
 };
 print $out;
 
index c4036e3f9544a08dd5b0d43ab336d6bba6aa2bb9..6b687344f7edb18f6045ab6ccd1bbcdf60ac93fb 100644 (file)
@@ -9,11 +9,8 @@ This package tests the basic functionality of Term::ProgressBar.
 =cut
 
 use Data::Dumper 2.101 qw( Dumper );
 =cut
 
 use Data::Dumper 2.101 qw( Dumper );
-use FindBin 1.42 qw( $Bin );
 use Test::More tests => 11;
 use Test::More tests => 11;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
 
 use constant MESSAGE1 => 'Walking on the Milky Way';
 
 
 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;
 
 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;
 
 };
 print $out;
 
@@ -86,11 +79,8 @@ This is to check that message preserves the progress bar value correctly.
 
 ($out, $err) = capture {
   my $p;
 
 ($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;
 
 };
 print $out;
 
index 5021f2d6f3a4cd20e218a3d3f8f933fd6f5dc62b..5176a52b8cfec437274dcd3f6ffec49793c36130 100644 (file)
@@ -9,11 +9,8 @@ This package tests the moving target functionality of Term::ProgressBar.
 =cut
 
 use Data::Dumper qw( Dumper );
 =cut
 
 use Data::Dumper qw( Dumper );
-use FindBin      qw( $Bin );
 use Test::More tests => 7;
 use Test::More tests => 7;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
 
 use Capture::Tiny qw(capture);
 
 
 use Capture::Tiny qw(capture);
 
@@ -41,14 +38,10 @@ Update it from 11 to 20.
 
 my ($out, $err) = capture {
   my $p;
 
 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;
 
 };
 print $out;
 
index 3bb54f784c4ee4c3b86b97f8724c74d79146cc9f..4816ab989ad012fad2015a1053989572f93cf676 100644 (file)
@@ -9,11 +9,8 @@ This package tests the basic functionality of Term::ProgressBar.
 =cut
 
 use Data::Dumper qw( Dumper );
 =cut
 
 use Data::Dumper qw( Dumper );
-use FindBin      qw( $Bin );
 use Test::More tests => 31;
 use Test::More tests => 31;
-
-use lib $Bin;
-use test qw( evcheck );
+use Test::Exception;
 
 use Capture::Tiny qw(capture);
 
 
 use Capture::Tiny qw(capture);
 
@@ -39,10 +36,8 @@ Update it it from 1 to 10.
   my $p;
 
 my ($out, $err) = 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;
 };
 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 {
   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;
 
 };
 print $out;
 
index 8e6426b978648577ad1c0bb62ff62ee895a211bf..ffabda91e980f4a98ac924043c7f8a73799a81d0 100644 (file)
--- 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 );
 =cut
 
 use Data::Dumper qw( Dumper );
-use FindBin      qw( $Bin );
 use Test::More tests => 9;
 use Test::More tests => 9;
+use Test::Exception;
 
 use Capture::Tiny qw(capture);
 
 
 use Capture::Tiny qw(capture);
 
-use lib $Bin;
-use test qw( evcheck );
-
 use_ok 'Term::ProgressBar';
 
 Term::ProgressBar->__force_term (50);
 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';
   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;
 };
 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 {
   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;
 };
 print $out;
   my @lines = grep $_ ne '', split /\r/, $err;