| 1 | package Test2::Plugin::GitHub::Actions::AnnotateFailedTest; | ||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use feature qw(state); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Encode qw(encode_utf8); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Test2::API qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | test2_add_callback_post_load | ||||||||||||||||||||||||||||
| 9 | test2_stack | ||||||||||||||||||||||||||||
| 10 | test2_stderr | ||||||||||||||||||||||||||||
| 11 | 8 | ); | |||||||||||||||||||||||||||
| 12 | 8 | ▶ | use URI::Escape qw(uri_escape); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 8 | our $VERSION = "0.04"; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 10 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 17 | 10 | my ($class) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 10 | ▶ | return unless $ENV{GITHUB_ACTIONS}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 7 | state $loaded = 0; # avoid multiple callback addition | |||||||||||||||||||||||||||
| 21 | 7 | ▶ | return if $loaded; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 5 | $loaded++; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | ▶ | test2_add_callback_post_load(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 5 | my $hub = test2_stack()->top; | |||||||||||||||||||||||||||
| 26 | 5 | $hub->listen(\&listener, inherit => 1); | |||||||||||||||||||||||||||
| 27 | 5 | }); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 10 | ▶ | sub listener { | ||||||||||||||||||||||||||
|
Subroutine
listener: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 10 | my ($hub, $event) = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 10 | ▶ | return unless $event->causes_fail; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 4 | my $trace = $event->trace; | |||||||||||||||||||||||||||
| 36 | 4 | my $summary = _extract_summary_from_event($event); | |||||||||||||||||||||||||||
| 37 | 4 | ▶ | my $file = $trace->file // '<no name>'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$trace->file // "<no name>"
MC/DC0%0/1
$trace->file // "<no name>"
$trace->file
Truth table50%1/2
A
A= $trace->file
| |||||||||||||||||||||||||||||
| 38 | 4 | ▶ | my $line = $trace->line // 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$trace->line // 0
MC/DC0%0/1
$trace->line // 0
$trace->line
Truth table50%1/2
A
A= $trace->line
| |||||||||||||||||||||||||||||
| 39 | 4 | my $details = _extract_details_from_event($event); | |||||||||||||||||||||||||||
| 40 | 4 | my $message = encode_utf8(join "\n", grep { defined } ($summary, $details)); # avoid Wide character in print warning | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 4 | _issue_error($file, $line, $message); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 4 | ▶ | sub _extract_summary_from_event { | ||||||||||||||||||||||||||
|
Subroutine
_extract_summary_from_event: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||
| 46 | 4 | my ($event) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 4 | ▶ | my $name_or_summary = $event->isa('Test2::Event::Fail') ? $event->name : $event->summary; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | # avoid uninitialized warning for regexp matching | ||||||||||||||||||||||||||||
| 50 | 4 | ▶ | $name_or_summary //= ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$name_or_summary //= ""
MC/DC0%0/1
$name_or_summary //= ""
$name_or_summary
Truth table50%1/2
A
A= $name_or_summary
| |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | if ($name_or_summary =~ /Nameless Assertion/ || ! length $name_or_summary) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name_or_summary =~ /Nameless Assertion/ or not length $name_or_summary
MC/DC50%1/2
$name_or_summary =~ /Nameless Assertion/ or not length $name_or_summary
$name_or_summary =~ /Nameless Assertion/
not length $name_or_summary
Truth table66%2/3
A or not(B)
A= $name_or_summary =~ /Nameless Assertion/B= not length $name_or_summary
| |||||||||||||||||||||||||||||
| 52 | 1 | return 'Test failed'; | |||||||||||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||||||||||
| 54 | 3 | return $name_or_summary; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 4 | ▶ | sub _extract_details_from_event { | ||||||||||||||||||||||||||
|
Subroutine
_extract_details_from_event: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 59 | 4 | my ($event) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 4 | ▶ | return undef unless exists $event->{info}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 1 | return join "\n", map { $_->{details} } @{$event->{info}}; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub _issue_error { | ||||||||||||||||||||||||||
|
Subroutine
_issue_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 66 | 0 | my ($file, $line, $detail) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my $stderr = test2_stderr(); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $stderr->printf("::error file=%s,line=%d::%s\n", $file, $line, _escape_data($detail)); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # escape a message of workflow command. | ||||||||||||||||||||||||||||
| 74 | # see also: https://github.com/actions/toolkit/blob/30e0a77337213de5d4e158b05d1019c6615f69fd/packages/core/src/command.ts#L92-L97 | ||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub _escape_data { | ||||||||||||||||||||||||||
|
Subroutine
_escape_data: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | 1 | my ($msg) = @_; | |||||||||||||||||||||||||||
| 77 | 1 | return uri_escape($msg, "%\r\n"); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 8 | 1; | |||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||