lib/DR/Tnt/Test.pm

filter: Statementstmt 75.0% 45 / 60 Branchbran 29.1% 7 / 24 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 4 totaltotal 61.5% 64 / 104 SCAR 32.2
CC
14
Cov
62%
tarantool_version_check
26.5
tarantool_version
4.9
free_port
4.2
CRAP 25.1
« blib/lib/DR/Tnt/Msgpack/Types/Blob.pm ↑ Summary lib/DR/Tnt/Msgpack/Types/Int.pm »
1 31 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 31 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 package DR::Tnt::Test;
7 31 ▶use DR::Tnt::Test::TntInstance;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 31 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 31 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 31 our @EXPORT = qw(
12 free_port
13 tarantool_version
14 tarantool_version_check
15 start_tarantool
16 );
17  
18  
19 sub tarantool_version() {
20  
21 30 ▶ local $SIG{__WARN__} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=0.0
Subroutine tarantool_version: called CC=3 SCAR=16.0
Pod undocumented
22 30 ▶ if (open my $fh, '-|', 'tarantool', '-V') {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "-|", "tarantool", "-V") 0 30 30
23 0 my $v = <$fh>;
24 0 ▶ return undef unless $v =~ /^Tarantool\s+(\S+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /^Tarantool\s+(\S+)/ 0 0 0
25 0 return $1;
26 }
27 30 return undef;
28 }
29  
30  
31 sub tarantool_version_check($) {
32 29 ▶ my ($version) = @_;
Subroutine tarantool_version_check: called CC=9 SCAR=32.8
Pod undocumented
33 29 ▶ $version ||= '1.6';
Condition50%1/2
$version ||= "1.6"
l!l
290
MC/DC0%0/1
$version ||= "1.6"
$version
Truth table50%1/2
A
A= $version
Aresult
11
00
34  
35 29 my $v = tarantool_version;
36  
37 29 ▶ goto FAIL unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 29 0 29
38 0 my @p = split /\./, $version;
39 0 $v =~ s/-.*//;
40 0 my @v = split /\./, $v;
41  
42 0 ▶ for (my $i = 0; $i < @p; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @p) 0 0 0
43 0 ▶ last unless $i < @v;
Branch: 1 branch
BranchTrueFalseTotal
unless $i < @v 0 0 0
44 0 ▶ goto OK if $v[$i] > $p[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $v[$i] > $p[$i] 0 0 0
45 0 ▶ goto FAIL unless $v[$i] >= $p[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $v[$i] >= $p[$i] 0 0 0
46 }
47  
48 0 ▶ goto FAIL unless @v >= @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @v >= @p 0 0 0
49  
50 0 OK:
51 return;
52  
53 FAIL: {
54 29 my $tb = Test::More->builder;
55 29 my @passed = $tb->details;
56 29 ▶ for (my $i = @passed; $i < $tb->expected_tests; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $tb->expected_tests) 1243 29 1272
57 1243 $tb->skip("tarantool $version is not found");
58 }
59 29 exit;
60 }
61  
62 }
63  
64  
65  
66 sub free_port() {
67 2 ▶ state $busy_ports = {};
Subroutine free_port: called CC=4 SCAR=14.5
Pod undocumented
68 2 while( 1 ) {
69 2 my $port = 10000 + int rand 30000;
70 2 ▶ next if exists $busy_ports->{ $port };
Branch: 1 branch
BranchTrueFalseTotal
if exists $busy_ports->{$port} 0 2 2
71 2 ▶ next unless IO::Socket::INET->new(
Branch: 2 branches
BranchTrueFalseTotal
unless "IO::Socket::INET"->new("Listen", 5, "LocalAddr", "127.0.0.1", "LocalPort", $port, "Proto", "tcp", $^O eq "MSWin32" ? () : ("ReuseAddr", 1)) 0 2 2
$^O eq 'MSWin32' ? : 0 2 2
72 Listen => 5,
73 LocalAddr => '127.0.0.1',
74 LocalPort => $port,
75 Proto => 'tcp',
76 (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)),
77 );
78 2 return $busy_ports->{ $port } = $port;
79 }
80 }
81  
82 sub start_tarantool {
83 0 ▶ my %opts = @_;
Subroutine start_tarantool: not called CC=1 SCAR=6.9
Pod undocumented
84 0 $opts{-port} = free_port;
85 0 DR::Tnt::Test::TntInstance->new(%opts);
86 }
87  
88 31 1;
« blib/lib/DR/Tnt/Msgpack/Types/Blob.pm ↑ Summary lib/DR/Tnt/Msgpack/Types/Int.pm »