From 863221fd52c3fe399a0648f8106f47a6e356f64c Mon Sep 17 00:00:00 2001 From: Brendan Byrd Date: Mon, 15 Apr 2013 16:40:29 +0100 Subject: [PATCH 1/3] Change subtest to auto-note at the beginning of the test Fix t/subtest/*.t to work with new auto-note Fix outergroup test in t/subtest/predicate.t Fix Test::Builder::Tester::complaint to not output double-spaced $wanted --- lib/Test/Builder.pm | 3 +++ lib/Test/Builder/Tester.pm | 2 +- lib/Test/More.pm | 1 + t/subtest/bail_out.t | 2 ++ t/subtest/line_numbers.t | 5 +++++ t/subtest/predicate.t | 12 ++++++++++-- t/subtest/todo.t | 1 + 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/Test/Builder.pm b/lib/Test/Builder.pm index 9ffb8b670..f3171109b 100644 --- a/lib/Test/Builder.pm +++ b/lib/Test/Builder.pm @@ -237,6 +237,9 @@ sub subtest { $self->croak("subtest()'s second argument must be a code ref"); } + # Add subtest note for clarification of starting point + $self->note("Subtest: $name"); + # Turn the child into the parent so anyone who has stored a copy of # the Test::Builder singleton will get the child. my $error; diff --git a/lib/Test/Builder/Tester.pm b/lib/Test/Builder/Tester.pm index 573c818fb..57b147b55 100644 --- a/lib/Test/Builder/Tester.pm +++ b/lib/Test/Builder/Tester.pm @@ -511,7 +511,7 @@ sub complaint { my $self = shift; my $type = $self->type; my $got = $self->got; - my $wanted = join "\n", @{ $self->wanted }; + my $wanted = join '', @{ $self->wanted }; # are we running in colour mode? if(Test::Builder::Tester::color) { diff --git a/lib/Test/More.pm b/lib/Test/More.pm index 8fff90de6..7e52429c7 100644 --- a/lib/Test/More.pm +++ b/lib/Test/More.pm @@ -727,6 +727,7 @@ This would produce. 1..3 ok 1 - First test + # Subtest: An example subtest 1..2 ok 1 - This is a subtest ok 2 - So is this diff --git a/t/subtest/bail_out.t b/t/subtest/bail_out.t index 3771a18ba..be7ec76ef 100644 --- a/t/subtest/bail_out.t +++ b/t/subtest/bail_out.t @@ -46,8 +46,10 @@ subtest 'bar' => sub { $Test->is_eq( $output, <<'OUT' ); 1..4 ok 1 +# Subtest: bar 1..3 ok 1 + # Subtest: sub_bar 1..3 ok 1 ok 2 diff --git a/t/subtest/line_numbers.t b/t/subtest/line_numbers.t index 33d70ecee..eaef1fb26 100644 --- a/t/subtest/line_numbers.t +++ b/t/subtest/line_numbers.t @@ -26,6 +26,7 @@ $ENV{HARNESS_ACTIVE} = 0; our %line; { + test_out("# Subtest: namehere"); test_out(" 1..3"); test_out(" ok 1"); test_out(" not ok 2"); @@ -46,6 +47,7 @@ our %line; test_test("un-named inner tests"); } { + test_out("# Subtest: namehere"); test_out(" 1..3"); test_out(" ok 1 - first is good"); test_out(" not ok 2 - second is bad"); @@ -76,6 +78,7 @@ sub run_the_subtest { }; BEGIN{ $line{outerfail3} = __LINE__ } } { + test_out("# Subtest: namehere"); test_out(" 1..3"); test_out(" ok 1 - first is good"); test_out(" not ok 2 - second is bad"); @@ -92,6 +95,7 @@ sub run_the_subtest { test_test("subtest() called from a sub"); } { + test_out("# Subtest: namehere"); test_out( " 1..0"); test_err( " # No tests run!"); test_out( 'not ok 1 - No tests run for subtest "namehere"'); @@ -105,6 +109,7 @@ sub run_the_subtest { test_test("lineno in 'No tests run' diagnostic"); } { + test_out("# Subtest: namehere"); test_out(" 1..1"); test_out(" not ok 1 - foo is bar"); test_err(" # Failed test 'foo is bar'"); diff --git a/t/subtest/predicate.t b/t/subtest/predicate.t index 9fbdf00ca..73b9c8105 100644 --- a/t/subtest/predicate.t +++ b/t/subtest/predicate.t @@ -16,7 +16,7 @@ BEGIN { use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Builder; use Test::Builder::Tester; @@ -40,6 +40,7 @@ sub foobar_ok ($;$) { }; } { + test_out("# Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -64,6 +65,7 @@ sub foobar_ok_2 ($;$) { foobar_ok($value, $name); } { + test_out("# Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -93,6 +95,7 @@ sub barfoo_ok ($;$) { }); } { + test_out("# Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -117,6 +120,7 @@ sub barfoo_ok_2 ($;$) { barfoo_ok($value, $name); } { + test_out("# Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -134,8 +138,10 @@ sub barfoo_ok_2 ($;$) { # A subtest-based predicate called from within a subtest { + test_out("# Subtest: outergroup"); test_out(" 1..2"); test_out(" ok 1 - this passes"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -145,6 +151,7 @@ sub barfoo_ok_2 ($;$) { test_out(" not ok 2 - namehere"); test_err(" # Failed test 'namehere'"); test_err(" # at $0 line $line{ipredcall}."); + test_err(" # Looks like you failed 1 test of 2."); test_out("not ok 1 - outergroup"); test_err("# Failed test 'outergroup'"); test_err("# at $0 line $line{outercall}."); @@ -154,5 +161,6 @@ sub barfoo_ok_2 ($;$) { ok 1, "this passes"; barfoo_ok_2 "foot", "namehere"; BEGIN{ $line{ipredcall} = __LINE__ } }; BEGIN{ $line{outercall} = __LINE__ } -} + test_test("outergroup with internal barfoo_ok_2 failing line numbers"); +} diff --git a/t/subtest/todo.t b/t/subtest/todo.t index 345f5e124..a53c4a042 100644 --- a/t/subtest/todo.t +++ b/t/subtest/todo.t @@ -52,6 +52,7 @@ sub test_subtest_in_todo { my ($set_via, $todo_reason, $level) = @$combo; test_out( + "# Subtest: xxx", @outlines, "not ok 1 - $xxx # TODO $todo_reason", "# Failed (TODO) test '$xxx'", From 5c1b28c198bd9de48aed3af31e7f2ff3baf2a7f0 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Mon, 15 Apr 2013 16:45:11 +0100 Subject: [PATCH 2/3] Indent the subtest note with the subtest. Discussed in #290. --- lib/Test/Builder.pm | 6 +++--- lib/Test/More.pm | 2 +- t/subtest/bail_out.t | 4 ++-- t/subtest/line_numbers.t | 10 +++++----- t/subtest/predicate.t | 12 ++++++------ t/subtest/todo.t | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/Test/Builder.pm b/lib/Test/Builder.pm index f3171109b..000c1a177 100644 --- a/lib/Test/Builder.pm +++ b/lib/Test/Builder.pm @@ -237,9 +237,6 @@ sub subtest { $self->croak("subtest()'s second argument must be a code ref"); } - # Add subtest note for clarification of starting point - $self->note("Subtest: $name"); - # Turn the child into the parent so anyone who has stored a copy of # the Test::Builder singleton will get the child. my $error; @@ -250,11 +247,14 @@ sub subtest { # $Level first to limit the scope of the reset to the subtest. local $Test::Builder::Level = $Test::Builder::Level + 1; + # Store the guts of $self as $parent and turn $child into $self. $child = $self->child($name); _copy($self, $parent); _copy($child, $self); my $run_the_subtests = sub { + # Add subtest name for clarification of starting point + $self->note("Subtest: $name"); $subtests->(); $self->done_testing unless $self->_plan_handled; 1; diff --git a/lib/Test/More.pm b/lib/Test/More.pm index 7e52429c7..947b187ef 100644 --- a/lib/Test/More.pm +++ b/lib/Test/More.pm @@ -727,7 +727,7 @@ This would produce. 1..3 ok 1 - First test - # Subtest: An example subtest + # Subtest: An example subtest 1..2 ok 1 - This is a subtest ok 2 - So is this diff --git a/t/subtest/bail_out.t b/t/subtest/bail_out.t index be7ec76ef..70dc9ac56 100644 --- a/t/subtest/bail_out.t +++ b/t/subtest/bail_out.t @@ -46,10 +46,10 @@ subtest 'bar' => sub { $Test->is_eq( $output, <<'OUT' ); 1..4 ok 1 -# Subtest: bar + # Subtest: bar 1..3 ok 1 - # Subtest: sub_bar + # Subtest: sub_bar 1..3 ok 1 ok 2 diff --git a/t/subtest/line_numbers.t b/t/subtest/line_numbers.t index eaef1fb26..7a20a60ae 100644 --- a/t/subtest/line_numbers.t +++ b/t/subtest/line_numbers.t @@ -26,7 +26,7 @@ $ENV{HARNESS_ACTIVE} = 0; our %line; { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..3"); test_out(" ok 1"); test_out(" not ok 2"); @@ -47,7 +47,7 @@ our %line; test_test("un-named inner tests"); } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..3"); test_out(" ok 1 - first is good"); test_out(" not ok 2 - second is bad"); @@ -78,7 +78,7 @@ sub run_the_subtest { }; BEGIN{ $line{outerfail3} = __LINE__ } } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..3"); test_out(" ok 1 - first is good"); test_out(" not ok 2 - second is bad"); @@ -95,7 +95,7 @@ sub run_the_subtest { test_test("subtest() called from a sub"); } { - test_out("# Subtest: namehere"); + test_out( " # Subtest: namehere"); test_out( " 1..0"); test_err( " # No tests run!"); test_out( 'not ok 1 - No tests run for subtest "namehere"'); @@ -109,7 +109,7 @@ sub run_the_subtest { test_test("lineno in 'No tests run' diagnostic"); } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..1"); test_out(" not ok 1 - foo is bar"); test_err(" # Failed test 'foo is bar'"); diff --git a/t/subtest/predicate.t b/t/subtest/predicate.t index 73b9c8105..4e29a426b 100644 --- a/t/subtest/predicate.t +++ b/t/subtest/predicate.t @@ -40,7 +40,7 @@ sub foobar_ok ($;$) { }; } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -65,7 +65,7 @@ sub foobar_ok_2 ($;$) { foobar_ok($value, $name); } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -95,7 +95,7 @@ sub barfoo_ok ($;$) { }); } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -120,7 +120,7 @@ sub barfoo_ok_2 ($;$) { barfoo_ok($value, $name); } { - test_out("# Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); @@ -138,10 +138,10 @@ sub barfoo_ok_2 ($;$) { # A subtest-based predicate called from within a subtest { - test_out("# Subtest: outergroup"); + test_out(" # Subtest: outergroup"); test_out(" 1..2"); test_out(" ok 1 - this passes"); - test_out(" # Subtest: namehere"); + test_out(" # Subtest: namehere"); test_out(" 1..2"); test_out(" ok 1 - foo"); test_out(" not ok 2 - bar"); diff --git a/t/subtest/todo.t b/t/subtest/todo.t index a53c4a042..7269da9b9 100644 --- a/t/subtest/todo.t +++ b/t/subtest/todo.t @@ -52,7 +52,7 @@ sub test_subtest_in_todo { my ($set_via, $todo_reason, $level) = @$combo; test_out( - "# Subtest: xxx", + " # Subtest: xxx", @outlines, "not ok 1 - $xxx # TODO $todo_reason", "# Failed (TODO) test '$xxx'", From 93cef25021b20030edf5acf0ba8e5ddf55dd1d59 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Mon, 15 Apr 2013 16:52:06 +0100 Subject: [PATCH 3/3] Log the subtest note change. --- Changes | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Changes b/Changes index 1ee71852e..b9ca54e4f 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,11 @@ * Add a shorter work around for the UTF-8 output problem. (Michael G Schwern) + New Features + * A subtest will put its name at the front of its results to make + subtests easier to read. [github #290] [github #364] + (Brendan Byrd) + 0.98_04 Sun Apr 14 10:54:13 BST 2013 Distribution Changes