html/tool/lib/Marpa/R2/HTML/Test/Util.pm

filter: Statementstmt 78.0% 57 / 73 Branchbran 35.7% 5 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 4 totaltotal 70.2% 78 / 111 SCAR 24.1
CC
9
Cov
70%
load_or_skip_all
14.6
quotearg
2.7
run_command
2.0
CRAP 11.2
« blib/lib/Marpa/R2/Stuifzand.pm ↑ Summary blib/script/marpa_r2_html_score »
1 # Copyright 2022 Jeffrey Kegler
2 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
3 # redistribute it and/or modify it under the terms of the GNU Lesser
4 # General Public License as published by the Free Software Foundation,
5 # either version 3 of the License, or (at your option) any later version.
6 #
7 # Marpa::R2 is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 # Lesser General Public License for more details.
11 #
12 # You should have received a copy of the GNU Lesser
13 # General Public License along with Marpa::R2. If not, see
14 # http://www.gnu.org/licenses/.
15  
16 package Marpa::R2::HTML::Test::Util;
17  
18 # This code was based on study of the test suite in Andy Lester's Ack package
19  
20 11 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 11 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 11 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 11 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 11 ▶use Fatal qw(unlink open close);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 11 ▶use CPAN::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 11 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 sub is_win32 {
33 65 ▶ return $OSNAME =~ /Win32/xms;
Subroutine is_win32: called CC=1 SCAR=0.0
Pod undocumented
34 }
35  
36 sub quotearg {
37 65 ▶ my ($arg) = @_;
Subroutine quotearg: called CC=2 SCAR=10.1
Pod undocumented
38 65 ▶ return quotemeta $arg if not is_win32();
Branch: 1 branch
BranchTrueFalseTotal
unless is_win32() 65 0 65
39 0 $arg =~ s/(\\+)$/$1$1/xms; # Double all trailing backslashes
40 0 $arg =~ s/"/\\"/gxms; # Backslash all quotes
41 0 return qq{"$arg"};
42 } ## end sub quotearg
43  
44 sub run_command {
45 15 ▶ my (@args) = @_;
Subroutine run_command: called CC=2 SCAR=7.0
Pod undocumented
46  
47 15 my $blib = $ENV{MARPA_TEST_BLIB};
48 15 my $current_wd = Cwd::getcwd();
49 15 ▶ $blib //= $current_wd;
Condition33%1/3
$blib //= $current_wd
l!l&&r!l&&!r
0150
MC/DC0%0/2
$blib //= $current_wd
$blib $current_wd
Truth table33%1/3
A //= B
A= $blibB= $current_wd
ABresult
1X1
011
000
50 15 my $blib_arg = '-Mblib=' . quotearg($blib);
51  
52 # my $command = join q{ }, $EXECUTABLE_NAME, $blib_arg, map { quotearg($_) } @args;
53 15 my $command = join q{ }, $EXECUTABLE_NAME, map { quotearg($_) } @args;
54  
55 ## no critic (InputOutput::ProhibitBacktickOperators)
56 15 my $stdout = `$command`;
57 ## use critic
58  
59 15 my ( $sig, $core, $rc ) = (
60 ( $CHILD_ERROR & 127 ),
61 ( $CHILD_ERROR & 128 ),
62 ( $CHILD_ERROR >> 8 ),
63 );
64  
65 15 return $stdout;
66 } ## end sub run_command
67  
68 # This method must be called *BEFORE* any test plan is
69 # written -- it creates its own test plan
70 sub load_or_skip_all {
71 12 ▶ my ($module_name) = @_;
Subroutine load_or_skip_all: called CC=7 SCAR=26.8
Pod undocumented
72 ## no critic(BuiltinFunctions::ProhibitStringyEval)
73 12 my $eval_result = eval "require $module_name; '$module_name'->import; 1";
74 12 ▶ if ( !$eval_result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval_result) 0 12 12
75 0 my $eval_error = $EVAL_ERROR;
76 0 $eval_error =~ s/^/# /gxms;
77 0 ▶ print "1..0 # Skip Could not load $module_name\n", $eval_error
Branch: 1 branch
BranchTrueFalseTotal
print "1..0 # Skip Could not load $module_name\n", $eval_error or Carp::croak("say failed: $Marpa::R2::HTML::Test::Util::ERRNO") 0 0 0
78 or Carp::croak("say failed: $ERRNO");
79 0 exit 0;
80 } ## end if ( !$eval_result )
81 11 ▶ use lib 'config';
Subroutine BEGIN: called CC=1 SCAR=0.0
82 12 $eval_result = eval { require Marpa::R2::Config; 1 };
83 12 ▶ if ( !$eval_result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($eval_result) 0 12 12
84 0 Test::More::plan tests => 1;
85 0 Test::More::diag($EVAL_ERROR);
86 0 Test::More::fail("Could not load Marpa::R2::Config\n");
87 0 exit 0;
88 } ## end if ( !$eval_result )
89 12 my $version_wanted = $Marpa::R2::VERSION_FOR_CONFIG{$module_name};
90 12 ▶ if ( not defined $version_wanted ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $version_wanted) 0 12 12
91 0 Test::More::plan tests => 1;
92 0 Test::More::fail("$module_name is not known to Marpa::R2");
93 0 exit 0;
94 }
95 12 my $module_version = eval q{$} . $module_name . '::VERSION';
96 12 ▶ if ( CPAN::Version->vlt( $module_version, $version_wanted ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("CPAN::Version"->vlt($module_version, $version_wanted)) 0 12 12
97 0 ▶ say
Branch: 1 branch
BranchTrueFalseTotal
say "1..0 # Skip $module_name version is $module_version; we wanted $version_wanted" or Carp::croak("say failed: $Marpa::R2::HTML::Test::Util::ERRNO") 0 0 0
98 "1..0 # Skip $module_name version is $module_version; we wanted $version_wanted"
99 or Carp::croak("say failed: $ERRNO");
100 0 exit 0;
101 } ## end if ( vlt( $module_version, $version_wanted ) )
102 } ## end sub load_or_skip_all
103  
104 11 1;
105  
106 # vim: set expandtab shiftwidth=4:
« blib/lib/Marpa/R2/Stuifzand.pm ↑ Summary blib/script/marpa_r2_html_score »