]> git.donarmstrong.com Git - term-progressbar.git/commitdiff
cleanup of the test code
authorGabor Szabo <gabor@szabgab.com>
Wed, 30 Nov 2011 06:22:41 +0000 (08:22 +0200)
committerGabor Szabo <gabor@szabgab.com>
Wed, 30 Nov 2011 06:22:41 +0000 (08:22 +0200)
t/compat.t
t/eta-linear.t
t/name.t
t/v1-message.t
t/v2-message.t
t/v2-mobile.t
t/v2-simple.t
t/zero.t

index 8f71b1891d66dc3ef0cb7bf2615e7315920e768e..da8c7d7608085a326672727c3ec3234cb411b0a8 100644 (file)
@@ -12,7 +12,6 @@ and is intended to test compatibility with that version.
 
 # Utility -----------------------------
 
-use Data::Dumper qw( );
 use Test::More tests => 9;
 
 use Term::ProgressBar;
index 8c07d2dd98a9e96e32fe2eaa2d0c1234621e41b3..3d4f06b3c2bcc89e9330995d9d993a96ac7692ef 100644 (file)
@@ -1,6 +1,7 @@
 # (X)Emacs mode: -*- cperl -*-
 
 use strict;
+use warnings;
 
 =head1 Unit Test Package for Term::ProgressBar
 
@@ -8,16 +9,10 @@ This package tests the basic functionality of 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;
 
@@ -42,28 +37,28 @@ Update it it from 1 to 10.
 
 =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)';
+}
 
 # ----------------------------------------------------------------------------
index ff4dfbfe31c6223bc4988cd2b75c1a788e4812fb..e89f4862eb518dbe026022b53052a8f9f79d76f9 100644 (file)
--- a/t/name.t
+++ b/t/name.t
@@ -1,6 +1,7 @@
 # (X)Emacs mode: -*- cperl -*-
 
 use strict;
+use warnings;
 
 =head1 Unit Test Package for Term::ProgressBar
 
@@ -8,21 +9,14 @@ This package tests the name functionality of 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';
 
@@ -47,49 +41,47 @@ Update it it from 1 to 10.
 
 =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)';
 }
 
 # -------------------------------------
@@ -114,40 +106,41 @@ Use v1 mode
 
 {
   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)';
 }
 
 # -------------------------------------
index 95ca985c6c06ea35e720d268c934e7104f272f3d..3428ff808f2ddff6ea1aeeed2ee7830027f28c9e 100644 (file)
@@ -1,6 +1,7 @@
 # (X)Emacs mode: -*- cperl -*-
 
 use strict;
+use warnings;
 
 =head1 Unit Test Package for Term::ProgressBar
 
@@ -8,18 +9,12 @@ This package tests the basic functionality of 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';
 
@@ -42,23 +37,24 @@ Update it it from 1 to 10.
 (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)';
+}
index 6b687344f7edb18f6045ab6ccd1bbcdf60ac93fb..10430b3a9ffc83fee7f4c280d6937104a024ea90 100644 (file)
@@ -1,6 +1,7 @@
 # (X)Emacs mode: -*- cperl -*-
 
 use strict;
+use warnings;
 
 =head1 Unit Test Package for Term::ProgressBar
 
@@ -8,14 +9,12 @@ This package tests the basic functionality of 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
 
@@ -44,25 +43,26 @@ Update it it from 1 to 10.  Output a message halfway through.
 (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)';
+}
 
 # -------------------------------------
 
@@ -77,15 +77,17 @@ This is to check that message preserves the progress bar value correctly.
 
 =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)';
+}
 
 # ----------------------------------------------------------------------------
index 5176a52b8cfec437274dcd3f6ffec49793c36130..dd42ea3f0d52b476d890ecbde1873b35d37fe274 100644 (file)
@@ -1,6 +1,7 @@
 # (X)Emacs mode: -*- cperl -*-
 
 use strict;
+use warnings;
 
 =head1 Unit Test Package for Term::ProgressBar
 
@@ -8,7 +9,6 @@ This package tests the moving target functionality of Term::ProgressBar.
 
 =cut
 
-use Data::Dumper qw( Dumper );
 use Test::More tests => 7;
 use Test::Exception;
 
@@ -45,11 +45,11 @@ my ($out, $err) = capture {
 };
 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)';
index 4816ab989ad012fad2015a1053989572f93cf676..439594f3534773f495369e4c594ca03593b21a14 100644 (file)
@@ -1,6 +1,7 @@
 # (X)Emacs mode: -*- cperl -*-
 
 use strict;
+use warnings;
 
 =head1 Unit Test Package for Term::ProgressBar
 
@@ -8,7 +9,6 @@ This package tests the basic functionality of Term::ProgressBar.
 
 =cut
 
-use Data::Dumper qw( Dumper );
 use Test::More tests => 31;
 use Test::Exception;
 
@@ -33,15 +33,15 @@ Update it it from 1 to 10.
 
 =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)';
@@ -64,16 +64,15 @@ Update it it from 1 to 9.
 =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)';
@@ -90,13 +89,14 @@ percentage or displayed bar).
 
 =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;
 }
index ffabda91e980f4a98ac924043c7f8a73799a81d0..fda3d35ae5f33ab040f309bcbddfe4413f8b21f4 100644 (file)
--- a/t/zero.t
+++ b/t/zero.t
@@ -1,6 +1,7 @@
 # (X)Emacs mode: -*- cperl -*-
 
 use strict;
+use warnings;
 
 =head1 Unit Test Package for Term::ProgressBar
 
@@ -8,7 +9,6 @@ This package tests the zero-progress handling of progress bar.
 
 =cut
 
-use Data::Dumper qw( Dumper );
 use Test::More tests => 9;
 use Test::Exception;
 
@@ -34,15 +34,15 @@ Update it it from 1 to 10.
 
 {
   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)';
@@ -65,16 +65,17 @@ Update it it from 1 to 10.
 {
   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)';
 }
 
 # ----------------------------------------------------------------------------