| 1 | 3 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | package Test::BDD::Cucumber::Harness::TAP 0.87; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | Test::BDD::Cucumber::Harness::TAP - Generate results in TAP format | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | version 0.87 | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | A L<Test::BDD::Cucumber::Harness> subclass whose output | ||||||||||||||||||||||||||||||||||||||||||
| 17 | is TAP (Test Anything Protocol), such as consumed by C<prove> | ||||||||||||||||||||||||||||||||||||||||||
| 18 | and C<yath>. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 OPTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head2 fail_skip | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | Boolean - makes tests with no matcher fail | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | use Types::Standard qw( Bool InstanceOf Int ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | use Test2::API qw/context/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | extends 'Test::BDD::Cucumber::Harness'; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | has 'fail_skip' => ( is => 'rw', isa => Bool, default => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | has '_reported_results' => ( is => 'rw', isa => Int, default => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | ▶ | sub feature { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
feature: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | my ( $self, $feature ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | my $ctx = context(); | |||||||||||||||||||||||||||||||||||||||||
| 43 | $ctx->note(join(' ', $feature->keyword_original, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | ($feature->name || '') . "\n", | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 9 | ▶ | map { $_->content } @{ $feature->satisfaction })); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$feature->name || ''
MC/DC0%0/1
$feature->name || ''
$feature->name
Truth table50%1/2
A
A= $feature->name
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | $ctx->release; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 73 | ▶ | sub scenario { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scenario: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 73 | my ( $self, $scenario, $dataset ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 73 | my $ctx = context(); | |||||||||||||||||||||||||||||||||||||||||
| 52 | $ctx->note(join(' ', $scenario->keyword_original, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ($scenario->name || '') . "\n", | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 73 | ▶ | map { $_->content} @{ $scenario->description })); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$scenario->name || ''
MC/DC0%0/1
$scenario->name || ''
$scenario->name
Truth table50%1/2
A
A= $scenario->name
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 73 | $ctx->release; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 52 | ▶ | sub scenario_skip { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scenario_skip: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 52 | my ( $self, $scenario, $dataset ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 52 | my $ctx = context(); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 52 | my $name = $scenario->name; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 52 | $ctx->skip("Scenario '$name' skipped due to tag filter"); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 52 | $ctx->release; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 73 | ▶ | sub scenario_done { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scenario_done: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 497 | ▶ | sub step { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 497 | ▶ | sub step_done { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step_done: called CC=13 SCAR=35.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 497 | my ( $self, $context, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 497 | my $status = $result->result; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 497 | my $step = $context->step; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 497 | my $scenario = $context->scenario; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 497 | my $step_name; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 497 | my $ctx = context(); | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # when called from a 'before' or 'after' hook, we have context, but no step | ||||||||||||||||||||||||||||||||||||||||||
| 80 | $ctx->trace->{frame} = [ | ||||||||||||||||||||||||||||||||||||||||||
| 81 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 497 | ▶ | $step ? $step->line->document->filename : $scenario->line->document->filename, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | $step ? $step->line->number : $scenario->line->number, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | undef ]; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 497 | ▶ | if ( $context->is_hook ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | $status ne 'undefined' | ||||||||||||||||||||||||||||||||||||||||||
| 87 | and $status ne 'pending' | ||||||||||||||||||||||||||||||||||||||||||
| 88 | and $status ne 'passing' | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 192 | ▶ | or do { $ctx->release; return; }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$status ne "undefined" and $status ne "pending" and $status ne "passing"
$status ne "undefined" and $status ne "pending"
MC/DC0%0/3
$status ne "undefined" and $status ne "pending" and $status ne "passing"
$status ne "undefined"
$status ne "pending"
$status ne "passing"
Truth table25%1/4
A and B and C
A= $status ne "undefined"B= $status ne "pending"C= $status ne "passing"
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $step_name = ucfirst( $context->verb ) . ' Hook'; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 305 | $step_name | |||||||||||||||||||||||||||||||||||||||||
| 93 | = ucfirst( $step->verb_original ) . ' ' . $context->text; | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 305 | ▶ | if ( $status eq 'undefined' || $status eq 'pending' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$status eq "undefined" or $status eq "pending"
MC/DC0%0/2
$status eq "undefined" or $status eq "pending"
$status eq "undefined"
$status eq "pending"
Truth table33%1/3
A or B
A= $status eq "undefined"B= $status eq "pending"
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( $self->fail_skip ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ( $status eq 'undefined' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $ctx->fail( "Matcher for: $step_name", | |||||||||||||||||||||||||||||||||||||||||
| 100 | $self->_note_step_data($step)); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->_reported_results( $self->_reported_results + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $ctx->skip( "Test skipped due to failure in previous step", | |||||||||||||||||||||||||||||||||||||||||
| 104 | $self->_note_step_data($step)); | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $self->_reported_results( $self->_reported_results + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $ctx->send_event( 'Skip', todo => 'pending', todo_diag => 1, | |||||||||||||||||||||||||||||||||||||||||
| 109 | reason => 'Step not implemented', pass => 0); | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $ctx->note($self->_note_step_data($step)); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } elsif ( $status eq 'passing' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 305 | $ctx->pass( $step_name ); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 305 | $ctx->note($self->_note_step_data($step)); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 305 | $self->_reported_results( $self->_reported_results + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $ctx->fail( $step_name ); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $ctx->note($self->_note_step_data($step)); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $self->_reported_results( $self->_reported_results + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ( !$context->is_hook ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $step_location | |||||||||||||||||||||||||||||||||||||||||
| 122 | = ' in step at ' | ||||||||||||||||||||||||||||||||||||||||||
| 123 | . $step->line->document->filename | ||||||||||||||||||||||||||||||||||||||||||
| 124 | . ' line ' | ||||||||||||||||||||||||||||||||||||||||||
| 125 | . $step->line->number . '.'; | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $ctx->diag($step_location); | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $ctx->diag( $result->output ); | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 305 | $ctx->release; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 305 | ▶ | sub _note_step_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_note_step_data: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 305 | my ( $self, $step ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 305 | ▶ | return unless $step; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 305 | my @step_data = @{ $step->data_as_strings }; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 305 | ▶ | return '' unless @step_data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 25 | ▶ | if ( ref( $step->data ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | return join("\n", @step_data); | |||||||||||||||||||||||||||||||||||||||||
| 141 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 19 | return join('', '"""', join("\n", @step_data), '"""'); | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | sub shutdown { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shutdown: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | my $ctx = context(); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | $ctx->done_testing; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $ctx->release; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | Peter Sergeant C<pete@clueball.com> | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | Copyright 2019-2023, Erik Huelsmann | ||||||||||||||||||||||||||||||||||||||||||
| 160 | Copyright 2011-2019, Peter Sergeant; Licensed under the same terms as Perl | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||