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

Source display doesn't work inside buffered subtests #2

Open
petdance opened this issue Jun 27, 2017 · 2 comments
Open

Source display doesn't work inside buffered subtests #2

petdance opened this issue Jun 27, 2017 · 2 comments

Comments

@petdance
Copy link

$ cat foo.t
#!/var/perl/bin/perl

use warnings;
use strict;

use Test2::V0;
use Test2::Plugin::SourceDiag;

plan 2;

is( 'war', 'peace', 'Is war peace?' );

subtest 'Freedom subtest' => sub {
    is( 'freedom', 'slavery' );
};

diag 'Got out of the subtest OK';
is( 'ignorance', 'strength' );

gives

$ prove -v foo.t
[15:54:59] foo.t .. 
# Seeded srand with seed '20170627' from local date.
1..2
not ok 1 - Is war peace?
# Failure source code:
# ------------
# 11: is( 'war', 'peace', 'Is war peace?' );
# ------------
# Failed test 'Is war peace?'
# at foo.t line 11.
# +-----+----+-------+
# | GOT | OP | CHECK |
# +-----+----+-------+
# | war | eq | peace |
# +-----+----+-------+
Can't call method "previous_sibling" on an undefined value at /var/perl5.20.3/lib/site_perl/5.20.3/Test2/Plugin/SourceDiag.pm line 136.
A context appears to have been destroyed without first calling release().
Based on $@ it does not look like an exception was thrown (this is not always
a reliable test)

This is a problem because the global error variables ($!, $@, and $?) will
not be restored. In addition some release callbacks will not work properly from
inside a DESTROY method.

Here are the context creation details, just in case a tool forgot to call
release():
  File: /var/perl5.20.3/lib/site_perl/5.20.3/Test2/Tools/Subtest.pm
  Line: 34
  Tool: Test2::API::run_subtest

Cleaning up the CONTEXT stack...
A context appears to have been destroyed without first calling release().
Based on $@ it does not look like an exception was thrown (this is not always
a reliable test)

This is a problem because the global error variables ($!, $@, and $?) will
not be restored. In addition some release callbacks will not work properly from
inside a DESTROY method.

Here are the context creation details, just in case a tool forgot to call
release():
  File: foo.t
  Line: 15
  Tool: Test2::Tools::Subtest::subtest_buffered

Cleaning up the CONTEXT stack...
# Looks like your test exited with 255 after test #1.
# Did not follow plan: expected 2, ran 1.
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 2/2 subtests 
[15:54:59]

Test Summary Report
-------------------
foo.t (Wstat: 65280 Tests: 1 Failed: 1)
  Failed test:  1
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 2 tests but ran 1.
Files=1, Tests=1,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.18 cusr  0.02 csys =  0.22 CPU)
Result: FAIL

However, if I change that subtest to subtest_streamed it is happy:

$ prove -v foo.t
[15:55:50] foo.t .. 
# Seeded srand with seed '20170627' from local date.
1..2
not ok 1 - Is war peace?
# Failure source code:
# ------------
# 11: is( 'war', 'peace', 'Is war peace?' );
# ------------
# Failed test 'Is war peace?'
# at foo.t line 11.
# +-----+----+-------+
# | GOT | OP | CHECK |
# +-----+----+-------+
# | war | eq | peace |
# +-----+----+-------+
# Subtest: Freedom subtest
    not ok 1 - is( 'freedom', 'slavery' );
    # Failed test 'is( 'freedom', 'slavery' );'
    # at foo.t line 14.
    # +---------+----+---------+
    # | GOT     | OP | CHECK   |
    # +---------+----+---------+
    # | freedom | eq | slavery |
    # +---------+----+---------+
    1..1
not ok 2 - Subtest: Freedom subtest
# Failure source code:
# ------------
# 13: Test2::Tools::Subtest::subtest_streamed 'Freedom subtest' => sub {
# 14:     is( 'freedom', 'slavery' );
# 15: };
# ------------
# Failed test 'Subtest: Freedom subtest'
# at foo.t line 15.
# Got out of the subtest OK
not ok 3 - is( 'ignorance', 'strength' );
# Failed test 'is( 'ignorance', 'strength' );'
# at foo.t line 18.
# +-----------+----+----------+
# | GOT       | OP | CHECK    |
# +-----------+----+----------+
# | ignorance | eq | strength |
# +-----------+----+----------+
# Did not follow plan: expected 2, ran 3.
Dubious, test returned 3 (wstat 768, 0x300)
Failed 2/2 subtests 
[15:55:51]

Test Summary Report
-------------------
foo.t (Wstat: 768 Tests: 3 Failed: 3)
  Failed tests:  1-3
  Non-zero exit status: 3
  Parse errors: Bad plan.  You planned 2 tests but ran 3.
Files=1, Tests=3,  1 wallclock secs ( 0.02 usr  0.01 sys +  0.16 cusr  0.01 csys =  0.20 CPU)
Result: FAIL
@petdance petdance changed the title Source display doesn't work inside subtests Source display doesn't work inside buffered subtests Jun 27, 2017
@petdance
Copy link
Author

petdance commented Jun 27, 2017

Note that the source didn't show up in the 3rd test, probably because it doesn't have a name, as noted in #1.

@petdance
Copy link
Author

My mistake. It's not a matter of buffered vs. streamed. It's calling subtest vs. subtest_buffered vs. subtest_streamed.

#!/var/perl/bin/perl

use warnings;
use strict;

use Test2::V0;
use Test2::Plugin::SourceDiag;

plan 3;

Test2::Tools::Subtest::subtest_streamed 'Freedom subtest' => sub {
    is( 'freedom', 'slavery' );
};
Test2::Tools::Subtest::subtest_buffered 'Freedom subtest' => sub {
    is( 'freedom', 'slavery' );
};
subtest 'Freedom subtest' => sub {
    is( 'freedom', 'slavery' );
};

gives

$ prove -v foo.t                                                                                       
[16:47:31] foo.t ..                                                 
# Seeded srand with seed '20170627' from local date.                
1..3                                                                
# Subtest: Freedom subtest                                          
    not ok 1 - is( 'freedom', 'slavery' );
    # Failed test 'is( 'freedom', 'slavery' );'                     
    # at foo.t line 12.                                             
    # +---------+----+---------+                                    
    # | GOT     | OP | CHECK   |                                    
    # +---------+----+---------+                                    
    # | freedom | eq | slavery |                                    
    # +---------+----+---------+
    1..1                                                            
not ok 1 - Subtest: Freedom subtest                                 
# Failure source code:                                              
# ------------                                                      
# 11: Test2::Tools::Subtest::subtest_streamed 'Freedom subtest' => sub {
# 12:     is( 'freedom', 'slavery' );                               
# 13: };                                                                                                                                
# ------------                                                      
# Failed test 'Subtest: Freedom subtest'                            
# at foo.t line 13.
not ok 2 - Freedom subtest {
    not ok 1 - is( 'freedom', 'slavery' );
    1..1
}
    # Failed test 'is( 'freedom', 'slavery' );'
    # at foo.t line 15.
    # +---------+----+---------+
    # | GOT     | OP | CHECK   |
    # +---------+----+---------+
    # | freedom | eq | slavery |
    # +---------+----+---------+
# Failure source code:
# ------------
# 14: Test2::Tools::Subtest::subtest_buffered 'Freedom subtest' => sub {
# 15:     is( 'freedom', 'slavery' );
# 16: };
# ------------
# Failed test 'Freedom subtest'
# at foo.t line 16.
Can't call method "previous_sibling" on an undefined value at /var/perl5.20.3/lib/site_perl/5.20.3/Test2/Plugin/SourceDiag.pm line 136.
A context appears to have been destroyed without first calling release().
Based on $@ it does not look like an exception was thrown (this is not always
a reliable test)

This is a problem because the global error variables ($!, $@, and $?) will
not be restored. In addition some release callbacks will not work properly from
inside a DESTROY method.

Here are the context creation details, just in case a tool forgot to call
release():
  File: /var/perl5.20.3/lib/site_perl/5.20.3/Test2/Tools/Subtest.pm
  Line: 34
  Tool: Test2::API::run_subtest

Cleaning up the CONTEXT stack...
A context appears to have been destroyed without first calling release().
Based on $@ it does not look like an exception was thrown (this is not always
a reliable test)

This is a problem because the global error variables ($!, $@, and $?) will
not be restored. In addition some release callbacks will not work properly from
inside a DESTROY method.

Here are the context creation details, just in case a tool forgot to call
release():
  File: foo.t
  Line: 19
  Tool: Test2::Tools::Subtest::subtest_buffered

Cleaning up the CONTEXT stack...
# Looks like your test exited with 255 after test #2.
# Did not follow plan: expected 3, ran 2.
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 3/3 subtests 
[16:47:32]

Test Summary Report
-------------------
foo.t (Wstat: 65280 Tests: 2 Failed: 2)
  Failed tests:  1-2
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 3 tests but ran 2.
Files=1, Tests=2,  1 wallclock secs ( 0.02 usr  0.00 sys +  0.12 cusr  0.01 csys =  0.15 CPU)
Result: FAIL

The first two going to subtest_buffered or subtest_streamed work. Going to subtest provided by ::V0 is what it can't handle.

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

1 participant