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

Test2::API run_subtest() TODO output wrong? #817

Closed
wolfsage opened this issue Aug 29, 2018 · 2 comments
Closed

Test2::API run_subtest() TODO output wrong? #817

wolfsage opened this issue Aug 29, 2018 · 2 comments

Comments

@wolfsage
Copy link
Contributor

wolfsage commented Aug 29, 2018

A $TODO in run_subtest loses the TODO <desc> on success, and loses <desc> on failure.

Consider:

alh@hyrule:~$ cat pass.t

use Test2::API qw(run_subtest);
use Test::More;

subtest "good pass" => sub {
  local $TODO = "first test";
  ok(1, "ok");
};

subtest "good fail" => sub {
  local $TODO = "second test";
  ok(0, "ok");
};

run_subtest("bad pass", sub {
  local $TODO = "third test";
  ok(1, "ok");
});

run_subtest("bad fail", sub {
  local $TODO = "third test";
  ok(0, "ok");
});

done_testing;

alh@hyrule:~$ perl pass.t

# Subtest: good pass
    ok 1 - ok # TODO first test
    1..1
ok 1 - good pass
# Subtest: good fail
    not ok 1 - ok # TODO second test
    #   Failed (TODO) test 'ok'
    #   at pass.t line 11.
    1..1
ok 2 - good fail
# bad pass
    ok 1 - ok # 
    1..1
ok 3 - bad pass
# bad fail
    not ok 1 - ok # TODO
    #   Failed (TODO) test 'ok'
    #   at pass.t line 21.
    1..1
ok 4 - bad fail
1..4
@exodist
Copy link
Member

exodist commented Dec 11, 2018

This looks like a bug with $TODO variable handling. When using Test2's newer form of TODO it works correctly. Here is an updated test file (that also includes a fix to how run_subtest() is called since it is not intended to be called outside of a sub that obtains a context)

use Test2::API qw(run_subtest context);
use Test::More;
use Test2::Tools::Tiny qw/todo/;

subtest "good pass" => sub {
#    local $TODO = "first test";
    todo "first test" => sub {
        ok(1, "ok");
    };  
};

subtest "good fail" => sub {
    #local $TODO = "second test";
    todo "second test" => sub {
        ok(0, "ok");
    }   
};

sub aaa {
    my $ctx = context();
    run_subtest(
        "bad pass",
        sub {
            #local $TODO = "third test";
            todo "third test" => sub {
                ok(1, "ok");
            };  
        }   
    );  
    $ctx->release;
}

aaa();

sub bbb {
    my $ctx = context();
    run_subtest(
        "bad fail",
        sub {
            #local $TODO = "fourth test";
            todo "fourth test" => sub {
                ok(0, "ok");
            }   
        }   
    );  

    $ctx->release;
}

bbb();

done_testing;

exodist added a commit that referenced this issue Dec 11, 2018
    - Fix #814 Windows fork+test failure
    - Fix #819 Documentation updates
    - Fix #810 Verbose TAP newline regression
    - Fix #817 local $TODO bug
    - Fix #812 Another local $TODO bug
    - Fix #815 shm read warning
    - Merge doc fix PR's from magnolia-k (thanks!)
@wolfsage
Copy link
Contributor Author

Fix solves our problems, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants