1package Test2::Event::Subtest; 2use strict; 3use warnings; 4 5our $VERSION = '1.302175'; 6 7BEGIN { require Test2::Event::Ok; our @ISA = qw(Test2::Event::Ok) } 8use Test2::Util::HashBase qw{subevents buffered subtest_id subtest_uuid}; 9 10sub init { 11 my $self = shift; 12 $self->SUPER::init(); 13 $self->{+SUBEVENTS} ||= []; 14 if ($self->{+EFFECTIVE_PASS}) { 15 $_->set_effective_pass(1) for grep { $_->can('effective_pass') } @{$self->{+SUBEVENTS}}; 16 } 17} 18 19{ 20 no warnings 'redefine'; 21 22 sub set_subevents { 23 my $self = shift; 24 my @subevents = @_; 25 26 if ($self->{+EFFECTIVE_PASS}) { 27 $_->set_effective_pass(1) for grep { $_->can('effective_pass') } @subevents; 28 } 29 30 $self->{+SUBEVENTS} = \@subevents; 31 } 32 33 sub set_effective_pass { 34 my $self = shift; 35 my ($pass) = @_; 36 37 if ($pass) { 38 $_->set_effective_pass(1) for grep { $_->can('effective_pass') } @{$self->{+SUBEVENTS}}; 39 } 40 elsif ($self->{+EFFECTIVE_PASS} && !$pass) { 41 for my $s (grep { $_->can('effective_pass') } @{$self->{+SUBEVENTS}}) { 42 $_->set_effective_pass(0) unless $s->can('todo') && defined $s->todo; 43 } 44 } 45 46 $self->{+EFFECTIVE_PASS} = $pass; 47 } 48} 49 50sub summary { 51 my $self = shift; 52 53 my $name = $self->{+NAME} || "Nameless Subtest"; 54 55 my $todo = $self->{+TODO}; 56 if ($todo) { 57 $name .= " (TODO: $todo)"; 58 } 59 elsif (defined $todo) { 60 $name .= " (TODO)"; 61 } 62 63 return $name; 64} 65 66sub facet_data { 67 my $self = shift; 68 69 my $out = $self->SUPER::facet_data(); 70 71 $out->{parent} = { 72 hid => $self->subtest_id, 73 children => [map {$_->facet_data} @{$self->{+SUBEVENTS}}], 74 buffered => $self->{+BUFFERED}, 75 }; 76 77 return $out; 78} 79 80sub add_amnesty { 81 my $self = shift; 82 83 for my $am (@_) { 84 $am = {%$am} if ref($am) ne 'ARRAY'; 85 $am = Test2::EventFacet::Amnesty->new($am); 86 87 push @{$self->{+AMNESTY}} => $am; 88 89 for my $e (@{$self->{+SUBEVENTS}}) { 90 $e->add_amnesty($am->clone(inherited => 1)); 91 } 92 } 93} 94 95 961; 97 98__END__ 99 100=pod 101 102=encoding UTF-8 103 104=head1 NAME 105 106Test2::Event::Subtest - Event for subtest types 107 108=head1 DESCRIPTION 109 110This class represents a subtest. This class is a subclass of 111L<Test2::Event::Ok>. 112 113=head1 ACCESSORS 114 115This class inherits from L<Test2::Event::Ok>. 116 117=over 4 118 119=item $arrayref = $e->subevents 120 121Returns the arrayref containing all the events from the subtest 122 123=item $bool = $e->buffered 124 125True if the subtest is buffered, that is all subevents render at once. If this 126is false it means all subevents render as they are produced. 127 128=back 129 130=head1 SOURCE 131 132The source code repository for Test2 can be found at 133F<http://github.com/Test-More/test-more/>. 134 135=head1 MAINTAINERS 136 137=over 4 138 139=item Chad Granum E<lt>exodist@cpan.orgE<gt> 140 141=back 142 143=head1 AUTHORS 144 145=over 4 146 147=item Chad Granum E<lt>exodist@cpan.orgE<gt> 148 149=back 150 151=head1 COPYRIGHT 152 153Copyright 2019 Chad Granum E<lt>exodist@cpan.orgE<gt>. 154 155This program is free software; you can redistribute it and/or 156modify it under the same terms as Perl itself. 157 158See F<http://dev.perl.org/licenses/> 159 160=cut 161