This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Sync Test-Simple with CPAN version 1.302173
[perl5.git] / cpan / Test-Simple / lib / Test / Builder.pm
index 41d5cbb..f388201 100644 (file)
@@ -4,7 +4,7 @@ use 5.006;
 use strict;
 use warnings;
 
-our $VERSION = '1.302111';
+our $VERSION = '1.302173';
 
 BEGIN {
     if( $] < 5.008 ) {
@@ -21,13 +21,12 @@ BEGIN {
     warn "Test::Builder was loaded after Test2 initialization, this is not recommended."
         if Test2::API::test2_init_done() || Test2::API::test2_load_done();
 
-    if (USE_THREADS) {
+    if (USE_THREADS && ! Test2::API::test2_ipc_disabled()) {
         require Test2::IPC;
         require Test2::IPC::Driver::Files;
         Test2::IPC::Driver::Files->import;
         Test2::API::test2_ipc_enable_polling();
         Test2::API::test2_no_wait(1);
-        Test2::API::test2_ipc_enable_shm();
     }
 }
 
@@ -64,18 +63,14 @@ sub _add_ts_hooks {
         $todo = ${"$cpkg\::TODO"} if $cpkg;
         $todo = ${"$epkg\::TODO"} if $epkg && !$todo;
 
-        return $e unless $todo;
+        return $e unless defined($todo);
+        return $e unless length($todo);
 
         # Turn a diag into a todo diag
         return Test::Builder::TodoDiag->new(%$e) if ref($e) eq 'Test2::Event::Diag';
 
-        if ($active_hub == $hub) {
-            $e->set_todo($todo) if $e->can('set_todo');
-            $e->add_amnesty({tag => 'TODO', details => $todo});
-        }
-        else {
-            $e->add_amnesty({tag => 'TODO', details => $todo, inherited => 1});
-        }
+        $e->set_todo($todo) if $e->can('set_todo');
+        $e->add_amnesty({tag => 'TODO', details => $todo});
 
         # Set todo on ok's
         if ($e->isa('Test2::Event::Ok')) {
@@ -120,7 +115,7 @@ sub new {
 
         Test2::API::test2_add_callback_exit(sub { $Test->_ending(@_) });
 
-        Test2::API::test2_ipc()->set_no_fatal(1) if USE_THREADS;
+        Test2::API::test2_ipc()->set_no_fatal(1) if Test2::API::test2_has_ipc();
     }
     return $Test;
 }
@@ -221,6 +216,7 @@ sub child {
     $meta->{Test_Results} = [];
     $meta->{subevents} = $subevents;
     $meta->{subtest_id} = $hub->id;
+    $meta->{subtest_uuid} = $hub->uuid;
     $meta->{subtest_buffered} = $parent->format ? 0 : 1;
 
     $self->_add_ts_hooks;
@@ -301,6 +297,7 @@ FAIL
         else {
             $parent->{subevents}  = $meta->{subevents};
             $parent->{subtest_id} = $meta->{subtest_id};
+            $parent->{subtest_uuid} = $meta->{subtest_uuid};
             $parent->{subtest_buffered} = $meta->{subtest_buffered};
             $parent->ok( $chub->is_passing, $meta->{Name} );
         }
@@ -319,6 +316,10 @@ sub subtest {
 
     $name ||= "Child of " . $self->name;
 
+
+    $_->($name,$code,@args)
+        for Test2::API::test2_list_pre_subtest_callbacks();
+
     $ctx->note("Subtest: $name");
 
     my $child = $self->child($name);
@@ -390,7 +391,7 @@ sub name {
 sub reset {    ## no critic (Subroutines::ProhibitBuiltinHomonyms)
     my ($self, %params) = @_;
 
-    Test2::API::test2_set_is_end(0);
+    Test2::API::test2_unset_is_end();
 
     # We leave this a global because it has to be localized and localizing
     # hash keys is just asking for pain.  Also, it was documented.
@@ -667,11 +668,12 @@ sub ok {
     my @attrs;
     my $subevents  = delete $self->{subevents};
     my $subtest_id = delete $self->{subtest_id};
+    my $subtest_uuid = delete $self->{subtest_uuid};
     my $subtest_buffered = delete $self->{subtest_buffered};
     my $epkg = 'Test2::Event::Ok';
     if ($subevents) {
         $epkg = 'Test2::Event::Subtest';
-        push @attrs => (subevents => $subevents, subtest_id => $subtest_id, buffered => $subtest_buffered);
+        push @attrs => (subevents => $subevents, subtest_id => $subtest_id, subtest_uuid => $subtest_uuid, buffered => $subtest_buffered);
     }
 
     my $e = bless {
@@ -694,7 +696,7 @@ sub _ok_debug {
     my $self = shift;
     my ($trace, $orig_name) = @_;
 
-    my $is_todo = defined($self->todo);
+    my $is_todo = $self->in_todo;
 
     my $msg = $is_todo ? "Failed (TODO)" : "Failed";
 
@@ -1758,7 +1760,6 @@ sub coordinate_forks {
     my $ipc = Test2::IPC::apply_ipc($self->{Stack});
     $ipc->set_no_fatal(1);
     Test2::API::test2_no_wait(1);
-    Test2::API::test2_ipc_enable_shm();
 }
 
 sub no_log_results { $_[0]->{no_log_results} = 1 }
@@ -2537,6 +2538,18 @@ bugs to support.
 Test::Builder is only thread-aware if threads.pm is loaded I<before>
 Test::Builder.
 
+You can directly disable thread support with one of the following:
+
+    $ENV{T2_NO_IPC} = 1
+
+or
+
+    no Test2::IPC;
+
+or
+
+    Test2::API::test2_ipc_disable()
+
 =head1 MEMORY
 
 An informative hash, accessible via C<details()>, is stored for each
@@ -2559,7 +2572,17 @@ L<Test::Exception> and L<Test::Differences> all use Test::Builder.
 
 =head1 SEE ALSO
 
-L<Test::Simple>, L<Test::More>, L<Test::Harness>
+=head2 INTERNALS
+
+L<Test2>, L<Test2::API>
+
+=head2 LEGACY
+
+L<Test::Simple>, L<Test::More>
+
+=head2 EXTERNAL
+
+L<Test::Harness>
 
 =head1 AUTHORS