BEGIN { $| = 1;
print
"1..5\n"
; }
END {
print
"module load failed\n"
unless
$loaded
; }
$loaded
= 1;
$TEST_NUM
= 1;
report_result(1,
"load test"
);
sub
report_result {
my
$ok
=
shift
;
my
$msg
=
shift
;
print
"not "
unless
$ok
;
print
"ok $TEST_NUM"
;
print
" $msg"
if
$msg
;
print
"\n"
;
$TEST_NUM
++;
}
{
my
$st
= grab {
print
"hel"
;
print
"lo"
; };
&report_result
(
$st
eq
"hello"
,
"grab test"
);
}
{
my
$n
;
my
$st
= grab {
print
"hel"
;
$n
=grab {
print
"nested"
}
print
"lo"
; };
&report_result
(
$st
eq
"hello"
&&
$n
eq
"nested"
,
"nested grab test"
);
}
{
my
$ex
=
""
;
try
{
throw
"error"
;
}
catch
{
$ex
=
$_
;
};
&report_result
(
$ex
eq
"error"
,
"try-catch test"
);
}
{
my
(
$first
,
$second
);
{
my
$out
=
""
;
{
tie
(
*STDOUT
,
"T"
);
print
"Hello"
;
untie
(
*STDOUT
);
}
$first
=
$out
;
$out
=
''
;
{
tie
(
*STDOUT
,
"T"
);
eval
(
"use CGI::WebOut(1)"
);
print
"Hello"
;
untie
(
*STDOUT
);
}
$second
=
$out
;
{{{
sub
TIEHANDLE {
$out
.=
"TIEHANDLE\n"
;
return
bless
{}; }
sub
PRINT {
$out
.=
"PRINT\n"
}
sub
UNTIE {
$out
.=
"UNTIE nRef=$_[1]\n"
}
}}}
}
&report_result
(
$first
eq
$second
,
"tie-safe test"
);
}