| 1 | package Log::Munger::App::Command::test_all; | ||||||||||
| 2 | |||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 16 | ▶ | use Log::Munger::App -command; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 16 | ▶ | use Log::Munger::RulesTest (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 16 | ▶ | use Log::Munger::WhichRuleFile (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | sub opt_spec { | ||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 10 | 1 | return ( [ 'verbose|v', 'Print each error and warning, not just counts.' ], ); | |||||||||
| 11 | } | ||||||||||
| 12 | |||||||||||
| 13 | 0 | ▶ | sub abstract { "Run the built-in tests for every discoverable rule file" } | ||||||||
|
Subroutine
abstract: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub description { | ||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 16 | 0 | "Runs Log::Munger::RulesTest over every rule file found across the search path and prints a | |||||||||
| 17 | pass/fail summary. Add -v to print each error and warning rather than just the counts. | ||||||||||
| 18 | |||||||||||
| 19 | Exits non-zero if any file has errors or fails to load, which makes this the thing to run in | ||||||||||
| 20 | CI. | ||||||||||
| 21 | "; | ||||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | sub validate { return 1 } | ||||||||
|
Subroutine
validate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: called CC=10 SCAR=27.5
Pod
documented
| |||||||||||
| 27 | 1 | my ( $self, $opts, $args ) = @_; | |||||||||
| 28 | |||||||||||
| 29 | # only the names are wanted, since each one is handed to | ||||||||||
| 30 | # Log::Munger::RulesTest, which resolves names itself | ||||||||||
| 31 | 1 | my @names = sort( keys( %{ Log::Munger::WhichRuleFile->available_rule_files } ) ); | |||||||||
| 32 | 1 | ▶ | if ( !@names ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | print "no rule files found\n"; | |||||||||
| 34 | 0 | return; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 1 | my $failed = 0; | |||||||||
| 38 | 1 | foreach my $name (@names) { | |||||||||
| 39 | 90 | my $res = Log::Munger::RulesTest->test( 'file' => $name ); | |||||||||
| 40 | |||||||||||
| 41 | 90 | ▶ | if ( defined( $res->{'fatal'} ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | $failed++; | |||||||||
| 43 | 0 | printf( "FAIL %-24s fatal: %s\n", $name, $res->{'fatal'} ); | |||||||||
| 44 | 0 | next; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 90 | my $errors = scalar( @{ $res->{'errors'} } ); | |||||||||
| 48 | 90 | my $warnings = scalar( @{ $res->{'warnings'} } ); | |||||||||
| 49 | 90 | ▶ | $failed++ if ($errors); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 90 | ▶ | printf( "%-5s %-24s %d error(s), %d warning(s)\n", ( $errors ? 'FAIL' : 'ok' ), $name, $errors, $warnings ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 90 | ▶ | if ( $opts->{'verbose'} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | print " ERROR: $_\n" for ( @{ $res->{'errors'} } ); | |||||||||
| 54 | 0 | print " warn: $_\n" for ( @{ $res->{'warnings'} } ); | |||||||||
| 55 | } | ||||||||||
| 56 | } ## end foreach my $name (@names) | ||||||||||
| 57 | |||||||||||
| 58 | 1 | printf( "\n%d file(s), %d failed\n", scalar(@names), $failed ); | |||||||||
| 59 | 1 | ▶ | exit(1) if ($failed); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | |||||||||||
| 61 | 1 | return; | |||||||||
| 62 | } ## end sub execute | ||||||||||
| 63 | |||||||||||
| 64 | 16 | 1; | |||||||||