cgi-carp.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl -w
use strict;
# Due to a bug in older versions of MakeMaker & Test::Harness, we must
# ensure the blib's are in @INC, else we might use the core CGI.pm
use Test;
BEGIN {
}
END {
}
#-----------------------------------------------------------------------------
# Test id
#-----------------------------------------------------------------------------
# directly invoked
# one level of indirection
# two levels of indirection
#-----------------------------------------------------------------------------
# Test stamp
#-----------------------------------------------------------------------------
"Time in correct format");
#-----------------------------------------------------------------------------
# Test warn and _warn
#-----------------------------------------------------------------------------
# set some variables to control what's going on.
# Test that realwarn is called
{
local $^W = 0;
eval "sub CGI::Carp::realwarn {return 'Called realwarn'};";
}
"Called realwarn",
"CGI::Carp::warn calls CORE::warn");
# Test that message is constructed correctly
eval 'sub CGI::Carp::realwarn {my $mess = shift; return $mess};';
"CGI::Carp::warn builds correct message");
# Test that _warn is called at the correct time
"CGI::Carp::warn builds correct message");
#-----------------------------------------------------------------------------
# Test ineval
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Test die
#-----------------------------------------------------------------------------
# set some variables to control what's going on.
ok($@,
'/^There is a problem/',
'CGI::Carp::die calls CORE::die without altering argument in eval');
# Test that realwarn is called
{
local $^W = 0;
eval 'sub CGI::Carp::realdie {my $mess = shift; return $mess};';
}
'CGI::Carp::die calls CORE::die, but adds stamp');
#-----------------------------------------------------------------------------
# Test set_message
#-----------------------------------------------------------------------------
'My new Message',
'CGI::Carp::set_message returns new message');
ok($CGI::Carp::CUSTOM_MSG,
'My new Message',
'CGI::Carp::set_message message set correctly');
# set the message back to the empty string so that the tests later
# work properly.
#-----------------------------------------------------------------------------
# Test set_progname
#-----------------------------------------------------------------------------
'new_progname',
'CGI::Carp::import set program name correctly');
'newer_progname',
'CGI::Carp::set_progname returns new program name');
'newer_progname',
'CGI::Carp::set_progname program name set correctly');
# set the message back to the empty string so that the tests later
# work properly.
#-----------------------------------------------------------------------------
# Test warnings_to_browser
#-----------------------------------------------------------------------------
# turn off STDOUT (prevents spurious warnings to screen
my $fname = $0;
'warningsToBrowser() on' );
#-----------------------------------------------------------------------------
# Test fatals_to_browser
#-----------------------------------------------------------------------------
sub TIEHANDLE {
my $class = shift;
}
sub PRINT {
my $self = shift;
}
sub READLINE {
my $self = shift;
shift @$self;
}
# do tests
my @result;
# now restore STDOUT
'/Content-type: text\/html/',
"Default string has header");
"Custom message not in default string");
'/Message to the world/',
"Custom Message appears in output");
"Server Admin does not appear in default message");
'/foo@bar.com/',
"Server Admin appears in output");
'/Message to the world/',
"Custom message not in result");
'/Override the message passed in/',
"Correct message in string");
#-----------------------------------------------------------------------------
# Test to_filehandle
#-----------------------------------------------------------------------------
sub buffer {
}
require FileHandle;