| 1 | package Test::PLP; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | ▶ | use PLP::Functions qw( DecodeURI ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | require PLP::Backend::CGI; | |||||||||||||||||||
| 8 | 2 | require PerlIO::scalar; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | our $VERSION = '1.00'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | ▶ | use Test::Builder::Module; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 2 | ▶ | use base 'Test::Builder::Module'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 2 | our @EXPORT = qw( plp_is plp_ok ); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 2 | ▶ | $PLP::use_cache = 0 if $PLP::use_cache; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | #TODO: caching on (change file names) | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 2 | open ORGOUT, '>&', *STDOUT; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | sub is_string ($$;$) { | ||||||||||||||||||||
| 22 | my $tb = __PACKAGE__->builder; | ||||||||||||||||||||
| 23 | $tb->is_eq(@_); | ||||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | ▶ | eval { | ||||||||||||||||||
|
Condition50%1/2
eval {
do {
require Test::LongString;
'Test::LongString'->import('max', 128);
BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"}
my $formatter = *Test::LongString::_display;
my $parent = \&{$formatter;};
*{$formatter;} = sub {
my $s = &{$parent;};
$s =~ s/\\x\{0a\}/\n /g;
return $s;
}
}
} || 1
MC/DC0%0/1
eval {
do {
require Test::LongString;
'Test::LongString'->import('max', 128);
BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"}
my $formatter = *Test::LongString::_display;
my $parent = \&{$formatter;};
*{$formatter;} = sub {
my $s = &{$parent;};
$s =~ s/\\x\{0a\}/\n /g;
return $s;
}
}
} || 1
eval {
do {
require Test::LongString;
'Test::LongString'->import('max', 128);
BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"}
my $formatter = *Test::LongString::_display;
my $parent = \&{$formatter;};
*{$formatter;} = sub {
my $s = &{$parent;};
$s =~ s/\\x\{0a\}/\n /g;
return $s;
}
}
}
Truth table50%1/2
A
A= eval {
do {
require Test::LongString;
'Test::LongString'->import('max', 128);
BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"}
my $formatter = *Test::LongString::_display;
my $parent = \&{$formatter;};
*{$formatter;} = sub {
my $s = &{$parent;};
$s =~ s/\\x\{0a\}/\n /g;
return $s;
}
}
}
| |||||||||||||||||||||
| 27 | # optionally replace unformatted is_string by LongString prettification | ||||||||||||||||||||
| 28 | 2 | require Test::LongString; | |||||||||||||||||||
| 29 | 2 | Test::LongString->import(max => 128); | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | # override output method to not escape newlines | ||||||||||||||||||||
| 32 | 2 | ▶ | no warnings 'redefine'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | 2 | my $formatter = *Test::LongString::_display; | |||||||||||||||||||
| 34 | 2 | my $parent = \&{$formatter}; | |||||||||||||||||||
| 35 | 2 | ▶ | *{$formatter} = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 2 | my $s = &{$parent}; | |||||||||||||||||||
| 37 | 2 | $s =~ s/\Q\x{0a}/\n /g; | |||||||||||||||||||
| 38 | # align lines to: "____expected: " | ||||||||||||||||||||
| 39 | 2 | return $s; | |||||||||||||||||||
| 40 | 2 | }; | |||||||||||||||||||
| 41 | } or 1; | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 25 | ▶ | sub _plp_run { | ||||||||||||||||||
|
Subroutine
_plp_run: called CC=6 SCAR=18.1
| |||||||||||||||||||||
| 44 | 25 | my ($src, $env, $input) = @_; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | %ENV = ( | ||||||||||||||||||||
| 47 | REQUEST_METHOD => 'GET', | ||||||||||||||||||||
| 48 | REQUEST_URI => "/$src/test/123", | ||||||||||||||||||||
| 49 | QUERY_STRING => 'test=1&test=2', | ||||||||||||||||||||
| 50 | GATEWAY_INTERFACE => 'CGI/1.1', | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | SCRIPT_NAME => '/plp.cgi', | ||||||||||||||||||||
| 53 | SCRIPT_FILENAME => "./plp.cgi", | ||||||||||||||||||||
| 54 | PATH_INFO => "/$src/test/123", | ||||||||||||||||||||
| 55 | PATH_TRANSLATED => "./$src/test/123", | ||||||||||||||||||||
| 56 | DOCUMENT_ROOT => ".", | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 25 | ▶ | $env ? %{$env} : (), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | ); # Apache/2.2.4 CGI environment | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 25 | ▶ | if (defined $input) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 2 | ▶ | $ENV{CONTENT_LENGTH} //= length $input; | ||||||||||||||||||
|
Condition33%1/3
$ENV{"CONTENT_LENGTH"} //= length $input
MC/DC0%0/2
$ENV{"CONTENT_LENGTH"} //= length $input
$ENV{"CONTENT_LENGTH"}
length $input
Truth table33%1/3
A //= B
A= $ENV{"CONTENT_LENGTH"}B= length $input
| |||||||||||||||||||||
| 63 | 2 | ▶ | $ENV{CONTENT_TYPE} //= 'application/x-www-form-urlencoded'; | ||||||||||||||||||
|
Condition100%2/2
$ENV{"CONTENT_TYPE"} //= "application/x-www-form-urlencoded"
MC/DC100%1/1
$ENV{"CONTENT_TYPE"} //= "application/x-www-form-urlencoded"
$ENV{"CONTENT_TYPE"}
Truth table100%2/2
A
A= $ENV{"CONTENT_TYPE"}
| |||||||||||||||||||||
| 64 | 2 | close STDIN; | |||||||||||||||||||
| 65 | 2 | open STDIN, '<', $input; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 25 | close STDOUT; | |||||||||||||||||||
| 69 | 25 | open STDOUT, '>', \my $output; # STDOUT buffered to scalar | |||||||||||||||||||
| 70 | 25 | select STDOUT; # output before start() (which selects PLPOUT) | |||||||||||||||||||
| 71 | 25 | eval { | |||||||||||||||||||
| 72 | 4 | ▶ | local $SIG{__WARN__} = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||
| 73 | # include warnings in stdout (but modified to distinguish) | ||||||||||||||||||||
| 74 | 4 | my $msg = shift; | |||||||||||||||||||
| 75 | 4 | ▶ | my $eol = $msg =~ s/(\s*\z)// && $1; | ||||||||||||||||||
|
Condition33%1/3
$msg =~ s/(\s*\z)// && $1
MC/DC0%0/2
$msg =~ s/(\s*\z)// && $1
$msg =~ s/(\s*\z)//
$1
Truth table33%1/3
A && B
A= $msg =~ s/(\s*\z)//B= $1
| |||||||||||||||||||||
| 76 | 4 | print "<warning>$msg</warning>$eol" | |||||||||||||||||||
| 77 | 25 | }; | |||||||||||||||||||
| 78 | 25 | PLP::everything(); | |||||||||||||||||||
| 79 | }; | ||||||||||||||||||||
| 80 | 25 | my $failure = $@; | |||||||||||||||||||
| 81 | 25 | select ORGOUT; # return to original STDOUT | |||||||||||||||||||
| 82 | 25 | ▶ | die $failure if $failure; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 25 | return $output; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 25 | ▶ | sub plp_is { | ||||||||||||||||||
|
Subroutine
plp_is: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||
| 88 | 25 | my ($src, $env, $input, $expect, $name) = @_; | |||||||||||||||||||
| 89 | 25 | my $tb = __PACKAGE__->builder; | |||||||||||||||||||
| 90 | 25 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 25 | my $output = eval { _plp_run($src, $env, $input) }; | |||||||||||||||||||
| 93 | 25 | ▶ | if (my $failure = $@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | $tb->ok(0, $name); | |||||||||||||||||||
| 95 | 0 | $tb->diag(" Error: $failure"); | |||||||||||||||||||
| 96 | 0 | return; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 25 | ▶ | if (defined $expect) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 24 | $output =~ s{((?:.+\n)*)}{ join "", sort split /(?<=\n)/, $1 }e; # order headers | |||||||||||||||||||
| 101 | 24 | return is_string($output, $expect, $name); | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 1 | $tb->ok(defined $output, $name); | |||||||||||||||||||
| 105 | 1 | return $output; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 2 | ▶ | sub _getwarning { | ||||||||||||||||||
|
Subroutine
_getwarning: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 109 | # captures the first warning produced by the given code string | ||||||||||||||||||||
| 110 | 2 | my ($code, $line, $file) = @_; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 2 | ▶ | local $SIG{__WARN__} = sub { die @_ }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 113 | # warnings module runs at BEGIN, so we need to use icky expression evals | ||||||||||||||||||||
| 114 | 2 | eval qq(# line $line "$file"\n$code; return); | |||||||||||||||||||
| 115 | 2 | my $res = $@; | |||||||||||||||||||
| 116 | 2 | chomp $res; | |||||||||||||||||||
| 117 | 2 | return $res; | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 24 | ▶ | sub _getplp { | ||||||||||||||||||
|
Subroutine
_getplp: called CC=11 SCAR=25.3
| |||||||||||||||||||||
| 121 | 24 | my ($file, %replace) = @_; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 24 | (my $name = $file) =~ s/[.][^.]+$//; | |||||||||||||||||||
| 124 | 24 | $file = "$name.html"; | |||||||||||||||||||
| 125 | 24 | ▶ | my $src = delete $replace{-input} // "$name.plp"; | ||||||||||||||||||
|
Condition50%1/2
delete $replace{"-input"} // "$name.plp"
MC/DC0%0/1
delete $replace{"-input"} // "$name.plp"
delete $replace{"-input"}
Truth table50%1/2
A
A= delete $replace{"-input"}
| |||||||||||||||||||||
| 126 | 24 | ▶ | my $input = -e "$name.txt" && "$name.txt"; | ||||||||||||||||||
|
Condition100%2/2
-e "$name.txt" && "$name.txt"
MC/DC100%1/1
-e "$name.txt" && "$name.txt"
-e "$name.txt"
Truth table100%2/2
A
A= -e "$name.txt"
| |||||||||||||||||||||
| 127 | 24 | ▶ | $name =~ s/^(\d*)-// and $name .= " ($1)"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 128 | 24 | DecodeURI($name); | |||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 24 | my $env = delete $replace{-env}; | |||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 24 | my $output; | |||||||||||||||||||
| 133 | 24 | ▶ | if (open my $fh, '<', $file) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 134 | 24 | local $/ = undef; # slurp | |||||||||||||||||||
| 135 | 24 | $output = readline $fh; | |||||||||||||||||||
| 136 | 24 | close $fh; | |||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 24 | ▶ | if ($output) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 140 | 24 | ▶ | $replace{HEAD} //= "Content-Type: text/html\nX-PLP-Version: $PLP::VERSION\n"; | ||||||||||||||||||
|
Condition50%1/2
$replace{"HEAD"} //= "Content-Type: text/html\nX-PLP-Version: $PLP::VERSION\n"
MC/DC0%0/1
$replace{"HEAD"} //= "Content-Type: text/html\nX-PLP-Version: $PLP::VERSION\n"
$replace{"HEAD"}
Truth table50%1/2
A
A= $replace{"HEAD"}
| |||||||||||||||||||||
| 141 | 24 | ▶ | $replace{VERSION } //= $PLP::VERSION; | ||||||||||||||||||
|
Condition33%1/3
$replace{"VERSION"} //= $PLP::VERSION
MC/DC0%0/2
$replace{"VERSION"} //= $PLP::VERSION
$replace{"VERSION"}
$PLP::VERSION
Truth table33%1/3
A //= B
A= $replace{"VERSION"}B= $PLP::VERSION
| |||||||||||||||||||||
| 142 | 24 | ▶ | $replace{SCRIPT_NAME } //= $src; | ||||||||||||||||||
|
Condition33%1/3
$replace{"SCRIPT_NAME"} //= $src
MC/DC0%0/2
$replace{"SCRIPT_NAME"} //= $src
$replace{"SCRIPT_NAME"}
$src
Truth table33%1/3
A //= B
A= $replace{"SCRIPT_NAME"}B= $src
| |||||||||||||||||||||
| 143 | 24 | ▶ | $replace{SCRIPT_FILENAME} //= "./$src"; | ||||||||||||||||||
|
Condition50%1/2
$replace{"SCRIPT_FILENAME"} //= "./$src"
MC/DC0%0/1
$replace{"SCRIPT_FILENAME"} //= "./$src"
$replace{"SCRIPT_FILENAME"}
Truth table50%1/2
A
A= $replace{"SCRIPT_FILENAME"}
| |||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 24 | chomp $output; | |||||||||||||||||||
| 146 | 24 | $output =~ s/\$$_/$replace{$_}/g for keys %replace; | |||||||||||||||||||
| 147 | 24 | $output =~ s{ | |||||||||||||||||||
| 148 | <eval \s+ line="([^"]*)"> (.*?) </eval> | ||||||||||||||||||||
| 149 | 2 | }{ _getwarning($2, $1, $src) }msxge; | |||||||||||||||||||
| 150 | } | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | 24 | return ($src, $env, $input, $output, $name); | |||||||||||||||||||
| 153 | } | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 24 | ▶ | sub plp_ok { | ||||||||||||||||||
|
Subroutine
plp_ok: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 156 | 24 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||
| 157 | 24 | plp_is(_getplp(@_)); | |||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | |||||||||||||||||||||