1use Test2::Tools::Tiny; 2use Test2::API qw/test2_add_uuid_via context intercept/; 3 4my %CNT; 5test2_add_uuid_via(sub { 6 my $type = shift; 7 $CNT{$type} ||= 1; 8 $type . '-' . $CNT{$type}++; 9}); 10 11my $events = intercept { 12 ok(1, "pass"); 13 14 sub { 15 my $ctx = context(); 16 ok(1, "pass"); 17 ok(0, "fail"); 18 $ctx->release; 19 }->(); 20 21 tests foo => sub { 22 ok(1, "pass"); 23 }; 24 25 warnings { 26 require Test::More; 27 *subtest = \&Test::More::subtest; 28 }; 29 30 subtest(foo => sub { 31 ok(1, "pass"); 32 }); 33}; 34 35my $hub = Test2::API::test2_stack->top; 36is($hub->uuid, 'hub-1', "First hub got a uuid"); 37 38is($events->[0]->uuid, 'event-1', "First event gets first uuid"); 39is($events->[0]->trace->uuid, 'context-2', "First event has correct context"); 40is($events->[0]->trace->huuid, 'hub-2', "First event has correct hub"); 41 42is($events->[0]->facet_data->{about}->{uuid}, "event-1", "The UUID makes it to facet data"); 43 44is($events->[1]->uuid, 'event-2', "Second event gets correct uuid"); 45is($events->[1]->trace->uuid, 'context-3', "Second event has correct context"); 46is($events->[1]->trace->huuid, 'hub-2', "Second event has correct hub"); 47 48is($events->[2]->uuid, 'event-3', "Third event gets correct uuid"); 49is($events->[2]->trace->uuid, $events->[1]->trace->uuid, "Third event shares context with event 2"); 50is($events->[2]->trace->huuid, 'hub-2', "Third event has correct hub"); 51 52is($events->[3]->uuid, 'event-6', "subtest event gets correct uuid (not next)"); 53is($events->[3]->subtest_uuid, 'hub-3', "subtest event gets correct subtest-uuid (next hub uuid)"); 54is($events->[3]->trace->uuid, 'context-4', "subtest gets next sequential context"); 55is($events->[3]->trace->huuid, 'hub-2', "subtest event has correct hub"); 56 57is($events->[3]->subevents->[0]->uuid, 'event-4', "First subevent gets next event uuid"); 58is($events->[3]->subevents->[0]->trace->uuid, 'context-5', "First subevent has correct context"); 59is($events->[3]->subevents->[0]->trace->huuid, 'hub-3', "First subevent has correct hub uuid (subtest hub uuid)"); 60 61is($events->[3]->subevents->[1]->uuid, 'event-5', "Second subevent gets next event uuid"); 62is($events->[3]->subevents->[1]->trace->uuid, $events->[3]->trace->uuid, "Second subevent has same context as subtest itself"); 63is($events->[3]->subevents->[1]->trace->huuid, 'hub-3', "Second subevent has correct hub uuid (subtest hub uuid)"); 64 65is($events->[5]->uuid, 'event-10', "subtest event gets correct uuid (not next)"); 66is($events->[5]->subtest_uuid, 'hub-4', "subtest event gets correct subtest-uuid (next hub uuid)"); 67is($events->[5]->trace->uuid, 'context-8', "subtest gets next sequential context"); 68is($events->[5]->trace->huuid, 'hub-2', "subtest event has correct hub"); 69 70is($events->[5]->subevents->[0]->uuid, 'event-8', "First subevent gets next event uuid"); 71is($events->[5]->subevents->[0]->trace->uuid, 'context-10', "First subevent has correct context"); 72is($events->[5]->subevents->[0]->trace->huuid, 'hub-4', "First subevent has correct hub uuid (subtest hub uuid)"); 73 74is($events->[5]->subevents->[1]->uuid, 'event-9', "Second subevent gets next event uuid"); 75is($events->[5]->subevents->[1]->trace->uuid, $events->[5]->trace->uuid, "Second subevent has same context as subtest itself"); 76is($events->[5]->subevents->[1]->trace->huuid, 'hub-2', "Second subevent has correct hub uuid (subtest hub uuid)"); 77 78done_testing; 79