• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wickedOne / gitlab-perl-helpers / 9930703181

14 Jul 2024 09:03PM UTC coverage: 100.0%. Remained the same
9930703181

push

github

web-flow
regex fixes (#30)

- fixed regex bug which caused the script to step out of the teardown
  too early.

2 of 2 new or added lines in 1 file covered. (100.0%)

842 of 842 relevant lines covered (100.0%)

21.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/GPH/Infection.pm
1
package GPH::Infection;
2

3
use strict;
1✔
4
use warnings FATAL => 'all';
1✔
5

6
sub new {
7
    my ($class, %args) = @_;
10✔
8

9
    (exists($args{msi}) and exists($args{covered})) or die "$!";
10✔
10

11
    my $self = {
12
        msi     => $args{msi},
13
        covered => $args{covered},
14
        code    => $args{exit_code} || 8,
8✔
15
    };
16

17
    bless $self, $class;
8✔
18

19
    return $self;
8✔
20
}
21

22
sub parse {
23
    my ($self) = @_;
5✔
24
    my $escapees = 0;
5✔
25
    my $msi = 0;
5✔
26
    my $covered = 0;
5✔
27

28
    while (<>) {
5✔
29
        if ($_ =~ '([\d]+) covered mutants were not detected') {
75✔
30
            $escapees = $1;
5✔
31
        }
32

33
        if ($_ =~ 'Mutation Score Indicator \(MSI\): ([\d]+)%') {
75✔
34
            $msi = $1;
5✔
35
        }
36

37
        if ($_ =~ 'Covered Code MSI: ([\d]+)%') {
75✔
38
            $covered = $1;
5✔
39
        }
40

41
        print $_;
75✔
42
    }
43

44
    if ($msi < $self->{'msi'} || $covered < $self->{'covered'}) {
5✔
45
        return 1;
3✔
46
    }
47

48
    if ($escapees != 0) {
2✔
49
        print "\n\n[warning] even though MSI is within allowed boundaries $escapees mutants were not detected. please improve your tests!\n";
1✔
50

51
        return $self->{'code'};
1✔
52
    }
53

54
    return 0;
1✔
55
}
56

57
1;
58

59
__END__
60

61
=head1 NAME
62

63
GPH::Infection - parse output generated by L<infection|https://infection.github.io/> and return alternate exit code
64
when both msi and covered msi meet the configured threshold, but there are escaped mutants.
65

66
=head1 SYNOPSIS
67

68
    use GPH::Infection;
69

70
    my $infection = GPH::Infection->new((
71
        msi     => 95.2,
72
        covered => 100.00,
73
    ));
74

75
    exit($infection->parse());
76

77
=head1 METHODS
78

79
=over 4
80

81
=item C<< -E<gt>new(%args) >>
82

83
the C<new> method creates a new GPH::Infection instance. it takes a hash of options, valid option keys include:
84

85
=over
86

87
=item msi B<(required)>
88

89
minimum mutation score indicator
90

91
=item covered B<(required)>
92

93
minimum covered msi
94

95
=item exit_code
96

97
exit code to return when the thresholds are met, but there are escaped mutants. defaults to C<8>
98

99
=back
100

101
=item C<< -E<gt>parse() >>
102

103
parse infection output from <>, print warning when appropriate and return exit code
104

105
=back
106

107
=head1 AUTHOR
108

109
the GPH::Infection module was written by wicliff wolda <wicliff.wolda@gmail.com>
110

111
=head1 COPYRIGHT AND LICENSE
112

113
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
114

115
=cut
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc