| 1 | package Test2::Event::Subtest; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | our $VERSION = '1.302073'; | ||
| 6 | |||
| 7 | |||
| 8 | BEGIN { require Test2::Event::Ok; our @ISA = qw(Test2::Event::Ok) } | ||
| 9 | use Test2::Util::HashBase qw{subevents buffered subtest_id}; | ||
| 10 | |||
| 11 | sub init { | ||
| 12 | my $self = shift; | ||
| 13 | $self->SUPER::init(); | ||
| 14 | $self->{+SUBEVENTS} ||= []; | ||
| 15 | if ($self->{+EFFECTIVE_PASS}) { | ||
| 16 | $_->set_effective_pass(1) for grep { $_->can('effective_pass') } @{$self->{+SUBEVENTS}}; | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | { | ||
| 21 | no warnings 'redefine'; | ||
| 22 | |||
| 23 | sub set_subevents { | ||
| 24 | my $self = shift; | ||
| 25 | my @subevents = @_; | ||
| 26 | |||
| 27 | if ($self->{+EFFECTIVE_PASS}) { | ||
| 28 | $_->set_effective_pass(1) for grep { $_->can('effective_pass') } @subevents; | ||
| 29 | } | ||
| 30 | |||
| 31 | $self->{+SUBEVENTS} = \@subevents; | ||
| 32 | } | ||
| 33 | |||
| 34 | sub set_effective_pass { | ||
| 35 | my $self = shift; | ||
| 36 | my ($pass) = @_; | ||
| 37 | |||
| 38 | if ($pass) { | ||
| 39 | $_->set_effective_pass(1) for grep { $_->can('effective_pass') } @{$self->{+SUBEVENTS}}; | ||
| 40 | } | ||
| 41 | elsif ($self->{+EFFECTIVE_PASS} && !$pass) { | ||
| 42 | for my $s (grep { $_->can('effective_pass') } @{$self->{+SUBEVENTS}}) { | ||
| 43 | $_->set_effective_pass(0) unless $s->can('todo') && defined $s->todo; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | $self->{+EFFECTIVE_PASS} = $pass; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | sub summary { | ||
| 52 | my $self = shift; | ||
| 53 | |||
| 54 | my $name = $self->{+NAME} || "Nameless Subtest"; | ||
| 55 | |||
| 56 | my $todo = $self->{+TODO}; | ||
| 57 | if ($todo) { | ||
| 58 | $name .= " (TODO: $todo)"; | ||
| 59 | } | ||
| 60 | elsif (defined $todo) { | ||
| 61 | $name .= " (TODO)" | ||
| 62 | } | ||
| 63 | |||
| 64 | return $name; | ||
| 65 | } | ||
| 66 | |||
| 67 | 1; | ||
| 68 | |||
| 69 | __END__ |