| 1 | 22 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 22 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Test::BDD::Cucumber::Model::Result 0.87; | ||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | Test::BDD::Cucumber::Model::Result - Encapsulates a result state | ||||||||||
| 9 | |||||||||||
| 10 | =head1 VERSION | ||||||||||
| 11 | |||||||||||
| 12 | version 0.87 | ||||||||||
| 13 | |||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||
| 15 | |||||||||||
| 16 | Encapsulation of result state - whether that's for a step, scenario, or feature | ||||||||||
| 17 | |||||||||||
| 18 | =cut | ||||||||||
| 19 | |||||||||||
| 20 | 22 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 22 | ▶ | use Types::Standard qw( Enum Str ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | =head1 ATTRIBUTES | ||||||||||
| 24 | |||||||||||
| 25 | =head2 result | ||||||||||
| 26 | |||||||||||
| 27 | Enum of: C<passing>, C<failing>, C<pending> or C<undefined>. C<pending> is used | ||||||||||
| 28 | if there was any TODO output from a test, and C<undefined> for a test that | ||||||||||
| 29 | wasn't run, either due to no matching step, or because a previous step failed. | ||||||||||
| 30 | |||||||||||
| 31 | =cut | ||||||||||
| 32 | |||||||||||
| 33 | 22 | has 'result' => ( is => 'ro', isa => Enum[qw( passing failing pending undefined )], required => 1 ); | |||||||||
| 34 | |||||||||||
| 35 | =head2 output | ||||||||||
| 36 | |||||||||||
| 37 | The underlying test-output that contributed to a result. | ||||||||||
| 38 | |||||||||||
| 39 | =cut | ||||||||||
| 40 | |||||||||||
| 41 | 22 | has 'output' => ( is => 'ro', isa => Str, required => 1 ); | |||||||||
| 42 | |||||||||||
| 43 | =head1 METHODS | ||||||||||
| 44 | |||||||||||
| 45 | =head2 from_children | ||||||||||
| 46 | |||||||||||
| 47 | Collates the Result objects you pass in, and returns one that encompasses all | ||||||||||
| 48 | of them. | ||||||||||
| 49 | |||||||||||
| 50 | As they may be varied, it runs through them in order of C<failing>, | ||||||||||
| 51 | C<undefined>, C<pending> and C<passing> - the first it finds is the overall | ||||||||||
| 52 | result. The empty set passes. | ||||||||||
| 53 | |||||||||||
| 54 | =cut | ||||||||||
| 55 | |||||||||||
| 56 | 32 | ▶ | sub from_children { | ||||||||
|
Subroutine
from_children: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 57 | 32 | my ( $class, @children ) = @_; | |||||||||
| 58 | |||||||||||
| 59 | # We'll be looking for the presence of just one of any of the | ||||||||||
| 60 | # short-circuiting statuses, but we need to keep a sum of all the output. | ||||||||||
| 61 | # Passing is the default state, so we cheat and say there was one of them. | ||||||||||
| 62 | 32 | my %results = ( passing => 1 ); | |||||||||
| 63 | 32 | my $output; | |||||||||
| 64 | |||||||||||
| 65 | 32 | for my $child (@children) { | |||||||||
| 66 | |||||||||||
| 67 | # Save the status of that child | ||||||||||
| 68 | 412 | $results{ $child->result }++; | |||||||||
| 69 | |||||||||||
| 70 | # Add its output | ||||||||||
| 71 | 412 | $output .= $child->output . "\n"; | |||||||||
| 72 | } | ||||||||||
| 73 | 32 | $output .= "\n"; | |||||||||
| 74 | |||||||||||
| 75 | 32 | for my $status (qw( failing undefined pending passing )) { | |||||||||
| 76 | 106 | ▶ | if ( $results{$status} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 32 | return $class->new( | |||||||||
| 78 | { | ||||||||||
| 79 | result => $status, | ||||||||||
| 80 | output => $output | ||||||||||
| 81 | } | ||||||||||
| 82 | ); | ||||||||||
| 83 | } | ||||||||||
| 84 | } | ||||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 22 | 1; | |||||||||