diff options
author | Todd Rinaldo <toddr@cpan.org> | 2020-09-15 21:23:31 -0500 |
---|---|---|
committer | Todd Rinaldo <toddr@cpan.org> | 2020-09-15 23:42:34 -0500 |
commit | 18c72c399196d35c6fc14d5bae4f312deceb8359 (patch) | |
tree | 0d62983c705b00b56a1edc1b0166b6179c2bb500 /cpan/Test-Simple/t | |
parent | 544e14500f76f6a28da0d5b423ccc23f22723777 (diff) | |
download | perl-18c72c399196d35c6fc14d5bae4f312deceb8359.tar.gz |
Update Test-Simple to CPAN version 1.302181
[DELTA]
1.302181 2020-09-14 09:46:04-07:00 America/Los_Angeles
- put try_sig_mask back where it goes (And add test to prevent this in the future)
- Drop new List::Util requirement back down
1.302180 2020-09-13 23:11:18-07:00 America/Los_Angeles
- No changes since last trial
1.302179 2020-09-12 22:35:19-07:00 America/Los_Angeles (TRIAL RELEASE)
- Bump minimum List::Util version (for uniq)
1.302178 2020-09-07 14:11:52-07:00 America/Los_Angeles (TRIAL RELEASE)
- Move try_sig_mask to the only module that uses it.
- Inherit warnings bitmask in cmp_ok string eval
- Update copyright date
- Improved API for interept {} and what it returns
1.302177 2020-08-06 21:46:06-07:00 America/Los_Angeles
- Minor fix to author downstream test
- No significant changes since the last trial
1.302176 2020-08-05 21:45:19-07:00 America/Los_Angeles (TRIAL RELEASE)
- Fix Test::More's $TODO inside intercept (#862)
Diffstat (limited to 'cpan/Test-Simple/t')
-rw-r--r-- | cpan/Test-Simple/t/Legacy/Builder/current_test.t | 5 | ||||
-rw-r--r-- | cpan/Test-Simple/t/Legacy/Regression/870-experimental-warnings.t | 16 | ||||
-rw-r--r-- | cpan/Test-Simple/t/Legacy/buffer.t | 5 | ||||
-rw-r--r-- | cpan/Test-Simple/t/Legacy/fail-like.t | 5 | ||||
-rw-r--r-- | cpan/Test-Simple/t/Legacy/is_deeply_fail.t | 1 | ||||
-rw-r--r-- | cpan/Test-Simple/t/Legacy/todo.t | 5 | ||||
-rw-r--r-- | cpan/Test-Simple/t/Test2/modules/API/InterceptResult.t | 302 | ||||
-rw-r--r-- | cpan/Test-Simple/t/Test2/modules/API/InterceptResult/Event.t | 950 | ||||
-rw-r--r-- | cpan/Test-Simple/t/Test2/modules/API/InterceptResult/Squasher.t | 117 | ||||
-rw-r--r-- | cpan/Test-Simple/t/Test2/modules/Event/V2.t | 2 | ||||
-rw-r--r-- | cpan/Test-Simple/t/regression/862-intercept_tb_todo.t | 62 |
11 files changed, 1464 insertions, 6 deletions
diff --git a/cpan/Test-Simple/t/Legacy/Builder/current_test.t b/cpan/Test-Simple/t/Legacy/Builder/current_test.t index edd201c0e9..b8979c64c6 100644 --- a/cpan/Test-Simple/t/Legacy/Builder/current_test.t +++ b/cpan/Test-Simple/t/Legacy/Builder/current_test.t @@ -3,8 +3,11 @@ # Dave Rolsky found a bug where if current_test() is used and no # tests are run via Test::Builder it will blow up. +use strict; +use warnings; + use Test::Builder; -$TB = Test::Builder->new; +my $TB = Test::Builder->new; $TB->plan(tests => 2); print "ok 1\n"; print "ok 2\n"; diff --git a/cpan/Test-Simple/t/Legacy/Regression/870-experimental-warnings.t b/cpan/Test-Simple/t/Legacy/Regression/870-experimental-warnings.t new file mode 100644 index 0000000000..9758d242f6 --- /dev/null +++ b/cpan/Test-Simple/t/Legacy/Regression/870-experimental-warnings.t @@ -0,0 +1,16 @@ +use strict; +use warnings; +use Test2::Tools::Tiny; + +BEGIN { skip_all "Only testing on 5.18+" if $] < 5.018 } + +require Test::More; +*cmp_ok = \&Test::More::cmp_ok; + +no warnings "experimental::smartmatch"; + +my $warnings = warnings { cmp_ok(1, "~~", 1) }; + +ok(!@$warnings, "Did not get any warnings"); + +done_testing; diff --git a/cpan/Test-Simple/t/Legacy/buffer.t b/cpan/Test-Simple/t/Legacy/buffer.t index 1e7b6c9e08..4829109761 100644 --- a/cpan/Test-Simple/t/Legacy/buffer.t +++ b/cpan/Test-Simple/t/Legacy/buffer.t @@ -1,6 +1,9 @@ #!/usr/bin/perl # HARNESS-NO-STREAM +use strict; +use warnings; + BEGIN { if( $ENV{PERL_CORE} ) { chdir 't'; @@ -16,7 +19,7 @@ my $T = Test::Builder->new; $T->no_ending(1); for my $num (1..10) { - $tnum = $num * 2; + my $tnum = $num * 2; pass("I'm ok"); $T->current_test($tnum); print "ok $tnum - You're ok\n"; diff --git a/cpan/Test-Simple/t/Legacy/fail-like.t b/cpan/Test-Simple/t/Legacy/fail-like.t index 4ec99aeab0..02f9539963 100644 --- a/cpan/Test-Simple/t/Legacy/fail-like.t +++ b/cpan/Test-Simple/t/Legacy/fail-like.t @@ -16,6 +16,7 @@ BEGIN { # This tests against that. use strict; +use warnings; # Can't use Test.pm, that's a 5.005 thing. @@ -58,14 +59,14 @@ ERR } { - # line 62 + # line 63 like("foo", "not a regex"); $TB->is_eq($out->read, <<OUT); not ok 2 OUT $TB->is_eq($err->read, <<OUT); -# Failed test at $0 line 62. +# Failed test at $0 line 63. # 'not a regex' doesn't look much like a regex to me. OUT diff --git a/cpan/Test-Simple/t/Legacy/is_deeply_fail.t b/cpan/Test-Simple/t/Legacy/is_deeply_fail.t index 21efe87a25..c43b3a2e12 100644 --- a/cpan/Test-Simple/t/Legacy/is_deeply_fail.t +++ b/cpan/Test-Simple/t/Legacy/is_deeply_fail.t @@ -11,6 +11,7 @@ BEGIN { } use strict; +use warnings; use Test::Builder; require Test::Simple::Catch; diff --git a/cpan/Test-Simple/t/Legacy/todo.t b/cpan/Test-Simple/t/Legacy/todo.t index 7d28846857..c5e5a232cf 100644 --- a/cpan/Test-Simple/t/Legacy/todo.t +++ b/cpan/Test-Simple/t/Legacy/todo.t @@ -9,10 +9,13 @@ BEGIN { use Test::More; +use strict; +use warnings; + plan tests => 36; -$Why = 'Just testing the todo interface.'; +my $Why = 'Just testing the todo interface.'; my $is_todo; TODO: { diff --git a/cpan/Test-Simple/t/Test2/modules/API/InterceptResult.t b/cpan/Test-Simple/t/Test2/modules/API/InterceptResult.t new file mode 100644 index 0000000000..4e9628fb01 --- /dev/null +++ b/cpan/Test-Simple/t/Test2/modules/API/InterceptResult.t @@ -0,0 +1,302 @@ +use strict; +use warnings; + +use Test::Builder; +use Test2::Tools::Tiny; +use Test2::API::InterceptResult; +use Scalar::Util qw/reftype/; +use Test2::API qw/intercept context/; + +my $CLASS = 'Test2::API::InterceptResult'; + +tests construction => sub { + my $one = $CLASS->new('a'); + ok($one->isa($CLASS), "Got an instance"); + is(reftype($one), 'ARRAY', "Blessed arrayref"); + is_deeply($one, ['a'], "Ref looks good."); + + my $two = $CLASS->new_from_ref(['a']); + ok($two->isa($CLASS), "Got an instance"); + is(reftype($two), 'ARRAY', "Blessed arrayref"); + is_deeply($two, ['a'], "Ref looks good."); + + my $three = $two->clone; + ok($three->isa($CLASS), "Got an instance"); + is(reftype($three), 'ARRAY', "Blessed arrayref"); + is_deeply($three, ['a'], "Ref looks good."); + + push @$two => 'b'; + is_deeply($two, ['a', 'b'], "Modified two"); + is_deeply($three, ['a'], "three was not changed"); + + my $four = intercept { + ok(1, "Pass"); + }; + + ok($four->isa($CLASS), "Intercept returns an instance"); +}; + +tests event_list => sub { + my $one = $CLASS->new('a', 'b'); + is_deeply([$one->event_list], ['a', 'b'], "event_list is essentially \@{\$self}"); +}; + +tests _upgrade => sub { + require Test2::Event::Pass; + my $event = Test2::Event::Pass->new(name => 'soup for you', trace => {frame => ['foo', 'foo.pl', 42]}); + ok($event->isa('Test2::Event'), "Start with an event"); + + my $one = $CLASS->new; + my $up = $one->_upgrade($event); + ok($up->isa('Test2::API::InterceptResult::Event'), "Upgraded the event"); + is($up->result_class, $CLASS, "set the result class"); + + is_deeply($event->facet_data, $up->facet_data, "Facet data is identical"); + + $up->facet_data->{trace}->{frame}->[2] = 43; + is($up->trace_line, 43, "Modified the facet data in the upgraded clone"); + is($event->facet_data->{trace}->{frame}->[2], 42, "Did nto modify the original"); + + my $up2 = $one->_upgrade($up); + is("$up2", "$up", "Returned the ref unmodified because it is already an upgraded item"); + + require Test2::Event::V2; + my $subtest = 'Test2::Event::V2'->new( + trace => {frame => ['foo', 'foo.pl', 42]}, + assert => {pass => 1, details => 'pass'}, + parent => { + hid => 1, + children => [ $event ], + }, + ); + + my $subup = $one->_upgrade($subtest); + ok($subup->the_subtest->{children}->isa($CLASS), "Blessed subtest subevents"); + ok( + $subup->the_subtest->{children}->[0]->isa('Test2::API::InterceptResult::Event'), + "Upgraded the children" + ); +}; + +tests hub => sub { + my $one = intercept { + ok(1, "pass"); + ok(0, "fail"); + plan 2; + }; + + my $hub = $one->hub; + ok($hub->isa('Test2::Hub'), "Hub is a proper instance"); + ok($hub->check_plan, "Had a plan and followed it"); + is($hub->count, 2, "saw both events"); + is($hub->failed, 1, "saw a failure"); + ok($hub->ended, "Hub ended"); + + is_deeply( + $one->state, + { + count => 2, + failed => 1, + is_passing => 0, + plan => 2, + bailed_out => undef, + skip_reason => undef, + follows_plan => 1, + }, + "Got the hub state" + ); +}; + +tests upgrade => sub { + my $one = intercept { + require Test::More; + Test::More::ok(1, "pass"); + Test::More::ok(1, "pass"); + }; + + ok($one->[0]->isa('Test2::Event::Ok'), "Original event is not upgraded 0"); + ok($one->[1]->isa('Test2::Event::Ok'), "Original event is not upgraded 1"); + + my $two = $one->upgrade; + ok($one->[0]->isa('Test2::Event::Ok'), "Did not modify original 0"); + ok($one->[0]->isa('Test2::Event::Ok'), "Did not modify original 1"); + ok($two->[0]->isa('Test2::API::InterceptResult::Event'), "Upgraded copy 0"); + ok($two->[1]->isa('Test2::API::InterceptResult::Event'), "Upgraded copy 1"); + + my $three = $two->upgrade; + ok("$two->[0]" ne "$three->[0]", "Upgrade on an already upgraded instance returns copies of the events, not originals"); + + like( + exception { $one->upgrade() }, + qr/Called a method that creates a new instance in void context/, + "Calling upgrade() without keeping the result is a bug" + ); + + $one->upgrade(in_place => 1); + ok($one->[0]->isa('Test2::API::InterceptResult::Event'), "Upgraded in place 0"); + ok($one->[1]->isa('Test2::API::InterceptResult::Event'), "Upgraded in place 1"); +}; + +tests squash_info => sub { + my $one = intercept { + diag "isolated 1"; + note "isolated 2"; + sub { + my $ctx = context(); + diag "inline 1"; + note "inline 2"; + $ctx->fail; + diag "inline 3"; + note "inline 4"; + $ctx->release; + }->(); + diag "isolated 3"; + note "isolated 4"; + }; + + my $new = $one->squash_info; + $one->squash_info(in_place => 1); + is_deeply( + $new, + $one, + "Squash and squash in place produce the same result" + ); + + is(@$one, 5, "5 events after squash"); + is_deeply([$one->[0]->info_messages], ['isolated 1'], "First event not modified"); + is_deeply([$one->[1]->info_messages], ['isolated 2'], "Second event not modified"); + is_deeply([$one->[3]->info_messages], ['isolated 3'], "second to last event not modified"); + is_deeply([$one->[4]->info_messages], ['isolated 4'], "last event not modified"); + is_deeply( + [$one->[2]->info_messages], + [ + 'inline 1', + 'inline 2', + 'inline 3', + 'inline 4', + ], + "Assertion collected info generated in the same context" + ); + ok($one->[2]->has_assert, "Assertion is still an assertion"); + + + my $two = intercept { + + }; +}; + +tests messages => sub { + my $one = intercept { + note "foo"; + diag "bar"; + + ok(1); + + sub { + my $ctx = context(); + + $ctx->send_ev2( + errors => [ + {tag => 'error', details => "Error 1" }, + {tag => 'error', details => "Error 2" }, + ], + info => [ + {tag => 'DIAG', details => 'Diag 1'}, + {tag => 'DIAG', details => 'Diag 2'}, + {tag => 'NOTE', details => 'Note 1'}, + {tag => 'NOTE', details => 'Note 2'}, + ], + ); + + $ctx->release; + }->(); + + note "baz"; + diag "bat"; + }; + + is_deeply( + $one->diag_messages, + ['bar', 'Diag 1', 'Diag 2', 'bat'], + "Got diags" + ); + + is_deeply( + $one->note_messages, + ['foo', 'Note 1', 'Note 2', 'baz'], + "Got Notes" + ); + + is_deeply( + $one->error_messages, + ['Error 1', 'Error 2'], + "Got errors" + ); +}; + +tests grep => sub { + my $one = intercept { + ok(1), # 0 + note "A Note"; # 1 + diag "A Diag"; # 2 + tests foo => sub { ok(1) }; # 3 + + sub { # 4 + my $ctx = context(); + $ctx->send_ev2(errors => [{tag => 'error', details => "Error 1"}]); + $ctx->release; + }->(); # 4 + + plan 2; # 5 + }; + + $one->upgrade(in_place => 1); + + is_deeply($one->asserts, [$one->[0], $one->[3]], "Got the asserts"); + is_deeply($one->subtests, [$one->[3]], "Got the subtests"); + is_deeply($one->diags, [$one->[2]], "Got the diags"); + is_deeply($one->notes, [$one->[1]], "Got the notes"); + is_deeply($one->errors, [$one->[4]], "Got the errors"); + is_deeply($one->plans, [$one->[5]], "Got the plans"); + + $one->asserts(in_place => 1); + is(@$one, 2, "2 events"); + ok($_->has_assert, "Is an assert") for @$one; +}; + +tests map => sub { + my $one = intercept { ok(1); ok(2) }; + $one->upgrade(in_place => 1); + + is_deeply( + $one->flatten, + [ $one->[0]->flatten, $one->[1]->flatten ], + "Flattened both events" + ); + + is_deeply( + $one->briefs, + [ $one->[0]->brief, $one->[1]->brief ], + "Brief of both events" + ); + + is_deeply( + $one->summaries, + [ $one->[0]->summary, $one->[1]->summary ], + "Summaries of both events" + ); + + my $two = intercept { + tests foo => sub { ok(1) }; + ok(1); + tests bar => sub { ok(1) }; + }->upgrade; + + is_deeply( + $two->subtest_results, + [ $two->[0]->subtest_result, $two->[2]->subtest_result ], + "Got subtest results" + ); +}; + +done_testing; diff --git a/cpan/Test-Simple/t/Test2/modules/API/InterceptResult/Event.t b/cpan/Test-Simple/t/Test2/modules/API/InterceptResult/Event.t new file mode 100644 index 0000000000..e1b2716474 --- /dev/null +++ b/cpan/Test-Simple/t/Test2/modules/API/InterceptResult/Event.t @@ -0,0 +1,950 @@ +use strict; +use warnings; + +use Test2::Tools::Tiny; +use Test2::API::InterceptResult::Event; + +my $CLASS = 'Test2::API::InterceptResult::Event'; + +tests facet_map => sub { + ok(!$CLASS->can('plugins'), "Did not expose 'plugins' sub"); + + my $fm = $CLASS->facet_map; + + is_deeply($fm->{__GENERIC__}, {class => 'Test2::API::InterceptResult::Facet', loaded => 1}, "Generic '__GENERIC__'"); + + is_deeply($CLASS->facet_info('about'), {class => 'Test2::EventFacet::About', list => 0, loaded => 1}, "Found 'about' facet"); + is_deeply($CLASS->facet_info('amnesty'), {class => 'Test2::EventFacet::Amnesty', list => 1, loaded => 1}, "Found 'amnesty' facet"); + is_deeply($CLASS->facet_info('assert'), {class => 'Test2::EventFacet::Assert', list => 0, loaded => 1}, "Found 'assert' facet"); + is_deeply($CLASS->facet_info('control'), {class => 'Test2::EventFacet::Control', list => 0, loaded => 1}, "Found 'control' facet"); + is_deeply($CLASS->facet_info('errors'), {class => 'Test2::EventFacet::Error', list => 1, loaded => 1}, "Found 'errors' facet"); + is_deeply($CLASS->facet_info('hubs'), {class => 'Test2::EventFacet::Hub', list => 1, loaded => 1}, "Found 'hubs' facet"); + is_deeply($CLASS->facet_info('info'), {class => 'Test2::EventFacet::Info', list => 1, loaded => 1}, "Found 'info' facet"); + is_deeply($CLASS->facet_info('meta'), {class => 'Test2::EventFacet::Meta', list => 0, loaded => 1}, "Found 'meta' facet"); + is_deeply($CLASS->facet_info('parent'), {class => 'Test2::EventFacet::Parent', list => 0, loaded => 1}, "Found 'parent' facet"); + is_deeply($CLASS->facet_info('plan'), {class => 'Test2::EventFacet::Plan', list => 0, loaded => 1}, "Found 'plan' facet"); + is_deeply($CLASS->facet_info('render'), {class => 'Test2::EventFacet::Render', list => 1, loaded => 1}, "Found 'render' facet"); + is_deeply($CLASS->facet_info('trace'), {class => 'Test2::EventFacet::Trace', list => 0, loaded => 1}, "Found 'trace' facet"); +}; + +tests init => sub { + # This is just here to make sure the later test is meaningful. If this + # starts to fail it probably means this test needs to be changed. + ok(!$INC{'Test2/API/InterceptResult.pm'}, "Did not load result class yes"); + my $one = $CLASS->new(); + ok($one->isa($CLASS), "Got an instance"); + is_deeply($one->facet_data, {}, "Got empty data"); + is($one->result_class, 'Test2::API::InterceptResult', "Got default result class"); + ok($INC{'Test2/API/InterceptResult.pm'}, "Loaded result class"); + + like( + exception { $CLASS->new(facet_data => {assert => [{}]}) }, + qr/^Facet 'assert' is an only-one facet, but got 'ARRAY' instead of a hashref/, + "Check list vs non-list when we can (check for single)" + ); + + like( + exception { $CLASS->new(facet_data => {info => {}}) }, + qr/^Facet 'info' is a list facet, but got 'HASH' instead of an arrayref/, + "Check list vs non-list when we can (check for list)" + ); + + like( + exception { $CLASS->new(facet_data => {info => [{},[]]}) }, + qr/Got item type 'ARRAY' in list-facet 'info', all items must be hashrefs/, + "Check each item in a list facet is a hashref" + ); + + my $two = $CLASS->new(facet_data => {assert => {}, info => [{}]}); + ok($two->isa($CLASS), "Got an instance with some actual facets"); +}; + +tests facet => sub { + my $one = $CLASS->new(facet_data => { + other_single => {}, + other_list => [{}], + assert => {pass => 1, details => 'xxx'}, + info => [ + {tag => 'DIAG', details => 'xxx'}, + {tag => 'NOTE', details => 'xxx'}, + ], + }); + + ok(($one->facet('assert'))[0]->isa('Test2::EventFacet::Assert'), "Bless the assert facet"); + ok(($one->facet('other_list'))[0]->isa('Test2::EventFacet'), "Bless the other_list as generic"); + ok(($one->facet('other_single'))[0]->isa('Test2::EventFacet'), "Bless the other_single as generic"); + ok(($one->facet('other_list'))[0]->isa('Test2::API::InterceptResult::Facet'), "Bless the other_list as generic"); + ok(($one->facet('other_single'))[0]->isa('Test2::API::InterceptResult::Facet'), "Bless the other_single as generic"); + + is(($one->facet('other_list'))[0]->foo, undef, "Generic gives us autoload for field access"); + + is_deeply( + [$one->facet('xxx')], + [], + "Got an empty list when facet is not present", + ); + + is_deeply( + [$one->facet('assert')], + [{pass => 1, details => 'xxx'}], + "One item list for non-list facets", + ); + + is_deeply( + [$one->facet('info')], + [ + {tag => 'DIAG', details => 'xxx'}, + {tag => 'NOTE', details => 'xxx'}, + ], + "Full list for list facets" + ); +}; + +tests the_facet => sub { + my $one = $CLASS->new(facet_data => { + other_single => {}, + other_list => [{}], + assert => {pass => 1, details => 'xxx'}, + info => [ + {tag => 'DIAG', details => 'xxx'}, + {tag => 'NOTE', details => 'xxx'}, + ], + }); + + ok($one->the_facet('assert')->isa('Test2::EventFacet::Assert'), "Bless the assert facet"); + ok($one->the_facet('other_list')->isa('Test2::EventFacet'), "Bless the other_list as generic"); + ok($one->the_facet('other_single')->isa('Test2::EventFacet'), "Bless the other_single as generic"); + ok($one->the_facet('other_list')->isa('Test2::API::InterceptResult::Facet'), "Bless the other_list as generic"); + ok($one->the_facet('other_single')->isa('Test2::API::InterceptResult::Facet'), "Bless the other_single as generic"); + + is($one->the_facet('other_list')->foo, undef, "Generic gives us autoload for field access"); + + is_deeply( + $one->the_facet('xxx'), + undef, + "Got an undef when facet is not present", + ); + + is_deeply( + $one->the_facet('assert'), + {pass => 1, details => 'xxx'}, + "One item", + ); + + like( + exception { $one->the_facet('info') }, + qr/'the_facet' called for facet 'info', but 'info' has '2' items/, + "the_facet dies if there are more than one" + ); +}; + +tests causes_failure => sub { + my $one = $CLASS->new(facet_data => { assert => {pass => 1, details => 'xxx'}}); + ok(!$one->causes_fail, "No failure for passing test"); + ok(!$one->causes_failure, "No failure for passing test (alt name)"); + + my $two = $CLASS->new(facet_data => { assert => {pass => 0, details => 'xxx'}}); + ok($two->causes_fail, "Failure for failing test"); + ok($two->causes_failure, "Failure for failing test (alt name)"); + + my $three = $CLASS->new( + facet_data => { + assert => {pass => 0, details => 'xxx'}, + amnesty => [{tag => 'TODO', details => 'a todo'}], + } + ); + ok(!$three->causes_fail, "No failure for failing test (with amnesty)"); + ok(!$three->causes_failure, "No failure for failing test (with amnesty) (alt name)"); +}; + +tests trace => sub { + my $one = $CLASS->new; + is($one->trace, undef, "No trace to get"); + is($one->frame, undef, "No frame to get"); + is($one->trace_details, undef, "No trace to get trace_details from"); + is($one->trace_file, undef, "No trace to get trace_file from"); + is($one->trace_line, undef, "No trace to get trace_line from"); + is($one->trace_package, undef, "No trace to get trace_package from"); + is($one->trace_subname, undef, "No trace to get trace_subname from"); + is($one->trace_tool, undef, "No trace to get trace_tool from"); + + my $two = $CLASS->new( + facet_data => { + trace => { + frame => [], + details => 'xxx', + pid => 1, + tid => 1, + }, + } + ); + is_deeply($two->the_trace, {details => 'xxx', frame => [], pid => 1, tid => 1}, "Got trace"); + is_deeply([$two->trace], [{details => 'xxx', frame => [], pid => 1, tid => 1}], "Got trace"); + is($two->trace_details, 'xxx', "get trace_details"); + is_deeply($two->frame, [], "No frame to get"); + is($two->trace_file, undef, "No frame to get trace_file from"); + is($two->trace_line, undef, "No frame to get trace_line from"); + is($two->trace_package, undef, "No frame to get trace_package from"); + is($two->trace_subname, undef, "No frame to get trace_subname from"); + is($two->trace_tool, undef, "No frame to get trace_tool from"); + + my $three = $CLASS->new( + facet_data => { + trace => { + details => 'xxx', + frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'ok'], + pid => 1, + tid => 1, + }, + } + ); + is_deeply($three->the_trace, {details => 'xxx', frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'ok'], pid => 1, tid => 1}, "Got trace"); + is($three->trace_details, 'xxx', "get trace_details"); + is_deeply($three->frame, ['Foo::Bar', 'Foo/Bar.pm', 42, 'ok'], "Got frame"); + is($three->trace_file, 'Foo/Bar.pm', "Got trace_file"); + is($three->trace_line, 42, "Got trace_line"); + is($three->trace_package, 'Foo::Bar', "Got trace_package"); + is($three->trace_subname, 'ok', "Got trace_subname"); + is($three->trace_tool, 'ok', "Got trace_tool"); +}; + +tests brief => sub { + my $one = $CLASS->new( + facet_data => { + control => {halt => 1, details => "some reason to bail out"}, + errors => [{tag => 'ERROR', details => "some kind of error"}], + assert => {pass => 1, details => "some passing assert"}, + plan => {count => 42}, + } + ); + + is($one->brief, $one->bailout_brief, "bail-out is used when present"); + delete $one->{facet_data}->{control}; + + is($one->brief, $one->error_brief, "error is next"); + delete $one->{facet_data}->{errors}; + + is($one->brief, $one->assert_brief, "assert is next"); + delete $one->{facet_data}->{assert}; + + is($one->brief, $one->plan_brief, "plan is last"); + delete $one->{facet_data}->{plan}; + + is_deeply( + [$one->brief], + [], + "Empty list if no briefs are available." + ); +}; + +tests summary => sub { + my $one = $CLASS->new(); + + is_deeply( + $one->summary, + { + brief => '', + + causes_failure => 0, + + trace_line => undef, + trace_file => undef, + trace_tool => undef, + trace_details => undef, + + facets => [], + }, + "Got summary for empty event" + ); + + my $two = $CLASS->new(facet_data => { + assert => {pass => 0}, + trace => {frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'ok'], details => 'a trace'}, + parent => {}, + plan => {count => 1}, + control => {halt => 1, details => "bailout wins"}, + info => [ + {tag => 'DIAG', details => 'diag 1'}, + {tag => 'DIAG', details => 'diag 2'}, + {tag => 'NOTE', details => 'note 1'}, + {tag => 'NOTE', details => 'note 2'}, + {tag => 'OTHER', details => 'other 1'}, + {tag => 'OTHER', details => 'other 2'}, + ], + }); + + is_deeply( + $two->summary, + { + brief => 'BAILED OUT: bailout wins', + + causes_failure => 1, + + trace_line => 42, + trace_file => 'Foo/Bar.pm', + trace_tool => 'ok', + trace_details => 'a trace', + + facets => [qw{ assert control info parent plan trace }], + }, + "Got summary for lots" + ); + + is_deeply( + $two->summary(fields => [qw/trace_line trace_file/]), + { + trace_line => 42, + trace_file => 'Foo/Bar.pm', + }, + "Got summary, specific fields" + ); + + is_deeply( + $two->summary(remove => [qw/brief facets/]), + { + causes_failure => 1, + + trace_line => 42, + trace_file => 'Foo/Bar.pm', + trace_tool => 'ok', + trace_details => 'a trace', + }, + "Got summary, removed some fields" + ); +}; + +tests assert => sub { + my $one = $CLASS->new(); + ok(!$one->has_assert, "Not an assert"); + is_deeply([$one->assert], [], "empty list for assert()"); + is_deeply([$one->assert_brief], [], "empty list for assert_brief()"); + + my $two = $CLASS->new(facet_data => {assert => {pass => 1, details => 'foo'}}); + ok($two->has_assert, "Is an assert"); + is_deeply([$two->assert], [{pass => 1, details => 'foo'}], "got assert item"); + is($two->assert_brief, "PASS", "got PASS for assert_brief()"); + + my $three = $CLASS->new(facet_data => { + assert => {pass => 0, details => 'foo'}, + amnesty => [ + {tag => 'TODO', details => 'todo 1'}, + {tag => 'SKIP', details => 'skip 1'}, + {tag => 'OOPS', details => 'oops 1'}, + {tag => 'TODO', details => 'todo 2'}, + {tag => 'SKIP', details => 'skip 2'}, + {tag => 'OOPS', details => 'oops 2'}, + ], + }); + ok($three->has_assert, "Is an assert"); + is_deeply([$three->assert], [{pass => 0, details => 'foo'}], "got assert item"); + is($three->assert_brief, "FAIL with amnesty", "Fail with amnesty"); + + my $four = $CLASS->new(facet_data => { + assert => {pass => 0, details => 'foo'}, + amnesty => [ + {tag => 'TODO'}, + {tag => 'SKIP'}, + {tag => 'OOPS'}, + ], + }); + ok($four->has_assert, "Is an assert"); + is_deeply([$four->assert], [{pass => 0, details => 'foo'}], "got assert item"); + is($four->assert_brief, "FAIL with amnesty", "Fail with amnesty"); +}; + +tests subtest => sub { + my $one = $CLASS->new(); + ok(!$one->has_subtest, "Not a subtest"); + is_deeply([$one->subtest], [], "subtest() returns empty list"); + is_deeply([$one->subtest_result], [], "subtest_result returns an empty list"); + + my $two = $CLASS->new( + facet_data => { + parent => { + hid => '1234', + children => [], + state => { + bailed_out => undef, + count => 5, + failed => 1, + follows_plan => 1, + is_passing => 0, + nested => 1, + skip_reason => undef, + }, + }, + } + ); + + ok($two->has_subtest, "has a subtest"); + is_deeply([$two->subtest], [$two->facet_data->{parent}], "subtest() returns 1 item list"); + + my $res = $two->subtest_result; + ok($res->isa('Test2::API::InterceptResult'), "Got a result instance"); +}; + +tests flatten => sub { + my $one = $CLASS->new(); + is_deeply( + $one->flatten, + { + causes_failure => 0, + trace_file => undef, + trace_line => undef + }, + "Empty event flattens to almost nothing" + ); + + my $two = $CLASS->new( + facet_data => { + hubs => [{details => "DO NOT SHOW"}], + meta => {details => "DO NOT SHOW"}, + control => {details => "A control"}, + assert => {pass => 1, details => "Test Name"}, + + trace => { + frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'Test2::Tools::Tiny::ok'], + details => "Trace Details", + }, + + parent => { + details => "A Subtest", + children => [ + $CLASS->new(facet_data => {assert => {pass => 1, details => 'nested assertion'}}), + $CLASS->new(facet_data => {plan => {count => 1}}), + ], + }, + + errors => [ + {tag => 'error', fail => 0, details => "not a fatal error"}, + {tag => 'error', fail => 1, details => "a fatal error"}, + ], + + info => [ + {tag => 'DIAG', details => 'diag 1'}, + {tag => 'DIAG', details => 'diag 2'}, + {tag => 'NOTE', details => 'note 1'}, + {tag => 'NOTE', details => 'note 2'}, + {tag => 'INFO', details => 'info 1'}, + {tag => 'INFO', details => 'info 2'}, + ], + amnesty => [ + {tag => 'TODO', details => 'todo 1'}, + {tag => 'TODO', details => 'todo 2'}, + {tag => 'SKIP', details => 'skip 1'}, + {tag => 'SKIP', details => 'skip 2'}, + {tag => 'OKOK', details => 'okok 1'}, + {tag => 'OKOK', details => 'okok 2'}, + ], + + other_single => {details => 'other single'}, + other_multi => [{details => 'other multi'}], + }, + ); + + is_deeply( + $two->flatten(include_subevents => 1), + { + # Summaries + causes_failure => 0, + trace_details => 'Trace Details', + trace_file => 'Foo/Bar.pm', + trace_line => 42, + + # Info + diag => ['diag 1', 'diag 2'], + info => ['info 1', 'info 2'], + note => ['note 1', 'note 2'], + + # Amnesty + okok => ['okok 1', 'okok 2'], + skip => ['skip 1', 'skip 2'], + todo => ['todo 1', 'todo 2'], + + # Errors + error => ['not a fatal error', 'FATAL: a fatal error'], + + # Assert + name => 'Test Name', + pass => 1, + + # Control + control => 'A control', + + # Other + other_multi => ['other multi'], + other_single => 'other single', + + # Subtest related + subtest => { + follows_plan => 1, + is_passing => 1, + count => 1, + failed => 0, + plan => 1, + }, + + subevents => [ + { + name => 'nested assertion', + trace_line => undef, + causes_failure => 0, + pass => 1, + trace_file => undef, + }, + { + trace_file => undef, + plan => '1', + trace_line => undef, + causes_failure => 0, + } + ], + }, + "Very full flattening, with subevents" + ); + + is_deeply( + $two->flatten(), + { + # Summaries + causes_failure => 0, + trace_details => 'Trace Details', + trace_file => 'Foo/Bar.pm', + trace_line => 42, + + # Info + diag => ['diag 1', 'diag 2'], + info => ['info 1', 'info 2'], + note => ['note 1', 'note 2'], + + # Amnesty + okok => ['okok 1', 'okok 2'], + skip => ['skip 1', 'skip 2'], + todo => ['todo 1', 'todo 2'], + + # Errors + error => ['not a fatal error', 'FATAL: a fatal error'], + + # Assert + name => 'Test Name', + pass => 1, + + # Control + control => 'A control', + + # Other + other_multi => ['other multi'], + other_single => 'other single', + + # Subtest related + subtest => { + follows_plan => 1, + is_passing => 1, + count => 1, + failed => 0, + plan => 1, + }, + }, + "Very full flattening, no subevents" + ); + + my $three = $CLASS->new( + facet_data => { + trace => { + frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'Test2::Tools::Tiny::ok'], + }, + + control => {halt => 1, details => "need to bail dude!"}, + + amnesty => [{tag => 'TODO', details => 'todo 1'}], + }, + ); + + is_deeply( + $three->flatten(include_subevents => 1), + { + # Summaries + causes_failure => 0, + + trace_file => 'Foo/Bar.pm', + trace_line => 42, + + bailed_out => "need to bail dude!", + + # Amnesty does not show without an assert or parent + }, + "Bail-out test" + ); + + my $four = $CLASS->new( + facet_data => { + trace => {frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'Test2::Tools::Tiny::ok']}, + errors => [{tag => 'ERROR', details => 'an error', fail => 1}], + amnesty => [{tag => 'TODO', details => 'todo 1'}], + }, + ); + + is_deeply( + $four->flatten(), + { + # Summaries + causes_failure => 0, + + trace_file => 'Foo/Bar.pm', + trace_line => 42, + + todo => ['todo 1'], + error => ['FATAL: an error'], + }, + "Include amnesty when there is a fatal error" + ); + + is_deeply( + $four->flatten(fields => [qw/trace_file trace_line/]), + { + trace_file => 'Foo/Bar.pm', + trace_line => 42, + }, + "Filtered to only specific fields" + ); + + is_deeply( + $four->flatten(remove => [qw/todo error/]), + { + # Summaries + causes_failure => 0, + + trace_file => 'Foo/Bar.pm', + trace_line => 42, + }, + "Remove specific fields" + ); + +}; + +tests bailout => sub { + my $one = $CLASS->new(); + ok(!$one->has_bailout, "No bailout"); + is_deeply([$one->bailout], [], "no bailout"); + is_deeply([$one->bailout_brief], [], "no bailout"); + is_deeply([$one->bailout_reason], [], "no bailout"); + + my $two = $CLASS->new( + facet_data => { + trace => { + frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'Test2::Tools::Tiny::ok'], + }, + + control => {halt => 1, details => "need to bail dude!"}, + }, + ); + + ok($two->has_bailout, "did bail out"); + is_deeply([$two->bailout], [{halt => 1, details => "need to bail dude!"}], "Got the bailout"); + is_deeply([$two->bailout_brief], ["BAILED OUT: need to bail dude!"], "Got the bailout brief"); + is_deeply([$two->bailout_reason], ["need to bail dude!"], "Got the bailout reason"); +}; + +tests plan => sub { + my $one = $CLASS->new; + ok(!$one->has_plan, "No plan"); + is_deeply([$one->plan], [], "No plan"); + is_deeply([$one->plan_brief], [], "No plan"); + + my $two = $CLASS->new(facet_data => {plan => { count => 42 }}); + ok($two->has_plan, "Got a plan"); + is_deeply([$two->plan], [{ count => 42 }], "Got the plan facet"); + is_deeply([$two->plan_brief], ["PLAN 42"], "Got the brief"); + + $two->{facet_data}->{plan}->{details} = "foo bar baz"; + is_deeply([$two->plan_brief], ["PLAN 42: foo bar baz"], "Got the brief with details"); + + $two->{facet_data}->{plan}->{count} = 0; + is_deeply([$two->plan_brief], ["SKIP ALL: foo bar baz"], "Got the skip form no count with details"); + + $two->{facet_data}->{plan}->{count} = 1; + $two->{facet_data}->{plan}->{skip} = 1; + is_deeply([$two->plan_brief], ["SKIP ALL: foo bar baz"], "Got the skip with details"); + + $two->{facet_data}->{plan}->{skip} = 0; + $two->{facet_data}->{plan}->{none} = 1; + is_deeply([$two->plan_brief], ["NO PLAN: foo bar baz"], "Got the 'NO PLAN' with details"); +}; + +tests amnesty => sub { + my $one = $CLASS->new(); + + ok(!$one->has_amnesty, "No amnesty"); + ok(!$one->has_todos, "No todos"); + ok(!$one->has_skips, "No skips"); + ok(!$one->has_other_amnesty, "No other amnesty"); + + is_deeply([$one->amnesty], [], "amnesty list is empty"); + is_deeply([$one->todos], [], "todos list is empty"); + is_deeply([$one->skips], [], "skips list is empty"); + is_deeply([$one->other_amnesty], [], "other_amnesty list is empty"); + + is_deeply([$one->amnesty_reasons], [], "amnesty_reasons list is empty"); + is_deeply([$one->todo_reasons], [], "todo_reasons list is empty"); + is_deeply([$one->skip_reasons], [], "skip_reasons list is empty"); + is_deeply([$one->other_amnesty_reasons], [], "other_amnesty_reasons list is empty"); + + my $two = $CLASS->new( + facet_data => { + amnesty => [ + {tag => 'TODO', details => 'todo 1'}, + {tag => 'TODO', details => 'todo 2'}, + {tag => 'SKIP', details => 'skip 1'}, + {tag => 'SKIP', details => 'skip 2'}, + {tag => 'OKOK', details => 'okok 1'}, + {tag => 'OKOK', details => 'okok 2'}, + ], + }, + ); + + ok($two->has_amnesty, "amnesty"); + ok($two->has_todos, "todos"); + ok($two->has_skips, "skips"); + ok($two->has_other_amnesty, "other amnesty"); + + is_deeply( + [$two->amnesty], + [ + {tag => 'TODO', details => 'todo 1'}, + {tag => 'TODO', details => 'todo 2'}, + {tag => 'SKIP', details => 'skip 1'}, + {tag => 'SKIP', details => 'skip 2'}, + {tag => 'OKOK', details => 'okok 1'}, + {tag => 'OKOK', details => 'okok 2'}, + ], + "amnesty list", + ); + is_deeply( + [$two->todos], + [ + {tag => 'TODO', details => 'todo 1'}, + {tag => 'TODO', details => 'todo 2'}, + ], + "todos list", + ); + is_deeply( + [$two->skips], + [ + {tag => 'SKIP', details => 'skip 1'}, + {tag => 'SKIP', details => 'skip 2'}, + ], + "skips list", + ); + is_deeply( + [$two->other_amnesty], + [ + {tag => 'OKOK', details => 'okok 1'}, + {tag => 'OKOK', details => 'okok 2'}, + ], + "other_amnesty list", + ); + + is_deeply( + [$two->amnesty_reasons], + [ + 'todo 1', + 'todo 2', + 'skip 1', + 'skip 2', + 'okok 1', + 'okok 2', + ], + "amnesty_reasons list is empty" + ); + is_deeply( + [$two->todo_reasons], + [ + 'todo 1', + 'todo 2', + ], + "todo_reasons list is empty" + ); + is_deeply( + [$two->skip_reasons], + [ + 'skip 1', + 'skip 2', + ], + "skip_reasons list is empty" + ); + is_deeply( + [$two->other_amnesty_reasons], + [ + 'okok 1', + 'okok 2', + ], + "other_amnesty_reasons list is empty" + ); +}; + +tests errors => sub { + my $one = $CLASS->new(); + ok(!$one->has_errors, "No errors"); + is_deeply([$one->errors], [], "No errors"); + is_deeply([$one->error_messages], [], "No errors"); + is_deeply([$one->error_brief], [], "No errors"); + + my $two = $CLASS->new(facet_data => { + errors => [{tag => 'error', details => 'a non fatal error'}], + }); + ok($two->has_errors, "Got errors"); + is_deeply([$two->errors], [{tag => 'error', details => 'a non fatal error'}], "Got the error"); + is_deeply([$two->error_messages], ['a non fatal error'], "Got the message"); + is_deeply([$two->error_brief], ['ERROR: a non fatal error'], "Got the brief"); + + my $three = $CLASS->new(facet_data => { + errors => [{tag => 'error', details => "a non fatal\nerror"}], + }); + ok($three->has_errors, "Got errors"); + is_deeply([$three->errors], [{tag => 'error', details => "a non fatal\nerror"}], "Got the error"); + is_deeply([$three->error_messages], ["a non fatal\nerror"], "Got the message"); + is_deeply([$three->error_brief], ["ERROR: a non fatal [...]"], "Got the brief"); + + my $four = $CLASS->new(facet_data => { + errors => [ + {tag => 'error', details => "a fatal error", fail => 1}, + {tag => 'error', details => "a non fatal error", fail => 0}, + ], + }); + + ok($four->has_errors, "Got errors"); + + is_deeply( + [$four->errors], + [ + {tag => 'error', details => "a fatal error", fail => 1}, + {tag => 'error', details => "a non fatal error", fail => 0}, + ], + "Got the error" + ); + + is_deeply( + [$four->error_messages], + [ + "a fatal error", + "a non fatal error", + ], + "Got the message" + ); + + is_deeply([$four->error_brief], ['ERRORS: a fatal error [...]'], "Got the brief"); + +}; + +tests info => sub { + my $one = $CLASS->new(); + + ok(!$one->has_info, "No info"); + ok(!$one->has_diags, "No diags"); + ok(!$one->has_notes, "No notes"); + ok(!$one->has_other_info, "No other info"); + + is_deeply([$one->info], [], "info list is empty"); + is_deeply([$one->diags], [], "diags list is empty"); + is_deeply([$one->notes], [], "notes list is empty"); + is_deeply([$one->other_info], [], "other_info list is empty"); + + is_deeply([$one->info_messages], [], "info_messages list is empty"); + is_deeply([$one->diag_messages], [], "diag_messages list is empty"); + is_deeply([$one->note_messages], [], "note_messages list is empty"); + is_deeply([$one->other_info_messages], [], "other_info_messages list is empty"); + + my $two = $CLASS->new( + facet_data => { + info => [ + {tag => 'DIAG', details => 'diag 1'}, + {tag => 'DIAG', details => 'diag 2'}, + {tag => 'NOTE', details => 'note 1'}, + {tag => 'NOTE', details => 'note 2'}, + {tag => 'INFO', details => 'info 1'}, + {tag => 'INFO', details => 'info 2'}, + ], + }, + ); + + ok($two->has_info, "info"); + ok($two->has_diags, "diags"); + ok($two->has_notes, "notes"); + ok($two->has_other_info, "other info"); + + is_deeply( + [$two->info], + [ + {tag => 'DIAG', details => 'diag 1'}, + {tag => 'DIAG', details => 'diag 2'}, + {tag => 'NOTE', details => 'note 1'}, + {tag => 'NOTE', details => 'note 2'}, + {tag => 'INFO', details => 'info 1'}, + {tag => 'INFO', details => 'info 2'}, + ], + "info list", + ); + is_deeply( + [$two->diags], + [ + {tag => 'DIAG', details => 'diag 1'}, + {tag => 'DIAG', details => 'diag 2'}, + ], + "diags list", + ); + is_deeply( + [$two->notes], + [ + {tag => 'NOTE', details => 'note 1'}, + {tag => 'NOTE', details => 'note 2'}, + ], + "notes list", + ); + is_deeply( + [$two->other_info], + [ + {tag => 'INFO', details => 'info 1'}, + {tag => 'INFO', details => 'info 2'}, + ], + "other_info list", + ); + + is_deeply( + [$two->info_messages], + [ + 'diag 1', + 'diag 2', + 'note 1', + 'note 2', + 'info 1', + 'info 2', + ], + "info_messages list is empty" + ); + is_deeply( + [$two->diag_messages], + [ + 'diag 1', + 'diag 2', + ], + "diag_messages list is empty" + ); + is_deeply( + [$two->note_messages], + [ + 'note 1', + 'note 2', + ], + "note_messages list is empty" + ); + is_deeply( + [$two->other_info_messages], + [ + 'info 1', + 'info 2', + ], + "other_info_messages list is empty" + ); +}; + +done_testing; diff --git a/cpan/Test-Simple/t/Test2/modules/API/InterceptResult/Squasher.t b/cpan/Test-Simple/t/Test2/modules/API/InterceptResult/Squasher.t new file mode 100644 index 0000000000..b84e0ff354 --- /dev/null +++ b/cpan/Test-Simple/t/Test2/modules/API/InterceptResult/Squasher.t @@ -0,0 +1,117 @@ +use strict; +use warnings; + +use Test2::Tools::Tiny; +use Test2::API::InterceptResult::Squasher; +use Test2::API::InterceptResult::Event; + +my $CLASS = 'Test2::API::InterceptResult::Squasher'; + +my $trace1 = {pid => $$, tid => 0, cid => 1, frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'ok']}; +my $trace2 = {pid => $$, tid => 0, cid => 2, frame => ['Foo::Bar', 'Foo/Bar.pm', 43, 'note']}; +my $trace3 = {pid => $$, tid => 0, cid => 3, frame => ['Foo::Bar', 'Foo/Bar.pm', 44, 'subtest']}; +my $trace4 = {pid => $$, tid => 0, cid => 4, frame => ['Foo::Bar', 'Foo/Bar.pm', 45, 'diag']}; + +my @raw = ( + # These 4 should merge + Test2::API::InterceptResult::Event->new(facet_data => { + trace => $trace1, + info => [{tag => 'DIAG', details => 'about to fail'}], + }), + Test2::API::InterceptResult::Event->new(facet_data => { + trace => $trace1, + assert => { pass => 0, details => 'fail' }, + }), + Test2::API::InterceptResult::Event->new(facet_data => { + trace => $trace1, + info => [{tag => 'DIAG', details => 'it failed'}], + }), + Test2::API::InterceptResult::Event->new(facet_data => { + trace => $trace1, + info => [{tag => 'DIAG', details => 'it failed part 2'}], + }), + + # Same trace, but should not merge as it has an assert + Test2::API::InterceptResult::Event->new(facet_data => { + trace => $trace1, + assert => { pass => 0, details => 'fail again' }, + info => [{tag => 'DIAG', details => 'it failed again'}], + }), + + # Stand alone note + Test2::API::InterceptResult::Event->new(facet_data => { + trace => $trace2, + info => [{tag => 'NOTE', details => 'Take Note!'}], + }), + + # Subtest, note, assert, diag as 3 events, should be merged + Test2::API::InterceptResult::Event->new(facet_data => { + trace => $trace3, + info => [{tag => 'NOTE', details => 'About to start subtest'}], + }), + Test2::API::InterceptResult::Event->new(facet_data => { + trace => $trace3, + assert => { pass => 0, details => 'failed subtest' }, + parent => { details => 'foo', state => {}, children => [] }, + }), + Test2::API::InterceptResult::Event->new(facet_data => { + trace => $trace3, + info => [{tag => 'DIAG', details => 'Subtest failed'}], + }), + + # Stand alone diag + Test2::API::InterceptResult::Event->new(facet_data => { + trace => $trace4, + info => [{tag => 'DIAG', details => 'Diagnosis: Murder'}], + }), +); + +my @events; +my $squasher = $CLASS->new(events => \@events); +ok($squasher->isa($CLASS), "Got an instanct"); +$squasher->process($_) for @raw; +$squasher = undef; + +is_deeply( + [map { $_->facet_data } @events], + [ + { + trace => $trace1, + assert => {pass => 0, details => 'fail'}, + info => [ + {tag => 'DIAG', details => 'about to fail'}, + {tag => 'DIAG', details => 'it failed'}, + {tag => 'DIAG', details => 'it failed part 2'}, + ], + }, + + { + trace => $trace1, + assert => {pass => 0, details => 'fail again'}, + info => [{tag => 'DIAG', details => 'it failed again'}], + }, + + { + trace => $trace2, + info => [{tag => 'NOTE', details => 'Take Note!'}], + }, + + { + trace => $trace3, + assert => {pass => 0, details => 'failed subtest'}, + parent => {details => 'foo', state => {}, children => []}, + info => [ + {tag => 'NOTE', details => 'About to start subtest'}, + {tag => 'DIAG', details => 'Subtest failed'}, + ], + }, + + { + trace => $trace4, + info => [{tag => 'DIAG', details => 'Diagnosis: Murder'}], + }, + ], + "Squashed events as expected" +); + +done_testing; diff --git a/cpan/Test-Simple/t/Test2/modules/Event/V2.t b/cpan/Test-Simple/t/Test2/modules/Event/V2.t index 5214bafd4d..9c7a52b8ad 100644 --- a/cpan/Test-Simple/t/Test2/modules/Event/V2.t +++ b/cpan/Test-Simple/t/Test2/modules/Event/V2.t @@ -47,7 +47,7 @@ is_deeply($one->trace, $trace, "Trace has all data"); $one = $CLASS->new; ok(!$one->uuid, "no uuid attribute"); -ok(!$one->about->{uuid}, "no uuid in about facet"); +ok(!($one->about && $one->about->{uuid}), "no uuid in about facet"); $one->set_uuid(123); is($one->about->{uuid}, 123, "Set uuid in about facet"); is($one->uuid, 123, "set uuid attribute"); diff --git a/cpan/Test-Simple/t/regression/862-intercept_tb_todo.t b/cpan/Test-Simple/t/regression/862-intercept_tb_todo.t new file mode 100644 index 0000000000..016f9cd459 --- /dev/null +++ b/cpan/Test-Simple/t/regression/862-intercept_tb_todo.t @@ -0,0 +1,62 @@ +use strict; +use warnings; + +use Test::More; +use Test2::API qw/intercept/; + +my $events; +{ + local $TODO = "main-outer-todo"; + + package Foo; + + our $TODO; + local $TODO = "foo-outer-todo"; + + $events = main::intercept(sub { + main::ok(1, "assertion 1"); + + { + local $main::TODO = "main-inner-todo"; + main::ok(1, "assertion 2"); + } + + { + local $Foo::TODO = "foo-inner-todo"; + main::ok(1, "assertion 3"); + } + + main::ok(1, "assertion 4"); + }); + + # Cannot use intercept, so make a failing test, the overall test file + # should still pass because this is todo. If this is not todo we know we + # broke something by the test failing overall. + main::ok(0, "Verifying todo, this should be a failed todo test"); +} + +@$events = grep { $_->facet_data->{assert} } @$events; + +ok(!$events->[0]->facet_data->{amnesty}, "No amnesty for the first event, \$TODO was cleaned"); + +is_deeply( + $events->[1]->facet_data->{amnesty}, + [{ + tag => 'TODO', + details => 'main-inner-todo', + }], + "The second event had the expected amnesty applied", +); + +is_deeply( + $events->[2]->facet_data->{amnesty}, + [{ + tag => 'TODO', + details => 'foo-inner-todo', + }], + "The third event had the expected amnesty applied", +); + +ok(!$events->[3]->facet_data->{amnesty}, "No amnesty for the fourth event, \$TODO was cleaned"); + +done_testing; |