Kit/Test/Screen.pm

filter: Statementstmt 100% 58 / 58 Branchbran 87.5% 14 / 16 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 13 / 13 Podpod 100% 5 / 5 totaltotal 97.8% 93 / 95 CC 10 SCAR 8.2
CC
10
Cov
97%
within
4.0
typed
3.0
kit
3.0
CRAP 2.3
« Kit/Log.pm ↑ Summary Kit/Ticker.pm »
1 package Game::Terminal::Kit::Test::Screen;
2  
3 9 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Game::Terminal::Kit::Keys;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Game::Terminal::Kit::Screen;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 our $VERSION = '0.06';
12  
13 9 our @EXPORT_OK = qw/keysource capture typed kit within/;
14  
15 36 ▶sub keysource {
Subroutine keysource: called CC=2 SCAR=6.9
Pod documented
16 36 my ($bytes) = @_;
17 36 ▶ my @chars = split //, defined $bytes ? $bytes : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $bytes ? : 35 1 36
18 36 ▶ return sub { return shift @chars };
Subroutine __ANON__: called CC=1 SCAR=0.0
19 }
20  
21 40 ▶sub capture {
Subroutine capture: called CC=2 SCAR=7.1
Pod documented
22 40 my $text = '';
23 40 ▶ open my $out, '>', \$text or die "cannot open the screen: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", \$text or die "cannot open the screen: $!" 40 0 40
24 40 return ($out, \$text);
25 }
26  
27 40 ▶sub typed {
Subroutine typed: called CC=3 SCAR=11.0
Pod documented
28 40 my (@lines) = @_;
29 40 ▶ my $script = join '', map { m/\n\z/ ? $_ : "$_\n" } @lines;
Branch: 1 branch
BranchTrueFalseTotal
/\n\z/u ? : 1 5 6
30 40 ▶ open my $in, '<', \$script or die "cannot read the script: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", \$script or die "cannot read the script: $!" 40 0 40
31 40 return $in;
32 }
33  
34 39 ▶sub kit {
Subroutine kit: called CC=3 SCAR=11.0
Pod documented
35 39 my (%option) = @_;
36 39 my $bytes = delete $option{keys};
37 39 my $lines = delete $option{typed};
38 39 my ($out, $text) = capture();
39 my $keys = Game::Terminal::Kit::Keys->new(
40 39 ▶ in => typed(@{ $lines || [] }),
Branch: 1 branch
BranchTrueFalseTotal
defined $bytes ? : 34 5 39
Condition100%2/2
$lines || []
l!l
435
MC/DC100%1/1
$lines || []
$lines
Truth table100%2/2
A
A= $lines
Aresult
11
00
41 (defined $bytes ? (keysource => keysource($bytes)) : ()),
42 );
43 39 my $screen = Game::Terminal::Kit::Screen->new(
44 out => $out,
45 interactive => 0,
46 colour => 0,
47 ascii => 1,
48 %option,
49 );
50 39 return ($keys, $screen, $text);
51 }
52  
53 16 ▶sub within {
Subroutine within: called CC=4 SCAR=13.9
Pod documented
54 16 my ($seconds, $body) = @_;
55 16 my $late = "it did not end in $seconds seconds\n";
56 16 my @result;
57 16 my $lived = eval {
58 16 ▶ local $SIG{ALRM} = sub { die $late };
Subroutine __ANON__: called CC=1 SCAR=0.0
59 16 alarm $seconds;
60 16 @result = $body->();
61 14 alarm 0;
62 14 1;
63 };
64 16 my $died = $@;
65 16 eval { alarm 0 };
66 16 ▶ return wantarray ? @result : $result[0] if $lived;
Branch: 2 branches
BranchTrueFalseTotal
if $lived 14 2 16
wantarray ? : 5 9 14
67 2 ▶ die $died unless $died eq $late;
Branch: 1 branch
BranchTrueFalseTotal
unless $died eq $late 1 1 2
68 1 require Test::Builder;
69 1 Test::Builder->new->ok(0, "ended within $seconds seconds");
70 1 return;
71 }
72  
73 9 1;
74  
75 __END__
« Kit/Log.pm ↑ Summary Kit/Ticker.pm »