| 1 | 14 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 2 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | package App::pherkin 0.87; | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 14 | ▶ | use lib; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use Module::Runtime qw(use_module module_notional_filename); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 14 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 14 | ▶ | use FindBin qw($RealBin $Script); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 14 | ▶ | use YAML qw( LoadFile ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 14 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 14 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 14 | ▶ | use Path::Class qw/file dir/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 14 | ▶ | use Cucumber::TagExpressions; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | use Test::BDD::Cucumber::I18n | ||||||||||||||||||||||||||||||||
| 21 | 14 | ▶ | qw(languages langdef readable_keywords keyword_to_subname); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 14 | ▶ | use Test::BDD::Cucumber::Loader; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 14 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | 14 | ▶ | use Types::Standard qw( ArrayRef Bool Str ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | 25 | ▶ | has 'step_paths' => ( is => 'rw', isa => ArrayRef, default => sub { [] } ); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | 25 | ▶ | has 'extensions' => ( is => 'rw', isa => ArrayRef, default => sub { [] } ); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 28 | 14 | has 'tags' => ( is => 'rw', isa => Str, default => '' ); | |||||||||||||||||||||||||||||||
| 29 | 14 | has 'match_only' => ( is => 'rw', isa => Bool, default => 0 ); | |||||||||||||||||||||||||||||||
| 30 | 14 | has 'matching' => ( is => 'rw', isa => Str, default => 'first'); | |||||||||||||||||||||||||||||||
| 31 | 14 | has 'strict' => ( is => 'rw', isa => Bool, default => 0 ); | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 14 | has 'harness' => ( is => 'rw' ); | |||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | App::pherkin - Run Cucumber tests from the command line | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | version 0.87 | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | pherkin | ||||||||||||||||||||||||||||||||
| 46 | pherkin some/path/features/ | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | C<pherkin> will search the directory specified (or C<./features/>) for | ||||||||||||||||||||||||||||||||
| 51 | feature files (any file matching C<*.feature>) and step definition files (any | ||||||||||||||||||||||||||||||||
| 52 | file matching C<*_steps.pl>), loading the step definitions and then executing | ||||||||||||||||||||||||||||||||
| 53 | the features. | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | Steps that pass will be printed in green, those that fail in red, and those | ||||||||||||||||||||||||||||||||
| 56 | for which there is no step definition as yellow (for TODO), assuming you're | ||||||||||||||||||||||||||||||||
| 57 | using the default output harness. | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | =head2 run | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | The C<App::pherkin> class, which is what the C<pherkin> command uses, makes | ||||||||||||||||||||||||||||||||
| 64 | use of the C<run()> method, which accepts currently a single path as a string, | ||||||||||||||||||||||||||||||||
| 65 | or nothing. | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | Returns a L<Test::BDD::Cucumber::Model::Result> object for all steps run. | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 14 | ▶ | sub _pre_run { | ||||||||||||||||||||||||||||||
|
Subroutine
_pre_run: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||
| 72 | 14 | my ( $self, @arguments ) = @_; | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | # localized features will have utf8 in them and options may output utf8 as | ||||||||||||||||||||||||||||||||
| 75 | # well | ||||||||||||||||||||||||||||||||
| 76 | 14 | binmode STDOUT, ':utf8'; | |||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 14 | my ($features_path) = $self->_process_arguments(@arguments); | |||||||||||||||||||||||||||||||
| 79 | 14 | ▶ | $features_path ||= './features/'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$features_path ||= "./features/"
MC/DC0%0/1
$features_path ||= "./features/"
$features_path
Truth table50%1/2
A
A= $features_path
| |||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 14 | my ( $executor, @features ) = | |||||||||||||||||||||||||||||||
| 82 | Test::BDD::Cucumber::Loader->load( $features_path ); | ||||||||||||||||||||||||||||||||
| 83 | 14 | ▶ | die "No feature files found in $features_path" unless @features; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 14 | $executor->matching( $self->matching ); | |||||||||||||||||||||||||||||||
| 86 | 14 | $executor->add_extensions($_) for @{ $self->extensions }; | |||||||||||||||||||||||||||||||
| 87 | 14 | $_->pre_execute($self) for @{ $self->extensions }; | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | Test::BDD::Cucumber::Loader->load_steps( $executor, $_ ) | ||||||||||||||||||||||||||||||||
| 90 | 14 | for @{ $self->step_paths }; | |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 14 | return ( $executor, @features ); | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 14 | ▶ | sub _post_run { | ||||||||||||||||||||||||||||||
|
Subroutine
_post_run: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 96 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 14 | $_->post_execute() for reverse @{ $self->extensions }; | |||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 14 | ▶ | sub run { | ||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 103 | 14 | my ( $self, @arguments ) = @_; | |||||||||||||||||||||||||||||||
| 104 | 14 | my ( $executor, @features ) = $self->_pre_run(@arguments); | |||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 14 | ▶ | if ( $self->match_only ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | 1 | ▶ | $self->_make_executor_match_only($executor) if $self->match_only; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | 1 | $self->_rename_feature_steps( @features ); | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 14 | my $result = $self->_run_tests( $executor, @features ); | |||||||||||||||||||||||||||||||
| 112 | 14 | $self->_post_run; | |||||||||||||||||||||||||||||||
| 113 | 14 | return $result; | |||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 14 | ▶ | sub _run_tests { | ||||||||||||||||||||||||||||||
|
Subroutine
_run_tests: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||
| 117 | 14 | my ( $self, $executor, @features ) = @_; | |||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 14 | my $harness = $self->harness; | |||||||||||||||||||||||||||||||
| 120 | 14 | $harness->startup(); | |||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 14 | my $tag_spec; | |||||||||||||||||||||||||||||||
| 123 | 14 | ▶ | if ( $self->tags ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 124 | 4 | $tag_spec = Cucumber::TagExpressions->parse( $self->tags ); | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 14 | $executor->execute( $_, $harness, $tag_spec ) for @features; | |||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 14 | $harness->shutdown(); | |||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 14 | my $exit_code = 0; | |||||||||||||||||||||||||||||||
| 132 | 14 | my $result = $harness->result->result; | |||||||||||||||||||||||||||||||
| 133 | 14 | ▶ | if ($result eq 'failing') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 134 | 1 | $exit_code = 2; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | elsif ($self->strict) { | ||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | if ($result eq 'pending' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$result eq "pending" or $result eq "undefined"
MC/DC0%0/2
$result eq "pending" or $result eq "undefined"
$result eq "pending"
$result eq "undefined"
Truth table33%1/3
A or B
A= $result eq "pending"B= $result eq "undefined"
| |||||||||||||||||||||||||||||||||
| 138 | or $result eq 'undefined') { | ||||||||||||||||||||||||||||||||
| 139 | 1 | $exit_code = 1; | |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | 14 | return $exit_code; | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 25 | ▶ | sub _initialize_harness { | ||||||||||||||||||||||||||||||
|
Subroutine
_initialize_harness: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||
| 147 | 25 | my ( $self, $harness_module ) = @_; | |||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 25 | my $harness_args_string = undef; | |||||||||||||||||||||||||||||||
| 150 | 25 | ( $harness_module, $harness_args_string ) = split /\(/, $harness_module, 2; | |||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 25 | ▶ | unless ( $harness_module =~ m/::/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | 21 | $harness_module = "Test::BDD::Cucumber::Harness::" . $harness_module; | |||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 25 | ▶ | eval { use_module($harness_module) } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 157 | || die "Unable to load harness [$harness_module]: $@"; | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 25 | ▶ | if ( $harness_args_string ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 160 | 1 | my %harness_args; | |||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | eval "%harness_args = ($harness_args_string; 1" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 162 | or die $@; | ||||||||||||||||||||||||||||||||
| 163 | 1 | $self->harness( $harness_module->new( %harness_args ) ); | |||||||||||||||||||||||||||||||
| 164 | } else { | ||||||||||||||||||||||||||||||||
| 165 | 24 | $self->harness( $harness_module->new() ); | |||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 31 | ▶ | sub _find_config_file { | ||||||||||||||||||||||||||||||
|
Subroutine
_find_config_file: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 171 | 31 | my ( $self, $config_filename, $debug ) = @_; | |||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | 31 | ▶ | return $config_filename if $config_filename; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | 21 | ▶ | for ( | ||||||||||||||||||||||||||||||
|
Condition100%3/3
$ENV{'PHERKIN_CONFIG'} || ()
MC/DC100%2/2
$ENV{'PHERKIN_CONFIG'} || ()
$ENV{'PHERKIN_CONFIG'}
()
Truth table100%3/3
A || B
A= $ENV{'PHERKIN_CONFIG'}B= ()
| |||||||||||||||||||||||||||||||||
| 176 | ( $ENV{'PHERKIN_CONFIG'} || () ), | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | # Allow .yaml or .yml for all of the below | ||||||||||||||||||||||||||||||||
| 179 | 105 | map { ( "$_.yaml", "$_.yml" ) } ( | |||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | # Relative locations | ||||||||||||||||||||||||||||||||
| 182 | 84 | ( map { file($_) } | |||||||||||||||||||||||||||||||
| 183 | qw!.pherkin config/pherkin ./.config/pherkin t/.pherkin! | ||||||||||||||||||||||||||||||||
| 184 | ), | ||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | # Home locations | ||||||||||||||||||||||||||||||||
| 187 | 21 | ( map { dir($_)->file('.pherkin') } | |||||||||||||||||||||||||||||||
| 188 | 42 | grep {$_} map { $ENV{$_} } qw/HOME USERPROFILE/ | |||||||||||||||||||||||||||||||
| 189 | ) | ||||||||||||||||||||||||||||||||
| 190 | ) | ||||||||||||||||||||||||||||||||
| 191 | ) | ||||||||||||||||||||||||||||||||
| 192 | { | ||||||||||||||||||||||||||||||||
| 193 | 201 | ▶ | return $_ if -f $_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 194 | 200 | ▶ | print "No config file found in $_\n" if $debug; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||
| 196 | 20 | return undef; | |||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 3 | ▶ | sub _replace_helper { | ||||||||||||||||||||||||||||||
|
Subroutine
_replace_helper: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 200 | 3 | my $inval = shift; | |||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | 3 | ▶ | return $ENV{$inval} // "Environment variable $inval not defined"; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{$inval} // "Environment variable $inval not defined"
MC/DC100%1/1
$ENV{$inval} // "Environment variable $inval not defined"
$ENV{$inval}
Truth table100%2/2
A
A= $ENV{$inval}
| |||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | 170 | ▶ | sub _resolve_envvars { | ||||||||||||||||||||||||||||||
|
Subroutine
_resolve_envvars: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 206 | 170 | my ( $config_data ) = shift; | |||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | 170 | ▶ | if (ref $config_data) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 209 | 92 | ▶ | if (ref $config_data eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 210 | return { | ||||||||||||||||||||||||||||||||
| 211 | map { | ||||||||||||||||||||||||||||||||
| 212 | 66 | $_ => _resolve_envvars( $config_data->{$_} ) | |||||||||||||||||||||||||||||||
| 213 | } keys %$config_data | ||||||||||||||||||||||||||||||||
| 214 | }; | ||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||
| 216 | elsif (ref $config_data eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
| 217 | 26 | return [ map { _resolve_envvars( $_ ) } @$config_data ]; | |||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||
| 219 | else { | ||||||||||||||||||||||||||||||||
| 220 | 0 | die 'Unhandled reference type in configuration data'; | |||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||
| 223 | else { | ||||||||||||||||||||||||||||||||
| 224 | # replace (in-place) ${ENVVAR_NAME} sequences with the envvar value | ||||||||||||||||||||||||||||||||
| 225 | 78 | $config_data =~ s/(?<!\$)\$\{([a-zA-Z0-9_]+)\}/_replace_helper($1)/ge; | |||||||||||||||||||||||||||||||
| 226 | # remove any escaping double dollar-signs | ||||||||||||||||||||||||||||||||
| 227 | 78 | $config_data =~ s/\$(\$\{[a-zA-Z0-9_]+\})/$1/g; | |||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | 78 | return $config_data; | |||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | 29 | ▶ | sub _load_config { | ||||||||||||||||||||||||||||||
|
Subroutine
_load_config: called CC=20 SCAR=31.4
| |||||||||||||||||||||||||||||||||
| 234 | 29 | my ( $self, $profile_name, $proposed_config_filename, $debug ) = @_; | |||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | 29 | my $config_filename | |||||||||||||||||||||||||||||||
| 237 | = $self->_find_config_file( $proposed_config_filename, $debug ); | ||||||||||||||||||||||||||||||||
| 238 | 29 | my $config_data_whole; | |||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | # Check we can actually load some data from that file if required | ||||||||||||||||||||||||||||||||
| 241 | 29 | ▶ | if ($config_filename) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 242 | 9 | ▶ | print "Found [$config_filename], reading...\n" if $debug; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 243 | 9 | $config_data_whole = LoadFile($config_filename); | |||||||||||||||||||||||||||||||
| 244 | 8 | ▶ | $config_data_whole = _resolve_envvars( $config_data_whole ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 245 | if $config_data_whole; | ||||||||||||||||||||||||||||||||
| 246 | } else { | ||||||||||||||||||||||||||||||||
| 247 | 20 | ▶ | if ($profile_name) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | print "No configuration files found\n" if $debug; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 249 | 0 | die | |||||||||||||||||||||||||||||||
| 250 | "Profile name [$profile_name] specified, but no configuration file found (use --debug-profiles to debug)"; | ||||||||||||||||||||||||||||||||
| 251 | } else { | ||||||||||||||||||||||||||||||||
| 252 | 20 | ▶ | print "No configuration files found, and no profile specified\n" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 253 | if $debug; | ||||||||||||||||||||||||||||||||
| 254 | 20 | return; | |||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | 8 | ▶ | $profile_name = 'default' unless defined $profile_name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | # Check the config file has the right type of data at the profile name | ||||||||||||||||||||||||||||||||
| 261 | 8 | ▶ | unless ( ref $config_data_whole eq 'HASH' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 262 | 1 | die | |||||||||||||||||||||||||||||||
| 263 | "Config file [$config_filename] doesn't return a hashref on parse, instead a [" | ||||||||||||||||||||||||||||||||
| 264 | . ref($config_data_whole) . ']'; | ||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||
| 266 | 7 | my $config_data = $config_data_whole->{$profile_name}; | |||||||||||||||||||||||||||||||
| 267 | 3 | ▶ | my $profile_problem = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 268 | 3 | return "Config file [$config_filename] profile [$profile_name]: " | |||||||||||||||||||||||||||||||
| 269 | . shift(); | ||||||||||||||||||||||||||||||||
| 270 | 7 | }; | |||||||||||||||||||||||||||||||
| 271 | 7 | ▶ | unless ($config_data) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 272 | 1 | die $profile_problem->("Profile not found"); | |||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||
| 274 | 6 | ▶ | unless ( ( my $reftype = ref $config_data ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 275 | 1 | die $profile_problem->("[$reftype] but needs to be a HASH"); | |||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||
| 277 | 5 | ▶ | print "Using profile [$profile_name]\n" if $debug; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | # Transform it in to an argument list | ||||||||||||||||||||||||||||||||
| 280 | 5 | my @arguments; | |||||||||||||||||||||||||||||||
| 281 | 5 | for my $key ( sort keys %$config_data ) { | |||||||||||||||||||||||||||||||
| 282 | 9 | my $value = $config_data->{$key}; | |||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 9 | ▶ | if ( my $reftype = ref $value ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 285 | 6 | ▶ | if ( $key ne 'extensions' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 286 | 4 | ▶ | die $profile_problem->( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 287 | "Option $key is a [$reftype] but can only be a single value or ARRAY" | ||||||||||||||||||||||||||||||||
| 288 | ) unless $reftype eq 'ARRAY'; | ||||||||||||||||||||||||||||||||
| 289 | 3 | push( @arguments, $key, $_ ) for @$value; | |||||||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||||||
| 291 | 2 | ▶ | die $profile_problem->( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$reftype eq "HASH" and $key eq "extensions"
MC/DC0%0/2
$reftype eq "HASH" and $key eq "extensions"
$reftype eq "HASH"
$key eq "extensions"
Truth table33%1/3
A and B
A= $reftype eq "HASH"B= $key eq "extensions"
| |||||||||||||||||||||||||||||||||
| 292 | "Option $key is a [$reftype] but can only be a HASH as '$key' is" | ||||||||||||||||||||||||||||||||
| 293 | . " a special case - see the documentation for details" | ||||||||||||||||||||||||||||||||
| 294 | ) unless $reftype eq 'HASH' && $key eq 'extensions'; | ||||||||||||||||||||||||||||||||
| 295 | 2 | push( @arguments, $key, $value ); | |||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||
| 297 | } else { | ||||||||||||||||||||||||||||||||
| 298 | 3 | push( @arguments, $key, $value ); | |||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | 4 | ▶ | if ($debug) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 303 | 0 | print "Arguments to add: " . ( join ' ', @arguments ) . "\n"; | |||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||
| 306 | 4 | return @arguments; | |||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||
| 309 | 20 | ▶ | sub _process_arguments { | ||||||||||||||||||||||||||||||
|
Subroutine
_process_arguments: called CC=38 SCAR=40.2
| |||||||||||||||||||||||||||||||||
| 310 | 20 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||
| 311 | 20 | local @ARGV = @args; | |||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||
| 313 | # Allow -Ilib, -bl | ||||||||||||||||||||||||||||||||
| 314 | 20 | Getopt::Long::Configure( 'bundling', 'pass_through' ); | |||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | 20 | my %options = ( | |||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||
| 318 | # Relating to other configuration options | ||||||||||||||||||||||||||||||||
| 319 | config => ['g|config=s'], | ||||||||||||||||||||||||||||||||
| 320 | profile => ['p|profile=s'], | ||||||||||||||||||||||||||||||||
| 321 | debug_profiles => ['debug-profiles'], | ||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||
| 323 | # Standard | ||||||||||||||||||||||||||||||||
| 324 | help => [ 'h|help|?' ], | ||||||||||||||||||||||||||||||||
| 325 | version => [ 'version' ], | ||||||||||||||||||||||||||||||||
| 326 | includes => [ 'I=s@', [] ], | ||||||||||||||||||||||||||||||||
| 327 | lib => [ 'l|lib' ], | ||||||||||||||||||||||||||||||||
| 328 | blib => [ 'b|blib' ], | ||||||||||||||||||||||||||||||||
| 329 | output => [ 'o|output=s' ], | ||||||||||||||||||||||||||||||||
| 330 | strict => [ 'strict' ], | ||||||||||||||||||||||||||||||||
| 331 | steps => [ 's|steps=s@', [] ], | ||||||||||||||||||||||||||||||||
| 332 | tags => [ 't|tags=s' ], | ||||||||||||||||||||||||||||||||
| 333 | i18n => [ 'i18n=s' ], | ||||||||||||||||||||||||||||||||
| 334 | extensions => [ 'e|extension=s@', [] ], | ||||||||||||||||||||||||||||||||
| 335 | matching => [ 'matching=s' ], | ||||||||||||||||||||||||||||||||
| 336 | match_only => [ 'm|match' ], | ||||||||||||||||||||||||||||||||
| 337 | ); | ||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||
| 339 | GetOptions( | ||||||||||||||||||||||||||||||||
| 340 | map { | ||||||||||||||||||||||||||||||||
| 341 | 20 | my $x; | |||||||||||||||||||||||||||||||
| 342 | 320 | ▶ | $_->[1] = \$x unless defined $_->[1]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 343 | 320 | ( $_->[0] => $_->[1] ); | |||||||||||||||||||||||||||||||
| 344 | } values %options | ||||||||||||||||||||||||||||||||
| 345 | ); | ||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||
| 347 | 374 | ▶ | my $deref = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 348 | 374 | my $key = shift; | |||||||||||||||||||||||||||||||
| 349 | 374 | my $value = $options{$key}->[1]; | |||||||||||||||||||||||||||||||
| 350 | 374 | ▶ | return ( ref $value eq 'ARRAY' ) ? $value : $$value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 351 | 20 | }; | |||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||
| 353 | 20 | ▶ | if ( $deref->('version') ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 354 | 0 | my ($vol, $dirs, $file) = File::Spec->splitpath( $0 ); | |||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | my $version = $App::pherkin::VERSION || '(development)'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$App::pherkin::VERSION || '(development)'
MC/DC0%0/1
$App::pherkin::VERSION || '(development)'
$App::pherkin::VERSION
Truth table0%0/2
A
A= $App::pherkin::VERSION
| |||||||||||||||||||||||||||||||||
| 356 | 0 | print "$file $version\n"; | |||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||
| 358 | 0 | exit 0; | |||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||
| 361 | pod2usage( | ||||||||||||||||||||||||||||||||
| 362 | 20 | ▶ | -verbose => 1, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 363 | -input => "$RealBin/$Script", | ||||||||||||||||||||||||||||||||
| 364 | ) if $deref->('help'); | ||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||
| 366 | 20 | my @parsed_extensions; | |||||||||||||||||||||||||||||||
| 367 | 20 | for my $e ( @{ $deref->('extensions') } ) { | |||||||||||||||||||||||||||||||
| 368 | 2 | my $e_args = "()"; | |||||||||||||||||||||||||||||||
| 369 | 2 | ▶ | $e_args = $1 if $e =~ s/\((.+)\)$//; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 370 | 2 | my @e_args = eval $e_args; | |||||||||||||||||||||||||||||||
| 371 | 2 | ▶ | die "Bad arguments in [$e]: $@" if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||
| 373 | 2 | push( @parsed_extensions, [ $e, \@e_args ] ); | |||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||
| 375 | 20 | $options{extensions}->[1] = \@parsed_extensions; | |||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||
| 377 | # Load the configuration file | ||||||||||||||||||||||||||||||||
| 378 | 20 | my @configuration_options = $self->_load_config( map { $deref->($_) } | |||||||||||||||||||||||||||||||
| 379 | qw/profile config debug_profiles/ ); | ||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||
| 381 | # Merge those configuration items | ||||||||||||||||||||||||||||||||
| 382 | # First we need a list of matching keys | ||||||||||||||||||||||||||||||||
| 383 | my %keys = map { | ||||||||||||||||||||||||||||||||
| 384 | 20 | my ( $key_basis, $ref ) = @{ $options{$_} }; | |||||||||||||||||||||||||||||||
| 385 | 860 | map { $_ => $ref } | |||||||||||||||||||||||||||||||
| 386 | 320 | map { s/=.+//; $_ } ( split( /\|/, $key_basis ), $_ ); | |||||||||||||||||||||||||||||||
| 387 | } keys %options; | ||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | # Now let's go through each option. For arrays, we want the configuration | ||||||||||||||||||||||||||||||||
| 390 | # options to appear in order at the front. So if configuration had 1, 2, | ||||||||||||||||||||||||||||||||
| 391 | # and command line options were 3, 4, we want: 1, 2, 3, 4. This is not | ||||||||||||||||||||||||||||||||
| 392 | # straight forward. | ||||||||||||||||||||||||||||||||
| 393 | 20 | my %additions; | |||||||||||||||||||||||||||||||
| 394 | 20 | ▶ | while (@configuration_options) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 395 | 5 | my ($key) = shift(@configuration_options); | |||||||||||||||||||||||||||||||
| 396 | 5 | my ($value) = shift(@configuration_options); | |||||||||||||||||||||||||||||||
| 397 | 5 | ▶ | my $target = $keys{$key} || die "Unknown configuration option [$key]"; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$keys{$key} || die("Unknown configuration option [$key]")
MC/DC0%0/1
$keys{$key} || die("Unknown configuration option [$key]")
$keys{$key}
Truth table50%1/2
A
A= $keys{$key}
| |||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | 5 | ▶ | if ( $key eq 'extensions' || $key eq 'extension' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$key eq "extensions" or $key eq "extension"
MC/DC50%1/2
$key eq "extensions" or $key eq "extension"
$key eq "extensions"
$key eq "extension"
Truth table66%2/3
A or B
A= $key eq "extensions"B= $key eq "extension"
| |||||||||||||||||||||||||||||||||
| 400 | 1 | ▶ | die "Value of $key in config file expected to be HASH but isn't" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 401 | if ref $value ne 'HASH'; | ||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||
| 403 | # if the configuration of the extension is 'undef', then | ||||||||||||||||||||||||||||||||
| 404 | # none was defined. Replace it with an empty hashref, which | ||||||||||||||||||||||||||||||||
| 405 | # is what Moo's 'new()' method wants later on | ||||||||||||||||||||||||||||||||
| 406 | 1 | ▶ | my @e = map { [ $_, [ $value->{$_} || {} ] ] } keys %$value; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$value->{$_} || {}
MC/DC0%0/1
$value->{$_} || {}
$value->{$_}
Truth table50%1/2
A
A= $value->{$_}
| |||||||||||||||||||||||||||||||||
| 407 | 1 | $value = \@e; | |||||||||||||||||||||||||||||||
| 408 | 1 | ▶ | my $array = $additions{ 0 + $target } ||= []; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$additions{0 + $target} ||= []
MC/DC0%0/1
$additions{0 + $target} ||= []
$additions{0 + $target}
Truth table50%1/2
A
A= $additions{0 + $target}
| |||||||||||||||||||||||||||||||||
| 409 | 1 | push( @$array, @$value ); | |||||||||||||||||||||||||||||||
| 410 | 1 | ▶ | print "Adding extensions near the front of $key" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 411 | if $deref->('debug_profiles'); | ||||||||||||||||||||||||||||||||
| 412 | } elsif ( ref $target ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | # Only use it if we don't have something already | ||||||||||||||||||||||||||||||||
| 415 | 2 | ▶ | if ( defined $$target ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 416 | 1 | ▶ | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 417 | "Ignoring $key from config file because set on cmd line as $$target\n" | ||||||||||||||||||||||||||||||||
| 418 | if $deref->('debug_profiles'); | ||||||||||||||||||||||||||||||||
| 419 | } else { | ||||||||||||||||||||||||||||||||
| 420 | 1 | $$target = $value; | |||||||||||||||||||||||||||||||
| 421 | 1 | ▶ | print "Set $key to $target from config file\n" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 422 | if $deref->('debug_profiles'); | ||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||
| 425 | } else { | ||||||||||||||||||||||||||||||||
| 426 | 2 | ▶ | my $array = $additions{ 0 + $target } ||= []; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$additions{0 + $target} ||= []
MC/DC100%1/1
$additions{0 + $target} ||= []
$additions{0 + $target}
Truth table100%2/2
A
A= $additions{0 + $target}
| |||||||||||||||||||||||||||||||||
| 427 | 2 | push( @$array, $value ); | |||||||||||||||||||||||||||||||
| 428 | 2 | ▶ | print "Adding $value near the front of $key\n" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 429 | if $deref->('debug_profiles'); | ||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||
| 432 | 20 | for my $target ( values %options ) { | |||||||||||||||||||||||||||||||
| 433 | 320 | ▶ | next unless ref $target->[1] eq 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 434 | 60 | my $key = $target->[1] + 0; | |||||||||||||||||||||||||||||||
| 435 | 60 | ▶ | unshift( @{ $target->[1] }, @{ $additions{$key} || [] } ); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$additions{$key} || []
MC/DC100%1/1
$additions{$key} || []
$additions{$key}
Truth table100%2/2
A
A= $additions{$key}
| |||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||
| 438 | 20 | ▶ | if ( $deref->('debug_profiles') ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 439 | 0 | print "Values are:\n"; | |||||||||||||||||||||||||||||||
| 440 | 0 | for ( sort keys %options ) { | |||||||||||||||||||||||||||||||
| 441 | 0 | printf( " %16s: ", $_ ); | |||||||||||||||||||||||||||||||
| 442 | 0 | my $value = $deref->($_); | |||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if ( ref $value ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 444 | 0 | print join ', ', @$value; | |||||||||||||||||||||||||||||||
| 445 | } else { | ||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | print( ( defined $value ) ? $value : '[undefined]' ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||
| 448 | 0 | print "\n"; | |||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||
| 450 | 0 | exit; | |||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||
| 453 | 20 | ▶ | if ( my $i18n = $deref->('i18n') ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | _print_langdef($i18n) unless $i18n eq 'help'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 455 | 0 | _print_languages(); | |||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||
| 458 | 20 | ▶ | unshift @{ $deref->('includes') }, 'lib' if $deref->('lib'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 459 | 20 | ▶ | unshift @{ $deref->('includes') }, 'blib/lib', 'blib/arch' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 460 | if $deref->('blib'); | ||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||
| 462 | # We may need some of the imported paths... | ||||||||||||||||||||||||||||||||
| 463 | 20 | lib->import( @{ $deref->('includes') } ); | |||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||
| 465 | # Load any extensions | ||||||||||||||||||||||||||||||||
| 466 | 20 | for my $e ( @{ $deref->('extensions') } ) { | |||||||||||||||||||||||||||||||
| 467 | 3 | my ( $c, $a ) = @$e; | |||||||||||||||||||||||||||||||
| 468 | 3 | use_module $c; | |||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||
| 470 | 3 | my $instance = $c->new(@$a); | |||||||||||||||||||||||||||||||
| 471 | 3 | push( @{ $self->extensions }, $instance ); | |||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||
| 473 | 3 | my $dir = file( $INC{ module_notional_filename($c) } )->dir; | |||||||||||||||||||||||||||||||
| 474 | 3 | my @step_dirs = map { File::Spec->rel2abs( $_, $dir ) } | |||||||||||||||||||||||||||||||
| 475 | 3 | @{ $instance->step_directories }; | |||||||||||||||||||||||||||||||
| 476 | 3 | unshift( @{ $deref->('steps') }, @step_dirs ); | |||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||
| 479 | # Munge the output harness | ||||||||||||||||||||||||||||||||
| 480 | 20 | ▶ | $self->_initialize_harness( $deref->('output') || "TermColor" ); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
&$deref('output') || 'TermColor'
MC/DC100%1/1
&$deref('output') || 'TermColor'
&$deref('output')
Truth table100%2/2
A
A= &$deref('output')
| |||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||
| 482 | # Store any extra step paths | ||||||||||||||||||||||||||||||||
| 483 | 20 | $self->step_paths( $deref->('steps') ); | |||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||
| 485 | 20 | ▶ | $self->tags( $deref->('tags') // '' ); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
&$deref("tags") // ""
MC/DC100%1/1
&$deref("tags") // ""
&$deref("tags")
Truth table100%2/2
A
A= &$deref("tags")
| |||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||
| 487 | 20 | ▶ | $self->matching( $deref->('matching') ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 488 | if $deref->('matching'); | ||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||
| 490 | # Match only? | ||||||||||||||||||||||||||||||||
| 491 | 20 | $self->match_only( $deref->('match_only') ); | |||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||
| 493 | 20 | ▶ | $self->strict( $deref->('strict') ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 494 | if $deref->('strict'); | ||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||
| 496 | 20 | return ( pop @ARGV ); | |||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | sub _print_languages { | ||||||||||||||||||||||||||||||
|
Subroutine
_print_languages: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||
| 501 | 0 | my @languages = languages(); | |||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||
| 503 | 0 | my $max_code_length = max map {length} @languages; | |||||||||||||||||||||||||||||||
| 504 | my $max_name_length | ||||||||||||||||||||||||||||||||
| 505 | 0 | = max map { length( langdef($_)->{name} ) } @languages; | |||||||||||||||||||||||||||||||
| 506 | my $max_native_length | ||||||||||||||||||||||||||||||||
| 507 | 0 | = max map { length( langdef($_)->{native} ) } @languages; | |||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||
| 509 | 0 | my $format | |||||||||||||||||||||||||||||||
| 510 | = "| %-${max_code_length}s | %-${max_name_length}s | %-${max_native_length}s |\n"; | ||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||
| 512 | 0 | for my $language ( sort @languages ) { | |||||||||||||||||||||||||||||||
| 513 | 0 | my $langdef = langdef($language); | |||||||||||||||||||||||||||||||
| 514 | 0 | printf $format, $language, $langdef->{name}, $langdef->{native}; | |||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||
| 516 | 0 | exit; | |||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | sub _print_langdef { | ||||||||||||||||||||||||||||||
|
Subroutine
_print_langdef: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 520 | 0 | my ($language) = @_; | |||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||
| 522 | 0 | my $langdef = langdef($language); | |||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||
| 524 | 0 | my @keywords = qw(feature background scenario scenarioOutline examples | |||||||||||||||||||||||||||||||
| 525 | given when then and but); | ||||||||||||||||||||||||||||||||
| 526 | my $max_length | ||||||||||||||||||||||||||||||||
| 527 | 0 | = max map { length readable_keywords( $langdef->{$_} ) } @keywords; | |||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||
| 529 | 0 | my $format = "| %-16s | %-${max_length}s |\n"; | |||||||||||||||||||||||||||||||
| 530 | 0 | for my $keyword ( | |||||||||||||||||||||||||||||||
| 531 | qw(feature background scenario scenarioOutline | ||||||||||||||||||||||||||||||||
| 532 | examples given when then and but ) | ||||||||||||||||||||||||||||||||
| 533 | ) | ||||||||||||||||||||||||||||||||
| 534 | { | ||||||||||||||||||||||||||||||||
| 535 | 0 | printf $format, $keyword, readable_keywords( $langdef->{$keyword} ); | |||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||
| 538 | 0 | my $codeformat = "| %-16s | %-${max_length}s |\n"; | |||||||||||||||||||||||||||||||
| 539 | 0 | for my $keyword (qw(given when then )) { | |||||||||||||||||||||||||||||||
| 540 | printf $codeformat, $keyword . ' (code)', | ||||||||||||||||||||||||||||||||
| 541 | 0 | readable_keywords( $langdef->{$keyword}, \&keyword_to_subname ); | |||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||
| 544 | 0 | exit; | |||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||
| 547 | 1 | ▶ | sub _make_executor_match_only { | ||||||||||||||||||||||||||||||
|
Subroutine
_make_executor_match_only: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 548 | 1 | my ($self, $executor) = @_; | |||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||
| 550 | 3 | ▶ | my $match_sub = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 551 | 3 | my $context = shift; | |||||||||||||||||||||||||||||||
| 552 | 3 | $Test::Builder::Test->ok( 1, "Test matched" ); | |||||||||||||||||||||||||||||||
| 553 | 3 | return 1; | |||||||||||||||||||||||||||||||
| 554 | 1 | }; | |||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||
| 556 | 1 | for my $verb ( keys %{$executor->steps} ) { | |||||||||||||||||||||||||||||||
| 557 | 3 | for my $step_tuple ( @{ $executor->steps->{$verb} } ) { | |||||||||||||||||||||||||||||||
| 558 | 3 | $step_tuple->[2] = $match_sub; | |||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||
| 562 | 1 | return 1; | |||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||
| 565 | 1 | ▶ | sub _rename_feature_steps { | ||||||||||||||||||||||||||||||
|
Subroutine
_rename_feature_steps: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||
| 566 | 1 | my ($self, @features) = @_; | |||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||
| 568 | 1 | my %steps; | |||||||||||||||||||||||||||||||
| 569 | 1 | for my $feature ( @features ) { | |||||||||||||||||||||||||||||||
| 570 | 1 | for my $scenario ( $feature->background, @{ $feature->scenarios } ) { | |||||||||||||||||||||||||||||||
| 571 | 2 | ▶ | next unless $scenario; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 572 | 1 | for my $step ( @{ $scenario->steps } ) { | |||||||||||||||||||||||||||||||
| 573 | 3 | $steps{ $step . '' } = $step; | |||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||
| 578 | 1 | for my $step_object ( values %steps ) { | |||||||||||||||||||||||||||||||
| 579 | 3 | ▶ | $step_object->verb_original( | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$step_object->verb_original || $step_object->verb
MC/DC0%0/2
$step_object->verb_original || $step_object->verb
$step_object->verb_original
$step_object->verb
Truth table33%1/3
A || B
A= $step_object->verb_originalB= $step_object->verb
| |||||||||||||||||||||||||||||||||
| 580 | 'MATCH MODE: ' . ( $step_object->verb_original || $step_object->verb ) | ||||||||||||||||||||||||||||||||
| 581 | ); | ||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||
| 585 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||
| 587 | Peter Sergeant C<pete@clueball.com> | ||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||
| 589 | =head1 LICENSE | ||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||
| 591 | Copyright 2019-2023, Erik Huelsmann | ||||||||||||||||||||||||||||||||
| 592 | Copyright 2011-2019, Peter Sergeant; Licensed under the same terms as Perl | ||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||
| 594 | =cut | ||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||
| 596 | 14 | 1; | |||||||||||||||||||||||||||||||