blib/lib/Tapper/CLI/Scenario.pm

filter: Statementstmt 72.3% 47 / 65 Branchbran 50.0% 8 / 16 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 9 / 9 Podpod 66.6% 2 / 3 totaltotal 66.3% 67 / 101 CC 12 SCAR 26.5
CC
12
Cov
65%
b_create_scenario
24.6
setup
2.1
BEGIN
1.0
CRAP 14.1
« blib/lib/Tapper/CLI/Schema.pm ↑ Summary blib/lib/Tapper/CLI/DbDeploy/Command/makeschemadiffs.pm »
1 package Tapper::CLI::Scenario;
2 72 our $AUTHORITY = 'cpan:TAPPER';
3 72 $Tapper::CLI::Scenario::VERSION = '5.0.8';
4  
5 72 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 72 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 72 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 72 ▶use feature qw/ say /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 72 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 72 ▶no if $] >= 5.018, warnings => "experimental";
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13  
14 2 ▶sub ar_get_create_scenario_parameters {
Subroutine ar_get_create_scenario_parameters: called CC=1 SCAR=0.0
Pod undocumented
15 return [
16 2 [ 'file|f=s' , 'String; use macro scenario file', ],
17 [ 'dryrun|n' , 'Print evaluated scenario without submit to DB', ],
18 [ 'verbose|v' , 'some more informational output', ],
19 [ 'D' , 'Define a key=value pair used in macro preconditions', ],
20 [ 'help|?' , 'Print this help message and exit.', ],
21 ];
22 }
23  
24  
25 2 ▶sub b_create_scenario {
Subroutine b_create_scenario: called CC=11 SCAR=32.0
Pod documented
26  
27 2 my ( $or_app_rad ) = @_;
28  
29 2 my $ar_parameters = ar_get_create_scenario_parameters();
30 2 $or_app_rad->getopt( map { $_->[0] } @{$ar_parameters} );
31 2 my $hr_options = $or_app_rad->options;
32  
33 2 ▶ if ( $hr_options->{help} or not %$hr_options) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"help"} or not %$hr_options) 0 2 2
Condition33%1/3
$hr_options->{"help"} or not %$hr_options
l!l&&r!l&&!r
002
MC/DC0%0/2
$hr_options->{"help"} or not %$hr_options
$hr_options->{"help"} not %$hr_options
Truth table33%1/3
A or not(B)
A= $hr_options->{"help"}B= not %$hr_options
ABresult
1X1
011
000
34 0 say {*STDERR} "Usage: $PROGRAM_NAME scenario-new [options]";
35 0 require Tapper::CLI::Base;
36 0 Tapper::CLI::Base::b_print_help( $ar_parameters );
37 0 return;
38 }
39  
40 2 my $s_error;
41 2 ▶ if (! $hr_options->{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hr_options->{"file"}) 0 2 2
42 0 $s_error = 'Scenario file needed';
43 }
44 2 ▶ if (! -e $hr_options->{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $hr_options->{"file"}) 0 2 2
45 0 $s_error = 'Scenario file ' . $hr_options->{file} . ' does not exist';
46 }
47 2 ▶ if (! -r $hr_options->{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $hr_options->{"file"}) 0 2 2
48 0 $s_error = 'Scenario file ' . $hr_options->{file} . ' is not readable';
49 }
50 2 ▶ if ( $s_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s_error) 0 2 2
51 0 die "error: $s_error\n";
52 }
53  
54 2 require Tapper::Cmd::Scenario;
55 2 my $or_scenario = Tapper::Cmd::Scenario->new();
56 2 my $s_scenario_text = $or_scenario->apply_macro($hr_options->{file}, $hr_options->{d});
57  
58 2 require YAML::Syck;
59 2 my @scenario_conf = YAML::Syck::Load( $s_scenario_text );
60 2 ▶ if ($hr_options->{dryrun}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{"dryrun"}) 0 2 2
61 0 say STDERR $s_scenario_text;
62 0 return;
63 }
64  
65 2 my @scenario_ids = $or_scenario->add(\@scenario_conf);
66  
67 2 ▶ if ( $hr_options->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_options->{'verbose'}) { } 0 2 2
68  
69 0 require Tapper::Model;
70 0 require Tapper::Config;
71 0 foreach my $i_scenario_id (@scenario_ids) {
72 0 my @a_testrun_ids = Tapper::Model::model('TestrunDB')->resultset('ScenarioElement')->search({
73 scenario_id => $i_scenario_id
74 })->get_column('testrun_id')->all;
75 0 say "scenario $i_scenario_id consists of testruns ", join ', ', @a_testrun_ids;
76 0 ▶ say Tapper::Config->subconfig->{base_url} // 'http://localhost/tapper', "/testruns/idlist/", join( q#,#, @a_testrun_ids );
Condition0%0/2
"Tapper::Config"->subconfig->{"base_url"} // "http://localhost/tapper"
l!l
00
MC/DC0%0/1
"Tapper::Config"->subconfig->{"base_url"} // "http://localhost/tapper"
"Tapper::Config"->subconfig->{"base_url"}
Truth table0%0/2
A
A= "Tapper::Config"->subconfig->{"base_url"}
Aresult
11
00
77 }
78  
79 }
80 else {
81 2 say join ",", @scenario_ids;
82 }
83  
84 2 return;
85  
86 }
87  
88  
89 71 ▶sub setup {
Subroutine setup: called CC=2 SCAR=7.4
Pod documented
90  
91 71 my ( $or_apprad ) = @_;
92  
93 71 $or_apprad->register( 'scenario-new', \&b_create_scenario, 'Create a scenraio', );
94  
95 71 ▶ if ( $or_apprad->can('group_commands') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_apprad->can("group_commands")) 0 71 71
96 0 $or_apprad->group_commands(
97 'Testrun commands',
98 'scenario-new',
99 );
100 }
101  
102 71 return;
103  
104 }
105  
106 72 1; # End of Tapper::CLI
107  
108 __END__
« blib/lib/Tapper/CLI/Schema.pm ↑ Summary blib/lib/Tapper/CLI/DbDeploy/Command/makeschemadiffs.pm »