# -*- Mode: cperl; coding: utf-8; cperl-indent-level: 2 -*-
#!/usr/local/bin/perl -w
-BEGIN {
- chdir 't' if -d 't';
- @INC = '../lib';
-}
-
use strict;
-#use lib qw(t/lib);
-use Test::More tests => 42;
+use lib qw(t/lib);
+
+# 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 lib qw(blib/lib blib/arch);
+
+use Test::More tests => 47;
use IO::Handle;
BEGIN { use_ok('CGI::Carp') };
# Test that _warn is called at the correct time
$CGI::Carp::WARN = 1;
-my $save_expect_l = $expect_l = __LINE__ + 1;
+$expect_l = __LINE__ + 1;
like(CGI::Carp::warn("There is a problem"),
"/] $id: There is a problem at $q_file line $expect_l.".'$/',
"CGI::Carp::warn builds correct message");
CGI::Carp::set_message(''),
#-----------------------------------------------------------------------------
+# Test set_progname
+#-----------------------------------------------------------------------------
+
+import CGI::Carp qw(name=new_progname);
+is($CGI::Carp::PROGNAME,
+ 'new_progname',
+ 'CGI::Carp::import set program name correctly');
+
+is(CGI::Carp::set_progname('newer_progname'),
+ 'newer_progname',
+ 'CGI::Carp::set_progname returns new program name');
+
+is($CGI::Carp::PROGNAME,
+ '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.
+is (CGI::Carp::set_progname(undef),undef,"CGI::Carp::set_progname returns unset name correctly");
+is ($CGI::Carp::PROGNAME,undef,"CGI::Carp::set_progname program name unset correctly");
+
+#-----------------------------------------------------------------------------
# Test warnings_to_browser
#-----------------------------------------------------------------------------
open(STDOUT, ">&REAL_STDOUT");
my $fname = $0;
$fname =~ tr/<>-/\253\273\255/; # _warn does this so we have to also
-is( $fake_out, "<!-- warning: There is a problem at $fname line $save_expect_l. -->\n",
+is( $fake_out, "<!-- warning: There is a problem at $fname line 100. -->\n",
'warningsToBrowser() on' );
is($CGI::Carp::EMIT_WARNINGS, 1, "Warnings turned off");