Skip to content

Commit

Permalink
resolve #3 - increase test coverage
Browse files Browse the repository at this point in the history
basic subroutine test coverage for several methods that currently
have zero test coverage
  • Loading branch information
leejo committed Apr 17, 2015
1 parent 08678ef commit 43d401c
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 94 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
- All *documentation* for HTML functionality in CGI has been moved into
its own namespace: CGI::HTML::Functions - although the functionality
continues to exist within CGI.pm so there are no code changes required
(GH #142)

[ TESTING ]
- Increase test coverage (GH #3)

[ INTERNALS ]
- Cwd made a TEST_REQUIRES rather than a BUILD_REQUIRES in Makefile.PL
Expand Down
1 change: 0 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ t/delete.t
t/end_form.t
t/form.t
t/function.t
t/gen-tests/gen-start-end-tags.pl
t/gh-155.t
t/headers.t
t/headers/attachment.t
Expand Down
2 changes: 0 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use ExtUtils::MakeMaker;
my $mm = $ExtUtils::MakeMaker::VERSION;

system( "perl", "t/gen-tests/gen-start-end-tags.pl" );

# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
Expand Down
2 changes: 1 addition & 1 deletion lib/CGI/Carp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ sub carpout {

open(SAVEERR, ">&STDERR");
open(STDERR, ">&$no") or
( print SAVEERR "Unable to redirect STDERR: $!\n" and exit(1) );
( print SAVEERR "Unable to redirect >&$no: $!\n" and exit(1) );
}

sub warningsToBrowser {
Expand Down
1 change: 1 addition & 0 deletions lib/CGI/Push.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ sub do_sleep {
sleep($delay);
} else {
select(undef,undef,undef,$delay);
return $delay;
}
}

Expand Down
15 changes: 14 additions & 1 deletion t/carp.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use strict;

use Test::More tests => 64;
use Test::More tests => 71;
use IO::Handle;

use CGI::Carp;
Expand Down Expand Up @@ -425,3 +425,16 @@ untie *STDOUT;
like $result[0] => qr/Message ToBrowser/, 'die message for ToBrowser = 0 is OK';
ok !$result[1], 'No output for ToBrowser = 0';

*CGI::Carp::die = sub { &$CGI::Carp::DIE_HANDLER; return 1 };
*CGI::Carp::warn = sub { return 1 };

CGI::Carp::set_die_handler( sub { pass( "die handler" ); return 1 } );
ok( CGI::Carp::confess(),'confess' );
ok( CGI::Carp::croak(),'croak' );
ok( CGI::Carp::carp(),'carp' );
ok( CGI::Carp::cluck(),'cluck' );

use File::Temp;
my $fh = File::Temp->new;

ok( CGI::Carp::carpout( $fh ),'carpout' );
73 changes: 73 additions & 0 deletions t/cgi.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/local/bin/perl

# coverage for testing that doesn't sit elsewhere

use strict;
use warnings;

use Test::More tests => 25;
use Test::Deep;
use Test::Warn;

use CGI ();

# Set up a CGI environment
$ENV{REQUEST_METHOD} = 'GET';
$ENV{QUERY_STRING} = 'game=chess&game=checkers&weather=dull';

isa_ok( my $q = CGI->new,'CGI' );

# undocumented ->r method, seems to be a temp store?
$q->r( 'foo' );
is( $q->r,'foo','r' );

diag( "cgi-lib.pl routines" );

ok( $q->ReadParse,'ReadParse' );
is( $q->PrintHeader,$q->header,'PrintHeader' );
is( $q->HtmlTop,$q->start_html,'HtmlTop' );
is( $q->HtmlBot,$q->end_html,'HtmlBot' );

cmp_deeply(
[ my @params = CGI::SplitParam( "foo\0bar" ) ],
[ qw/ foo bar /],
'SplitParam'
);

ok( $q->MethGet,'MethGet' );
ok( ! $q->MethPost,'MethPost' );
ok( ! $q->MethPut,'MethPut' );

note( "TIE methods" );
ok( ! $q->FIRSTKEY,'FIRSTKEY' );
ok( ! $q->NEXTKEY,'NEXTKEY' );
ok( ! $q->CLEAR,'CLEAR' );

is( $q->version,$CGI::VERSION,'version' );
is( $q->as_string,'<ul></ul>','as_string' );

is( ( $q->_style )[0],'<link rel="stylesheet" type="text/css" href="" />','_style' );
is( $q->state,'http://localhost','state' );

$CGI::NOSTICKY = 0;
ok( $q->nosticky( 1 ),'nosticky' );
is( $CGI::NOSTICKY,1,' ... sets $CGI::NOSTICKY' );

$CGI::NPH = 0;
ok( $q->nph( 1 ),'nph' );
is( $CGI::NPH,1,' ... sets $CGI::NPH' );

$CGI::CLOSE_UPLOAD_FILES = 0;
ok( $q->close_upload_files( 1 ),'close_upload_files' );
is( $CGI::CLOSE_UPLOAD_FILES,1,' ... sets $CGI::CLOSE_UPLOAD_FILES' );

cmp_deeply(
$q->default_dtd,
[
'-//W3C//DTD HTML 4.01 Transitional//EN',
'http://www.w3.org/TR/html4/loose.dtd'
],
'default_dtd'
);

ok( ! $q->private_tempfiles,'private_tempfiles' );
75 changes: 0 additions & 75 deletions t/gen-tests/gen-start-end-tags.pl

This file was deleted.

13 changes: 1 addition & 12 deletions t/push.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@ ok( my $q = CGI::Push->new(), 'create a new CGI::Push object' );
# test the simple_counter() method
like( join('', $q->simple_counter(10)) , '/updated.+?10.+?times./', 'counter' );

# test do_sleep, except we don't want to bog down the tests
# there's also a potential timing-related failure lurking here
# change this variable at your own risk
my $sleep_in_tests = 0;

SKIP: {
skip( 'do_sleep() test may take a while', 1 ) unless $sleep_in_tests;

my $time = time;
CGI::Push::do_sleep(2);
is(time - $time, 2, 'slept for a while' );
}
ok( CGI::Push::do_sleep(0.01),'do_sleep' );

# test push_delay()
ok( ! defined $q->push_delay(), 'no initial delay' );
Expand Down
13 changes: 11 additions & 2 deletions t/util.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@

$| = 1;

use Test::More tests => 77;
use Test::More tests => 80;
use Test::Deep;
use Config;
use_ok ( 'CGI::Util', qw(escape unescape rearrange) );
use_ok ( 'CGI::Util', qw(
escape
unescape
rearrange
ebcdic2ascii
ascii2ebcdic
) );

# ASCII order, ASCII codepoints, ASCII repertoire

Expand Down Expand Up @@ -79,3 +85,6 @@ for ( 1 .. 20 ) {
);
}

ok( CGI::Util::utf8_chr( "1",1 ),'utf8_chr' );
ok( my $ebcdic = ascii2ebcdic( "A" ),'ascii2ebcdic' );
is( ebcdic2ascii( $ebcdic ),'A','ebcdic2ascii' );

0 comments on commit 43d401c

Please sign in to comment.