File Coverage

blib/lib/TAP/Formatter/GitHubActions/ErrorGroup.pm
Criterion Covered Total %
statement 47 47 100.0
branch 4 4 100.0
condition 1 2 50.0
subroutine 11 11 100.0
pod 0 4 0.0
total 63 68 92.6


line stmt bran cond sub pod time code
1             package TAP::Formatter::GitHubActions::ErrorGroup;
2              
3 3     3   592 use strict;
  3         7  
  3         106  
4 3     3   17 use warnings;
  3         6  
  3         135  
5 3     3   33 use v5.16;
  3         29  
6 3     3   19 use base 'TAP::Object';
  3         11  
  3         355  
7 3     3   1478 use TAP::Formatter::GitHubActions::Utils;
  3         16  
  3         167  
8             my @ATTR;
9              
10             BEGIN {
11 3     3   11 @ATTR = qw(line errors);
12 3         30 __PACKAGE__->mk_methods(@ATTR);
13             }
14              
15             sub _initialize {
16 42     42   174050 my ($self, %args) = @_;
17              
18 42         156 $self->{line} = $args{line};
19 42   50     182 $self->{errors} = $args{errors} // [];
20              
21 42         243 return $self;
22             }
23              
24             sub add {
25 43     43 0 764 my ($self, @errors) = @_;
26 43         92 push @{$self->{errors}}, $_ for @errors;
  46         168  
27 43         121 return $self;
28             }
29              
30             sub as_markdown_summary {
31 1     1 0 6 my ($self) = @_;
32 1         2 my $summary = "";
33              
34 1         2 foreach my $error (@{$self->errors}) {
  1         2  
35 2         9 $summary .= sprintf(" - %s on line %d\n", $error->test_name, $error->line);
36              
37 2 100       19 if (my $context_message = $error->decorated_context_message('```', '```')) {
38 1         7 $context_message =~ s/^/ /mg;
39 1         1 $summary .= $context_message;
40 1         3 $summary .= "\n";
41             }
42             }
43              
44 1         4 return $summary;
45             }
46              
47             sub as_summary_hash {
48 32     32 0 65 my ($self) = @_;
49              
50 32         51 my $error_count = scalar @{$self->errors};
  32         136  
51 32 100       307 my $title = "$error_count failed test" . ($error_count > 1 ? 's' : '');
52 32         61 my $body = join("\n\n", map { $_->as_plain_text } @{$self->errors});
  35         237  
  32         72  
53 32         71 chomp($body);
54              
55             return {
56 32         115 title => $title,
57             body => $body
58             };
59             }
60              
61              
62             sub as_gha_summary_for {
63 31     31 0 429 my ($self, $test) = @_;
64 31         80 my $reduction = $self->as_summary_hash();
65              
66             my $log_line = TAP::Formatter::GitHubActions::Utils::log_annotation_line(
67             type => 'error',
68             filename => $test,
69             line => $self->line,
70             title => $reduction->{title},
71             body => $reduction->{body}
72 31         94 );
73              
74 31         183 return "$log_line\n";
75             }
76              
77             1;
78             __END__