blib/lib/App/test/travis.pm

filter: Statementstmt 89.6% 95 / 106 Branchbran 55.0% 11 / 20 Conditioncond 46.6% 7 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 90.4% 19 / 21 Podpod 0.0% 0 / 4 totaltotal 75.4% 132 / 175 CC 19 SCAR 17.3
CC
19
Cov
80%
run
14.1
__ANON__
4.2
xsystem
4.1
CRAP 5.6
↑ Summary
1 package App::test::travis;
2 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use version; our $VERSION = version->declare("v0.9.7");
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use encoding::warnings 'FATAL';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Fatal qw(open close);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Config qw(%Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Getopt::Long qw(GetOptionsFromArray :config posix_default no_ignore_case bundling auto_version);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use autouse 'Pod::Usage' => qw(pod2usage);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use autouse 'Pod::Find' => qw(pod_where);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use YAML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 my $path_sep = $Config{path_sep};
20  
21 my %tab = (
22 c => {
23 script => './configure && make && make test',
24 },
25 cpp => {
26 script => './configure && make && make test',
27 },
28 clojure => {
29 script => 'lein test',
30 },
31 erlang => {
32 install => 'rebar get-deps',
33 script => 'rebar compile && rebar skip_deps=true eunit',
34 },
35 go => {
36 install => 'go get -d -v ./... && go build -v ./...',
37 script => 'make',
38 },
39 groovy => {
40 install => 'gradle assemble',
41 script => 'gradle check',
42 },
43 haskell => {
44 install => 'cabal install --only-dependencies --enable-tests',
45 script => 'cabal configure --enable-tests && cabal build && cabal test',
46 },
47 java => {
48 install => 'mvn install -DskipTests=true',
49 script => 'mvn test',
50 },
51  
52 node_js => {
53 1 ▶ setup => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
54 1 my($config, $tempdir, $cb) = @_;
55 1 local $ENV{PATH} = join $path_sep, "node_modules/.bin", $ENV{PATH};
56 1 $cb->();
57 },
58 install => 'npm install',
59 script => 'npm test',
60 },
61  
62 perl => {
63 1 ▶ setup => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
64 1 my($config, $tempdir, $cb) = @_;
65 1 local $ENV{PERL_CPANM_OPT} = "-l$tempdir --verbose";
66 1 local $ENV{PERL5OPT} = "-Mlib=$tempdir/lib/perl5";
67 1 local $ENV{PATH} = join $path_sep, "$tempdir/bin", $ENV{PATH};
68  
69 1 $cb->();
70 },
71 1 install => 'cpanm --installdeps --notest .',
72 script => 'cpanm --test-only .',
73 },
74  
75 php => {
76 script => 'phpunit',
77 },
78  
79 python => {
80 install => 'pip install -r requirements.txt --use-mirrors',
81 },
82  
83 ruby => {
84 install => 'bundle install',
85 script => 'bundle exec rake',
86 },
87  
88 scala => {
89 script => 'sbt test',
90 },
91 );
92  
93 2 ▶sub run {
Subroutine run: called CC=11 SCAR=26.4
Pod undocumented
94 2 my($class, @args) = @_;
95  
96 2 my $start = time();
97  
98 2 my $DRY_RUN;
99 my $HELP;
100  
101 2 ▶ GetOptionsFromArray(\@args,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray(\@args, "--dry-run", \$DRY_RUN, "--help", \$HELP) or return help(1) 2 0 2
102 '--dry-run' => \$DRY_RUN,
103 '--help' => \$HELP,
104 ) or return help(1);
105 2 ▶ return help(0) if $HELP;
Branch: 1 branch
BranchTrueFalseTotal
if $HELP 0 2 2
106  
107 2 my($travis_yml) = @args;
108 2 ▶ $travis_yml //= '.travis.yml';
Condition50%1/2
$travis_yml //= ".travis.yml"
l!l
20
MC/DC0%0/1
$travis_yml //= ".travis.yml"
$travis_yml
Truth table50%1/2
A
A= $travis_yml
Aresult
11
00
109  
110 2 my $config = YAML::LoadFile($travis_yml);
111  
112 2 ▶ my $language = lc($config->{language} // 'ruby');
Condition50%1/2
$config->{"language"} // "ruby"
l!l
20
MC/DC0%0/1
$config->{"language"} // "ruby"
$config->{"language"}
Truth table50%1/2
A
A= $config->{"language"}
Aresult
11
00
113  
114 2 ▶ my $behavior = $tab{$language} or die "no behavior defined for $language\n";
Branch: 1 branch
BranchTrueFalseTotal
my $behavior = $tab{$language} or die "no behavior defined for $language\n" 2 0 2
115  
116 2 close STDIN;
117 2 open STDIN, '<', File::Spec->devnull;
118  
119 2 ▶ if ($ENV{TRAVIS} && $ENV{CI}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"TRAVIS"} and $ENV{"CI"}) 0 2 2
Condition33%1/3
$ENV{"TRAVIS"} and $ENV{"CI"}
!ll&&!rl&&r
200
MC/DC0%0/2
$ENV{"TRAVIS"} and $ENV{"CI"}
$ENV{"TRAVIS"} $ENV{"CI"}
Truth table33%1/3
A and B
A= $ENV{"TRAVIS"}B= $ENV{"CI"}
ABresult
0X0
100
111
120 0 say '# skip because TRAVIS and CI are already set';
121 0 return;
122 }
123 2 say "# running $travis_yml";
124  
125 # Travis CI Environment Variables
126 # http://about.travis-ci.org/docs/user/osx-ci-environment/
127 2 local $ENV{CI} = 'true';
128 2 local $ENV{TRAVIS} = 'true';
129  
130 2 my $tempdir = tempdir('.travis-run-XXXXXXX', CLEANUP => 1);
131 0 ▶ my $setup = $behavior->{setup} // sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
132 0 my($config, $tempdir, $cb) = @_;
133 0 $cb->();
134 2 ▶ };
Condition33%1/3
$behavior->{"setup"} // sub { my($config, $tempdir, $cb) = @_; &$cb(); }
l!l&&r!l&&!r
200
MC/DC0%0/2
$behavior->{"setup"} // sub { my($config, $tempdir, $cb) = @_; &$cb(); }
$behavior->{"setup"} sub { my($config, $tempdir, $cb) = @_; &$cb(); }
Truth table33%1/3
A // B
A= $behavior->{"setup"}B= sub { my($config, $tempdir, $cb) = @_; &$cb(); }
ABresult
1X1
011
000
135  
136 2 for my $mode(qw(before_install install script)) {
137 6 ▶ $config->{$mode} //= $behavior->{$mode};
Condition66%2/3
$config->{$mode} //= $behavior->{$mode}
l!l&&r!l&&!r
420
MC/DC0%0/2
$config->{$mode} //= $behavior->{$mode}
$config->{$mode} $behavior->{$mode}
Truth table66%2/3
A //= B
A= $config->{$mode}B= $behavior->{$mode}
ABresult
1X1
011
000
138 }
139  
140 2 ▶ $setup->($config, $tempdir, sub {
Subroutine __ANON__: called CC=4 SCAR=14.4
141 2 ▶ my $versions = $config->{$language} // []; # TODO
Condition50%1/2
$config->{$language} // []
l!l
20
MC/DC0%0/1
$config->{$language} // []
$config->{$language}
Truth table50%1/2
A
A= $config->{$language}
Aresult
11
00
142  
143 # http://about.travis-ci.org/docs/user/build-configuration/#Build-Lifecycle
144 2 run_commands($config, $DRY_RUN, 'before_install');
145 2 run_commands($config, $DRY_RUN, 'install');
146 2 run_commands($config, $DRY_RUN, 'before_script');
147 2 eval {
148 2 run_commands($config, $DRY_RUN, 'script');
149 };
150 2 ▶ if (! $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $@) { } 2 0 2
151 2 run_commands($config, $DRY_RUN, 'after_success');
152 }
153 else {
154 0 run_commands($config, $DRY_RUN, 'after_failure');
155 }
156 2 run_commands($config, $DRY_RUN, 'after_script');
157  
158 2 say '# finished: ', scalar localtime;
159  
160 2 my $duration = (time() - $start);
161 2 ▶ if ($duration > 60) {
Branch: 1 branch
BranchTrueFalseTotal
if ($duration > 60) { } 0 2 2
162 0 say sprintf '# duration: %d min %d sec', int($duration / 60), $duration % 60;
163 }
164 else {
165 2 say sprintf '# duration: %d sec', $duration;
166 }
167 2 });
168 2 return 0;
169 }
170  
171 12 ▶sub run_commands {
Subroutine run_commands: called CC=4 SCAR=13.9
Pod undocumented
172 12 my($config, $dry_run, $mode) = @_;
173 12 ▶ return unless defined $config->{$mode};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{$mode} 6 6 12
174 6 say "# $mode";
175 my @cmds = ref($config->{$mode}) eq 'ARRAY'
176 3 ? @{$config->{$mode}}
177 6 ▶ : ($config->{$mode});
Branch: 1 branch
BranchTrueFalseTotal
ref $config->{$mode} eq 'ARRAY' ? : 3 3 6
178 6 for my $cmd(@cmds) {
179 7 xsystem($dry_run, $cmd);
180 }
181 }
182  
183 7 ▶sub xsystem {
Subroutine xsystem: called CC=3 SCAR=14.2
Pod undocumented
184 7 my($dry_run, @command) = @_;
185  
186 7 say "\$ @command";
187 7 ▶ unless($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dry_run) 0 7 7
188 0 ▶ system(@command) == 0 or die "failed to call `@command`";
Branch: 1 branch
BranchTrueFalseTotal
system(@command) == 0 or die "failed to call `@command`" 0 0 0
189 }
190 }
191  
192 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod undocumented
193 0 my($exit_status) = @_;
194 0 my $pod_file = pod_where({ -inc => 1 }, __PACKAGE__);
195 0 pod2usage(
196 -exitval => 'noexit',
197 -input => $pod_file,
198 );
199 0 return $exit_status;
200 }
201 1 1;
202 __END__
↑ Summary