From 694b837203341a81f3a593f058ccbdc2e8f46db3 Mon Sep 17 00:00:00 2001 From: Alex Beamish Date: Thu, 8 Aug 2019 21:55:53 -0400 Subject: [PATCH 1/2] Bump version to 0.14 --- lib/Test/Block.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Test/Block.pm b/lib/Test/Block.pm index e367e0b..d342202 100644 --- a/lib/Test/Block.pm +++ b/lib/Test/Block.pm @@ -16,7 +16,7 @@ use overload q{0+} => \&remaining, fallback => 1; -our $VERSION = '0.13'; +our $VERSION = '0.14'; my $Last_test_in_previous_block = 0; my $Active_block_count = 0; @@ -59,6 +59,22 @@ sub DESTROY { my $name = $self->{name}; my $tests_ran = _tests_run_in_block($self); $name = "'$name'" unless looks_like_number( $name ); + + # In perl 5.23.7 and earlier, the call stack at this point looks like: + # + # Test::Block::DESTROY(...) called at test_script line NNN + # eval {...} called at test_script line NNN + # + # in perl 5.23.8 and later, like: + # + # Test::Block::DESTROY(...) called at Tie/Scalar.pm line 157 + # eval {...} called at Tie/Scalar.pm line 157 + # Tie::StdScalar::STORE(...) called at Test/Block.pm line 96 + # Test::Block::Plan::STORE(...) called at test_script line NNN + # + local $Test::Builder::Level = + $Test::Builder::Level + ($] >= 5.023008 ? 3 : 0); + $Test_builder->ok( 0, "block $name expected $expected test(s) and ran $tests_ran" From 27d6f60a43fdb9bd90ca176118af154536d72962 Mon Sep 17 00:00:00 2001 From: Alex Beamish Date: Thu, 8 Aug 2019 21:55:53 -0400 Subject: [PATCH 2/2] Add provided patch, bump version to 0.14 This implements the patch at https://rt.cpan.org/Public/Bug/Display.html?id=112462 and bumps the version number to 0.14. --- lib/Test/Block.pm | 18 +++++++++++++++++- t/block.t | 10 +++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/Test/Block.pm b/lib/Test/Block.pm index e367e0b..d342202 100644 --- a/lib/Test/Block.pm +++ b/lib/Test/Block.pm @@ -16,7 +16,7 @@ use overload q{0+} => \&remaining, fallback => 1; -our $VERSION = '0.13'; +our $VERSION = '0.14'; my $Last_test_in_previous_block = 0; my $Active_block_count = 0; @@ -59,6 +59,22 @@ sub DESTROY { my $name = $self->{name}; my $tests_ran = _tests_run_in_block($self); $name = "'$name'" unless looks_like_number( $name ); + + # In perl 5.23.7 and earlier, the call stack at this point looks like: + # + # Test::Block::DESTROY(...) called at test_script line NNN + # eval {...} called at test_script line NNN + # + # in perl 5.23.8 and later, like: + # + # Test::Block::DESTROY(...) called at Tie/Scalar.pm line 157 + # eval {...} called at Tie/Scalar.pm line 157 + # Tie::StdScalar::STORE(...) called at Test/Block.pm line 96 + # Test::Block::Plan::STORE(...) called at test_script line NNN + # + local $Test::Builder::Level = + $Test::Builder::Level + ($] >= 5.023008 ? 3 : 0); + $Test_builder->ok( 0, "block $name expected $expected test(s) and ran $tests_ran" diff --git a/t/block.t b/t/block.t index fbf8469..4a9f814 100644 --- a/t/block.t +++ b/t/block.t @@ -4,6 +4,10 @@ use Test::Builder::Tester tests => 6; use Test::More; use Test::Block; +# in perl 5.23.8 and later, caller() in a destructor called while +# exiting a block shows the last line of the block, not the first +my $lastl = $] >= 5.023008; + test_out('ok 1'); { my $block = Test::Block->plan(1); @@ -14,7 +18,7 @@ test_test("count okay"); test_out('ok 1'); test_out('not ok 2 - block 2 expected 2 test(s) and ran 1'); -test_fail(+2); +test_fail($lastl ? +3 : +2); { my $block = Test::Block->plan(2); ok(1); @@ -25,7 +29,7 @@ test_test("too few tests"); test_out('ok 1'); test_out('ok 2'); test_out('not ok 3 - block 3 expected 1 test(s) and ran 2'); -test_fail(+2); +test_fail($lastl ? +4 : +2); { my $block = Test::Block->plan(1); ok(1); @@ -57,7 +61,7 @@ test_test("nested blocks"); test_out('ok 1'); test_out("not ok 2 - block 'foo' expected 2 test(s) and ran 1"); -test_fail(+2); +test_fail($lastl ? +3 : +2); { my $block = Test::Block->plan(foo => 2); ok(1);