Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subtest should auto-note at the beginning of the test #290

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Test/Builder.pm
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/Test/Builder/Tester.pm
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/Test/More.pm
Expand Up @@ -706,6 +706,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
Expand Down
2 changes: 2 additions & 0 deletions t/subtest/bail_out.t
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions t/subtest/line_numbers.t
Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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"');
Expand All @@ -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'");
Expand Down
12 changes: 10 additions & 2 deletions t/subtest/predicate.t
Expand Up @@ -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;

Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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}.");
Expand All @@ -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");
}
1 change: 1 addition & 0 deletions t/subtest/todo.t
Expand Up @@ -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'",
Expand Down