File Coverage

blib/lib/TAP/Formatter/GitHubActions/Error.pm
Criterion Covered Total %
statement 33 33 100.0
branch 4 4 100.0
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 50 50 100.0


line stmt bran cond sub pod time code
1             package TAP::Formatter::GitHubActions::Error;
2              
3 4     4   432410 use strict;
  4         10  
  4         156  
4 4     4   22 use warnings;
  4         7  
  4         204  
5 4     4   52 use v5.16;
  4         18  
6 4     4   20 use base 'TAP::Object';
  4         7  
  4         1029  
7              
8             my @ATTR;
9              
10             BEGIN {
11 4     4   22 @ATTR = qw(test_name filename line context_msg );
12 4         34 __PACKAGE__->mk_methods(@ATTR);
13             }
14              
15             my $TRIPHASIC_REGEX = qr/
16             \s*
17             (? # Test header
18             Failed\stest
19             (?:\s*'[^']+')? # Test name [usually last param in an assertion, optional]
20             )
21             \s*
22             at\s(?.+) # Location: File
23             \s+
24             line\s(?\d+)\. # Location: Line
25             (\n)?
26             (?[\w\W]*) # Any additional content
27             /mx;
28              
29             use constant {
30 4         1831 TRIPHASIC_REGEX => $TRIPHASIC_REGEX,
31 4     4   1042 };
  4         10  
32              
33             sub from_output {
34 36     36 1 12802 my ($class, $output) = @_;
35              
36 36 100       814 return undef unless $output =~ qr/$TRIPHASIC_REGEX/m;
37              
38             return $class->new(
39             line => $+{line},
40             filename => $+{filename},
41             test_name => $+{test_name},
42             context_msg => $+{context_msg}
43 35         397 );
44             }
45              
46             sub _initialize {
47 51     51   224441 my ($self, %args) = @_;
48              
49 51         166 $self->{test_name} = $args{test_name};
50 51         124 $self->{filename} = $args{filename};
51 51         171 $self->{line} = $args{line};
52 51         94 $self->{context_msg} = $args{context_msg};
53              
54 51         193 return $self;
55             }
56              
57             sub decorated_context_message {
58 45     45 1 332 my ($self, $pre, $post) = @_;
59              
60 45 100       155 return unless $self->{context_msg};
61              
62             return join("\n",
63 34         92 grep { $_ } ($pre, $self->context_msg, $post)
  102         491  
64             );
65             }
66              
67             sub as_plain_text {
68 38     38 1 97 my ($self) = @_;
69 38         97 my @components = (
70             $self->test_name,
71             $self->decorated_context_message(
72             '--- CAPTURED CONTEXT ---',
73             '--- END OF CONTEXT ---')
74             );
75 38         89 return join("\n", grep { $_ } @components);
  67         239  
76             }
77              
78             1;
79             __END__