From: Gabor Szabo Date: Tue, 29 Nov 2011 20:32:38 +0000 (+0200) Subject: switch from Test to Test::More X-Git-Url: https://git.donarmstrong.com/?p=term-progressbar.git;a=commitdiff_plain;h=8f87af0520c5dbcedbfe74dd6ef6e7826f200263 switch from Test to Test::More --- diff --git a/t/compat.t b/t/compat.t index daba215..3698e57 100644 --- a/t/compat.t +++ b/t/compat.t @@ -12,15 +12,7 @@ and is intended to test compatibility with that version. # Utility ----------------------------- use Data::Dumper qw( ); -use Test qw( ok plan ); - -# Test Setup -------------------------- - -BEGIN { - plan tests => 5, - todo => [], - ; -} +use Test::More tests => 4; # ------------------------------------- @@ -68,23 +60,9 @@ sub grab_output($) { return [ $o, $e ]; } -# Change 1..1 below to 1..last_test_to_print . -# (It may become useful if the test is moved to ./t subdirectory.) - use Term::ProgressBar; use POSIX qw; -=head2 Test 1: compilation - -This test confirms that the test script and the modules it calls compiled -successfully. - -=cut - -ok 1, 1, 'compilation'; - -# ------------------------------------- - $| = 1; my $count = 100; @@ -99,7 +77,7 @@ if (not $b or $o->[0] ne '' or $o->[1] ne "$test_str: ") { if $ENV{TEST_DEBUG}; print 'not '; } -print "ok 2\n"; +ok 1; # Test 3: do half the stuff and check half the bar has printed my $halfway = floor($count / 2); @@ -111,7 +89,7 @@ if ($o->[0] ne '' if $ENV{TEST_DEBUG}; print 'not '; } -print "ok 3\n"; +ok 1; # Test 4: do the rest of the stuff and check the whole bar has printed $o = grab_output("update \$b foreach ($halfway .. $count - 1)"); @@ -122,7 +100,7 @@ if ($o->[0] ne '' if $ENV{TEST_DEBUG}; print 'not '; } -print "ok 4\n"; +ok 1; # Test 5: try to do another item and check there is an error eval { update $b }; @@ -134,4 +112,4 @@ unless ( defined($@) if $ENV{TEST_DEBUG}; print 'not '; } -print "ok 5\n"; +ok 1; diff --git a/t/eta-linear.t b/t/eta-linear.t index 0de0594..ea8410d 100644 --- a/t/eta-linear.t +++ b/t/eta-linear.t @@ -10,17 +10,11 @@ This package tests the basic functionality of Term::ProgressBar. use Data::Dumper qw( Dumper ); use FindBin qw( $Bin ); -use Test qw( ok plan ); +use Test::More tests => 9; use lib $Bin; use test qw( evcheck ); -BEGIN { - # 1 for compilation test, - plan tests => 10, - todo => [], -} - =head2 Test 1: compilation This test confirms that the test script and the modules it calls compiled @@ -30,8 +24,6 @@ successfully. use Term::ProgressBar; -ok 1, 1, 'compilation'; - Term::ProgressBar->__force_term (50); # ------------------------------------- @@ -61,26 +53,26 @@ my ($out, $err) = capture { $p = Term::ProgressBar->new({count => 10, name => 'fred', ETA => 'linear'}); }, 'Count 1-10 (1)' ), - 1, 'Count 1-10 (1)'); + 'Count 1-10 (1)'); ok (evcheck(sub { for (1..5) { $p->update($_); sleep 1 } }, 'Count 1-10 (2)' ), - 1, 'Count 1-10 (2)'); + 'Count 1-10 (2)'); ok (evcheck(sub { $p->message('Hello Mum!') }, 'Count 1-10 (3)' ), - 1, 'Count 1-10 (3)'); + 'Count 1-10 (3)'); ok (evcheck(sub { for (6..10) { $p->update($_); sleep 1 } }, 'Count 1-10 (4)' ), - 1, 'Count 1-10 (4)'); + 'Count 1-10 (4)'); }; print $out; my @lines = grep $_ ne '', split /[\n\r]+/, $err; print Dumper \@lines if $ENV{TEST_DEBUG}; ok grep $_ eq 'Hello Mum!', @lines; - ok $lines[-1], qr/\[=+\]/, 'Count 1-10 (6)'; - ok $lines[-1], qr/^fred: \s*100%/, 'Count 1-10 (7)'; - ok $lines[-1], qr/D[ \d]\dh\d{2}m\d{2}s$/, 'Count 1-10 (8)'; - ok $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)'; # ---------------------------------------------------------------------------- diff --git a/t/name.t b/t/name.t index 09ea432..565779f 100644 --- a/t/name.t +++ b/t/name.t @@ -10,7 +10,7 @@ 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( evcheck ); @@ -19,11 +19,6 @@ 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 @@ -32,9 +27,7 @@ successfully. =cut -use Term::ProgressBar; - -ok 1, 1, 'compilation'; +use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); @@ -65,9 +58,9 @@ 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)'); + 'Count 1-10 ( 2)'); }; print $out; @@ -76,7 +69,7 @@ print $out; 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 @@ -89,9 +82,9 @@ print $out; ($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)'); + 'Count 1-10 ( 6)'); }; print $out; @@ -101,9 +94,9 @@ print $out; @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)'; } # ------------------------------------- @@ -131,9 +124,9 @@ Use v1 mode 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)'); + 'Count 1-10 ( 2)'); }; print $out; @@ -142,7 +135,7 @@ print $out; 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 @@ -154,9 +147,9 @@ print $out; ($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)'); + 'Count 1-10 ( 6)'); }; print $out; $err =~ s!^.*\r!!gm; @@ -165,8 +158,8 @@ print $out; @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)'; } # ------------------------------------- diff --git a/t/test.pm b/t/test.pm index 1025f4e..f72ae08 100644 --- a/t/test.pm +++ b/t/test.pm @@ -8,19 +8,6 @@ test - tools for helping in test suites (not including running externalprograms) =head1 SYNOPSIS - use FindBin 1.42 qw( $Bin ); - use Test 1.13 qw( ok plan ); - - BEGIN { unshift @INC, $Bin }; - - use test qw( evcheck runcheck ); - - BEGIN { - plan tests => 3, - todo => [], - ; - } - ok evcheck(sub { open my $fh, '>', 'foo'; print $fh "$_\n" diff --git a/t/v1-message.t b/t/v1-message.t index 550ab79..0b43108 100644 --- a/t/v1-message.t +++ b/t/v1-message.t @@ -10,19 +10,13 @@ This package tests the basic functionality of Term::ProgressBar. use Data::Dumper qw( Dumper ); use FindBin qw( $Bin ); -use Test qw( ok plan ); +use Test::More tests => 8; use lib $Bin; use test qw( evcheck ); use constant MESSAGE1 => 'Walking on the Milky Way'; -BEGIN { - # 1 for compilation test, - plan tests => 8, - todo => [], -} - =head2 Test 1: compilation This test confirms that the test script and the modules it calls compiled @@ -30,9 +24,8 @@ successfully. =cut -use Term::ProgressBar; +use_ok 'Term::ProgressBar'; -ok 1, 1, 'compilation'; Term::ProgressBar->__force_term (50); @@ -58,13 +51,13 @@ my ($out, $err) = capture { my $p; ok (evcheck(sub { $p = Term::ProgressBar->new('bob', 10); }, 'Count 1-10 (1)' ), - 1, 'Count 1-10 (1)'); + 'Count 1-10 (1)'); ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-10 (2)' ), - 1, 'Count 1-10 (2)'); + 'Count 1-10 (2)'); ok (evcheck(sub { $p->message(MESSAGE1) }, 'Count 1-10 (3)' ), - 1, 'Count 1-10 (3)'); + 'Count 1-10 (3)'); ok (evcheck(sub { $p->update($_) for 6..10 }, 'Count 1-10 (4)' ), - 1, 'Count 1-10 (4)'); + 'Count 1-10 (4)'); }; print $out; @@ -74,6 +67,6 @@ print $out; my @lines = split /\n/, $err; - ok $lines[0], MESSAGE1; - ok $lines[-1], qr/bob:\s+\d+% \#+/, 'Count 1-10 (6)'; - ok $lines[-1], qr/^bob:\s+100%/, 'Count 1-10 (7)'; + 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)'; diff --git a/t/v2-message.t b/t/v2-message.t index 5b215be..c4036e3 100644 --- a/t/v2-message.t +++ b/t/v2-message.t @@ -10,7 +10,7 @@ This package tests the basic functionality of Term::ProgressBar. use Data::Dumper 2.101 qw( Dumper ); use FindBin 1.42 qw( $Bin ); -use Test 1.122 qw( ok plan ); +use Test::More tests => 11; use lib $Bin; use test qw( evcheck ); @@ -19,11 +19,6 @@ use constant MESSAGE1 => 'Walking on the Milky Way'; use Capture::Tiny qw(capture); -BEGIN { - # 1 for compilation test, - plan tests => 11, - todo => [], -} =head2 Test 1: compilation @@ -32,9 +27,7 @@ successfully. =cut -use Term::ProgressBar; - -ok 1, 1, 'compilation'; +use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); @@ -58,13 +51,13 @@ 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)' ), - 1, 'Count 1-10 (1)'); + 'Count 1-10 (1)'); ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-10 (2)' ), - 1, 'Count 1-10 (2)'); + 'Count 1-10 (2)'); ok (evcheck(sub { $p->message(MESSAGE1) }, 'Count 1-10 (3)' ), - 1, 'Count 1-10 (3)'); + 'Count 1-10 (3)'); ok (evcheck(sub { $p->update($_) for 6..10 }, 'Count 1-10 (4)' ), - 1, 'Count 1-10 (4)'); + 'Count 1-10 (4)'); }; print $out; @@ -74,9 +67,9 @@ print $out; my @lines = split /\n/, $err; - ok $lines[0], MESSAGE1; - ok $lines[-1], qr/\[=+\]/, 'Count 1-10 (5)'; - ok $lines[-1], qr/^\s*100%/, 'Count 1-10 (6)'; + is $lines[0], MESSAGE1; + like $lines[-1], qr/\[=+\]/, 'Count 1-10 (5)'; + like $lines[-1], qr/^\s*100%/, 'Count 1-10 (6)'; # ------------------------------------- @@ -94,15 +87,15 @@ 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)'), - 1, 'Message Check ( 1)'); + 'Message Check ( 1)'); ok (evcheck(sub { for (0..100) { $p->update($_); $p->message("Hello") } }, 'Message Check ( 2)',), - 1, 'Message Check ( 2)'); + 'Message Check ( 2)'); }; print $out; my @err_lines = split /\n/, $err; (my $last_line = $err_lines[-1]) =~ tr/\r//d; - ok substr($last_line, 0, 4), '100%', 'Message Check ( 3)'; + is substr($last_line, 0, 4), '100%', 'Message Check ( 3)'; # ---------------------------------------------------------------------------- diff --git a/t/v2-mobile.t b/t/v2-mobile.t index dca4062..5021f2d 100644 --- a/t/v2-mobile.t +++ b/t/v2-mobile.t @@ -10,29 +10,14 @@ This package tests the moving target functionality of Term::ProgressBar. use Data::Dumper qw( Dumper ); use FindBin qw( $Bin ); -use Test qw( ok plan ); +use Test::More tests => 7; use lib $Bin; use test qw( evcheck ); use Capture::Tiny qw(capture); -BEGIN { - # 1 for compilation test, - plan tests => 7, - todo => [], -} - -=head2 Test 1: compilation - -This test confirms that the test script and the modules it calls compiled -successfully. - -=cut - -use Term::ProgressBar; - -ok 1, 1, 'compilation'; +use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); @@ -57,13 +42,13 @@ Update it from 11 to 20. my ($out, $err) = capture { my $p; ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-20 (1)' ), - 1, 'Count 1-20 (1)'); + 'Count 1-20 (1)'); ok (evcheck(sub { $p->update($_) for 1..5 }, 'Count 1-20 (2)' ), - 1, 'Count 1-20 (2)'); + 'Count 1-20 (2)'); ok (evcheck(sub { $p->target(20) }, 'Count 1-20 (3)' ), - 1, 'Count 1-20 (3)'); + 'Count 1-20 (3)'); ok (evcheck(sub { $p->update($_) for 11..20 }, 'Count 1-20 (4)' ), - 1, 'Count 1-20 (4)'); + 'Count 1-20 (4)'); }; print $out; @@ -73,5 +58,5 @@ print $out; my @lines = split /\n/, $err; - ok $lines[-1], qr/\[=+\]/, 'Count 1-20 (5)'; - ok $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)'; diff --git a/t/v2-simple.t b/t/v2-simple.t index 5b300ba..3bb54f7 100644 --- a/t/v2-simple.t +++ b/t/v2-simple.t @@ -10,29 +10,14 @@ This package tests the basic functionality of Term::ProgressBar. use Data::Dumper qw( Dumper ); use FindBin qw( $Bin ); -use Test qw( ok plan ); +use Test::More tests => 31; use lib $Bin; use test qw( evcheck ); use Capture::Tiny qw(capture); -BEGIN { - # 1 for compilation test, - plan tests => 31, - todo => [], -} - -=head2 Test 1: compilation - -This test confirms that the test script and the modules it calls compiled -successfully. - -=cut - -use Term::ProgressBar; - -ok 1, 1, 'compilation'; +use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); @@ -55,17 +40,17 @@ Update it it from 1 to 10. my ($out, $err) = capture { ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-10 (1)' ), - 1, 'Count 1-10 (1)'); + 'Count 1-10 (1)'); ok (evcheck(sub { $p->update($_) for 1..10 }, 'Count 1-10 (2)' ), - 1, 'Count 1-10 (2)'); + 'Count 1-10 (2)'); }; print $out; my @lines = grep $_ ne '', split /\r/, $err; print Dumper \@lines if $ENV{TEST_DEBUG}; - ok $lines[-1], qr/\[=+\]/, 'Count 1-10 (3)'; - ok $lines[-1], qr/^\s*100%/, 'Count 1-10 (4)'; - ok $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-10 (%d)', 5+$_) + like $lines[-1], qr/\[=+\]/, 'Count 1-10 (3)'; + like $lines[-1], qr/^\s*100%/, 'Count 1-10 (4)'; + like $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-10 (%d)', 5+$_) for 0..10; } # ------------------------------------- @@ -88,18 +73,18 @@ Update it it from 1 to 9. my ($out, $err) = capture { ok (evcheck(sub { $p = Term::ProgressBar->new(10); }, 'Count 1-9 (1)' ), - 1, 'Count 1-9 (1)'); + 'Count 1-9 (1)'); ok (evcheck(sub { $p->update($_) for 1..9 }, 'Count 1-9 (2)' ), - 1, 'Count 1-9 (2)'); + 'Count 1-9 (2)'); }; print $out; my @lines = grep $_ ne '', split /\r/, $err; print Dumper \@lines if $ENV{TEST_DEBUG}; - ok $lines[-1], qr/\[=+ +\]/, 'Count 1-9 (3)'; - ok $lines[-1], qr/^\s*90%/, 'Count 1-9 (4)'; - ok $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-9 (%d)', 5+$_) + like $lines[-1], qr/\[=+ +\]/, 'Count 1-9 (3)'; + like $lines[-1], qr/^\s*90%/, 'Count 1-9 (4)'; + like $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-9 (%d)', 5+$_) for 0..9; } # ------------------------------------- @@ -120,5 +105,5 @@ print $out; my @lines = grep $_ ne '', split /\r/, $err; print Dumper \@lines if $ENV{TEST_DEBUG}; - ok scalar @lines, 1; + is scalar @lines, 1; } diff --git a/t/zero.t b/t/zero.t index 7461163..8e6426b 100644 --- a/t/zero.t +++ b/t/zero.t @@ -10,29 +10,14 @@ This package tests the zero-progress handling of progress bar. use Data::Dumper qw( Dumper ); use FindBin qw( $Bin ); -use Test qw( ok plan ); +use Test::More tests => 9; use Capture::Tiny qw(capture); use lib $Bin; use test qw( evcheck ); -BEGIN { - # 1 for compilation test, - plan tests => 9, - todo => [], -} - -=head2 Test 1: compilation - -This test confirms that the test script and the modules it calls compiled -successfully. - -=cut - -use Term::ProgressBar; - -ok 1, 1, 'compilation'; +use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); @@ -57,16 +42,16 @@ my ($out, $err) = capture { $name = 'doing nothing'; ok (evcheck(sub { $p = Term::ProgressBar->new($name, 0); }, 'V1 mode ( 1)' ), - 1, 'V1 mode ( 1)'); + 'V1 mode ( 1)'); ok (evcheck(sub { $p->update($_) for 1..10 },'V1 mode ( 2)'), - 1, 'V1 mode ( 2)'); + 'V1 mode ( 2)'); }; print $out; my @lines = grep $_ ne '', split /\r/, $err; print Dumper \@lines if $ENV{TEST_DEBUG}; - ok $lines[-1], qr/^$name:/, 'V1 mode ( 3)'; - ok $lines[-1], qr/\(nothing to do\)/, 'V1 mode ( 4)'; + like $lines[-1], qr/^$name:/, 'V1 mode ( 3)'; + like $lines[-1], qr/\(nothing to do\)/, 'V1 mode ( 4)'; } # ------------------------------------- @@ -90,16 +75,16 @@ my ($out, $err) = capture { ok (evcheck(sub { $p = Term::ProgressBar->new({ count => 0, name => $name }); }, 'V2 mode ( 1)' ), - 1, 'V2 mode ( 1)'); + 'V2 mode ( 1)'); ok (evcheck(sub { $p->update($_) for 1..10 },'V2 mode ( 2)'), - 1, 'V2 mode ( 2)'); + 'V2 mode ( 2)'); }; print $out; my @lines = grep $_ ne '', split /\r/, $err; print Dumper \@lines if $ENV{TEST_DEBUG}; - ok $lines[-1], qr/^$name:/, 'V2 mode ( 3)'; - ok $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)'; } # ----------------------------------------------------------------------------