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