Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Nov 15, 2024
1 parent 461e50b commit 3ea1cc6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
35 changes: 29 additions & 6 deletions t/carp.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
use strict;
use warnings;

use Carp;
use Test::Carp;
use Test::Most tests => 9;
use Test::Most tests => 15;

BEGIN {
use_ok('CGI::Info');
}

CARP: {
$ENV{'GATEWAY_INTERFACE'} = 'CGI/1.1';
local $ENV{'GATEWAY_INTERFACE'} = 'CGI/1.1';

does_carp_that_matches(
sub {
$ENV{'GATEWAY_INTERFACE'} = 'CGI/1.1';
$ENV{'REQUEST_METHOD'} = 'FOO';
local $ENV{'REQUEST_METHOD'} = 'FOO';
my $i = new_ok('CGI::Info');
$i->params();
ok($i->status() == 501);
Expand All @@ -26,10 +26,10 @@ CARP: {

does_carp_that_matches(
sub {
$ENV{'REQUEST_METHOD'} = 'POST';
local $ENV{'REQUEST_METHOD'} = 'POST';

my $input = 'foo=bar';
$ENV{'CONTENT_LENGTH'} = length($input) + 1; # One more than the length, should error
local $ENV{'CONTENT_LENGTH'} = length($input) + 1; # One more than the length, should error

open (my $fin, '<', \$input);
local *STDIN = $fin;
Expand All @@ -44,4 +44,27 @@ CARP: {
);

does_carp_that_matches(sub { CGI::Info->new({ expect => 'foo' }); }, qr/must be a reference to an array/);

{
local $ENV{'REQUEST_METHOD'} = 'POST';
local $ENV{'CONTENT_TYPE'} = 'Multipart/form-data; boundary=-----xyz';
my $input = <<'EOF';
-------xyz
Content-Disposition: form-data; name="country"
44
-------xyz
Content-Disposition: form-data; name="datafile"; filename="foo.txt"
Content-Type: text/plain
Bar
-------xyz--
EOF
local $ENV{'CONTENT_LENGTH'} = length($input);
does_carp_that_matches(sub { new_ok('CGI::Info')->params(upload_dir => '/') }, qr/ isn't writeable$/);
does_carp_that_matches(sub { new_ok('CGI::Info')->params(upload_dir => 't/carp.t') }, qr/ isn't a full pathname$/);
does_carp_that_matches(sub { new_ok('CGI::Info')->params(upload_dir => '/t/carp.t') }, qr/ isn't a directory$/);
# new_ok('CGI::Info')->params(upload_dir => '/t/carp.t');
}
}
1 change: 1 addition & 0 deletions t/comment-spelling.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ getpairs
INET
NetBSD
NUL
param
paramref
params
realpath
Expand Down
3 changes: 2 additions & 1 deletion t/rootdir.t
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ ROOTDIR: {
ok(-r $dir);
ok(-d $dir);

$ENV{'DOCUMENT_ROOT'} = File::Spec->catdir(File::Spec->tmpdir());
delete $ENV{'DOCUMENT_ROOT'};
$ENV{'C_DOCUMENT_ROOT'} = File::Spec->catdir(File::Spec->tmpdir());
$dir = $i->root_dir();
ok($dir eq File::Spec->catdir(File::Spec->tmpdir()));
ok(-r $dir);
Expand Down

0 comments on commit 3ea1cc6

Please sign in to comment.