line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Plugin::GitHub::Actions::AnnotateWarnings; |
2
|
4
|
|
|
4
|
|
2993
|
use 5.008001; |
|
4
|
|
|
|
|
13
|
|
3
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
77
|
|
4
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
108
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
35
|
use Test2::API qw(test2_stderr); |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
208
|
|
7
|
4
|
|
|
4
|
|
428
|
use URI::Escape qw(uri_escape); |
|
4
|
|
|
|
|
1219
|
|
|
4
|
|
|
|
|
1856
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub __ignore_no_warnings { |
12
|
2
|
|
|
2
|
|
6
|
my ($message, $filename, $line) = @_; |
13
|
2
|
|
|
|
|
12
|
return 0; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# By default, no warning is ignored. |
17
|
|
|
|
|
|
|
my $ignore_if = \&__ignore_no_warnings; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $_orig_warn_handler; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub import { |
22
|
4
|
|
|
4
|
|
16781
|
my ($class, %args) = @_; |
23
|
|
|
|
|
|
|
|
24
|
4
|
100
|
|
|
|
25
|
return unless $ENV{GITHUB_ACTIONS}; |
25
|
|
|
|
|
|
|
|
26
|
3
|
100
|
|
|
|
10
|
$ignore_if = $args{ignore_if} if exists $args{ignore_if}; |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
|
|
7
|
$_orig_warn_handler = $SIG{__WARN__}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$SIG{__WARN__} = sub { |
31
|
4
|
|
|
4
|
|
289
|
my (undef, $file, $line) = caller; |
32
|
4
|
|
50
|
|
|
15
|
my $message = $_[0] // "Warning: Something's wrong"; |
33
|
4
|
|
|
|
|
10
|
chomp $message; |
34
|
4
|
|
|
|
|
9
|
$message = _escape_data($message); |
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
|
|
548
|
my $stderr = test2_stderr(); |
37
|
4
|
100
|
|
|
|
26
|
_issue_warning($file, $line, $message) unless $ignore_if->($message, $file, $line); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# from Test::Warnings |
40
|
|
|
|
|
|
|
# TODO: this doesn't handle blessed coderefs... does anyone care? |
41
|
4
|
0
|
0
|
|
|
104
|
if ($_orig_warn_handler and ((ref $_orig_warn_handler eq 'CODE') or ($_orig_warn_handler ne 'DEFAULT' and $_orig_warn_handler ne 'IGNORE' and defined &$_orig_warn_handler))) { |
|
|
|
33
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
goto &$_orig_warn_handler; |
43
|
|
|
|
|
|
|
} |
44
|
3
|
|
|
|
|
18
|
}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub unimport { |
48
|
1
|
|
|
1
|
|
306
|
my ($class) = @_; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
3
|
$ignore_if = \&__ignore_no_warnings; |
51
|
1
|
|
|
|
|
10
|
$SIG{__WARN__} = $_orig_warn_handler; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _issue_warning { |
55
|
0
|
|
|
0
|
|
0
|
my ($file, $line, $detail) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
my $stderr = test2_stderr(); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
0
|
if (length $detail) { |
60
|
0
|
|
|
|
|
0
|
$stderr->printf("::warning file=%s,line=%d::%s\n", $file, $line, _escape_data($detail)); |
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
0
|
$stderr->printf("::warning file=%s,line=%d\n", $file, $line); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# escape a message of workflow command. |
67
|
|
|
|
|
|
|
# see also: https://github.com/actions/toolkit/blob/30e0a77337213de5d4e158b05d1019c6615f69fd/packages/core/src/command.ts#L92-L97 |
68
|
|
|
|
|
|
|
sub _escape_data { |
69
|
4
|
|
|
4
|
|
8
|
my ($msg) = @_; |
70
|
4
|
|
|
|
|
14
|
return uri_escape($msg, "%\r\n"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |