]> git.donarmstrong.com Git - term-progressbar.git/blobdiff - t/name.t
switch from Test to Test::More
[term-progressbar.git] / t / name.t
index 9b6857676c7ce0d7bad7ab1093361d60675a3f6f..565779fcd8c3f06f742467766d69b4f2317e97aa 100644 (file)
--- a/t/name.t
+++ b/t/name.t
@@ -10,21 +10,15 @@ This package tests the name functionality of Term::ProgressBar.
 
 use Data::Dumper  qw( Dumper );
 use FindBin       qw( $Bin );
-use Test          qw( ok plan );
+use Test::More tests => 18;
 
 use lib $Bin;
-use test qw( DATA_DIR
-             evcheck restore_output save_output );
+use test qw( evcheck );
 
 use constant MESSAGE1 => 'The Gospel of St. Jude';
 use constant NAME1    => 'Algenon';
 use constant NAME2    => 'Smegma';
 
-BEGIN {
-  # 1 for compilation test,
-  plan tests  => 18,
-       todo   => [],
-}
 
 =head2 Test 1: compilation
 
@@ -33,9 +27,7 @@ successfully.
 
 =cut
 
-use Term::ProgressBar;
-
-ok 1, 1, 'compilation';
+use_ok 'Term::ProgressBar';
 
 Term::ProgressBar->__force_term (50);
 
@@ -58,23 +50,26 @@ Update it it from 1 to 10.
 
 =cut
 
+use Capture::Tiny qw(capture);
+
 {
   my $p;
-  save_output('stderr', *STDERR{IO});
+my ($out, $err) = capture {
   ok (evcheck(sub {
                 $p = Term::ProgressBar->new({count => 10, name => NAME1});
               },                                            'Count 1-10 ( 1)'),
-      1,                                                    'Count 1-10 ( 1)');
+                                                          'Count 1-10 ( 1)');
   ok (evcheck(sub { $p->update($_) for 1..3  },             'Count 1-10 ( 2)'),
-      1,                                                    'Count 1-10 ( 2)');
-
-  my $err = restore_output('stderr');
+                                                          'Count 1-10 ( 2)');
+};
+print $out;
 
   $err =~ s!^.*\r!!gm;
   print STDERR "ERR (1) :\n$err\nlength: ", length($err), "\n"
     if $ENV{TEST_DEBUG};
   my @lines = split /\n/, $err;
-  ok $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
@@ -84,13 +79,14 @@ Update it it from 1 to 10.
   my $ok = length($bar) > $barexpect -1 && length($bar) < $barexpect+1;
   ok $ok;
 
-  save_output('stderr', *STDERR{IO});
+($out, $err) = capture {
 
   ok (evcheck(sub { $p->message(MESSAGE1)    },             'Count 1-10 ( 5)'),
-      1,                                                    'Count 1-10 ( 5)');
+                                                          'Count 1-10 ( 5)');
   ok (evcheck(sub { $p->update($_) for 6..10 },             'Count 1-10 ( 6)'),
-      1,                                                    'Count 1-10 ( 6)');
-  $err = restore_output('stderr');
+                                                          'Count 1-10 ( 6)');
+};
+print $out;
 
   $err =~ s!^.*\r!!gm;
   print STDERR "ERR (2) :\n$err\nlength: ", length($err), "\n"
@@ -98,9 +94,9 @@ Update it it from 1 to 10.
 
   @lines = split /\n/, $err;
 
-  ok $lines[0], MESSAGE1,                                    'Count 1-10 ( 7)';
-  ok $lines[-1], qr/\[=+\]/,                                 'Count 1-10 ( 8)';
-  ok $lines[-1], qr/^@{[NAME1()]}: \s*100%/,                 'Count 1-10 ( 9)';
+  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)';
 }
 
 # -------------------------------------
@@ -125,20 +121,21 @@ Use v1 mode
 
 {
   my $p;
-  save_output('stderr', *STDERR{IO});
+my ($out, $err) = capture {
   ok (evcheck(sub { $p = Term::ProgressBar->new(NAME2, 10); }, 
                                                             'Count 1-10 ( 1)'),
-      1,                                                    'Count 1-10 ( 1)');
+                                                          'Count 1-10 ( 1)');
   ok (evcheck(sub { $p->update($_) for 1..3  },             'Count 1-10 ( 2)'),
-      1,                                                    'Count 1-10 ( 2)');
-
-  my $err = restore_output('stderr');
+                                                          'Count 1-10 ( 2)');
+};
+print $out;
 
   $err =~ s!^.*\r!!gm;
   print STDERR "ERR (1) :\n$err\nlength: ", length($err), "\n"
     if $ENV{TEST_DEBUG};
   my @lines = split /\n/, $err;
-  ok $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
@@ -147,23 +144,22 @@ Use v1 mode
   my $barexpect = $length * 0.3;
   my $ok = length($bar) > $barexpect -1 && length($bar) < $barexpect+1;
   ok $ok;
-
-  save_output('stderr', *STDERR{IO});
-
+  
+($out, $err) = capture {
   ok (evcheck(sub { $p->message(MESSAGE1)    },             'Count 1-10 ( 5)'),
-      1,                                                    'Count 1-10 ( 5)');
+                                                          'Count 1-10 ( 5)');
   ok (evcheck(sub { $p->update($_) for 6..10 },             'Count 1-10 ( 6)'),
-      1,                                                    'Count 1-10 ( 6)');
-  $err = restore_output('stderr');
-
+                                                          'Count 1-10 ( 6)');
+};
+print $out;
   $err =~ s!^.*\r!!gm;
   print STDERR "ERR (2) :\n$err\nlength: ", length($err), "\n"
     if $ENV{TEST_DEBUG};
 
   @lines = split /\n/, $err;
 
-  ok $lines[-1], qr/^@{[NAME2()]}: \s*\d+% \#*$/,            'Count 1-10 ( 8)';
-  ok $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)';
 }
 
 # -------------------------------------