our
$VERSION
=
'1.302210'
;
our
@ISA
=
qw( Test::Builder )
;
BEGIN {
*share
=
sub
{ 0 };
*lock
=
sub
{ 0 };
}
my
$Curr_Test
= 0; share(
$Curr_Test
);
my
@Test_Results
= (); share(
@Test_Results
);
my
$Prem_Diag
= {
diag
=>
""
}; share(
$Curr_Test
);
sub
new
{
my
$class
=
shift
;
return
bless
{},
$class
;
}
sub
ok {
my
(
$self
,
$test
,
$name
) =
@_
;
my
$ctx
=
$self
->ctx;
$test
=
$test
? 1 : 0;
lock
$Curr_Test
;
$Curr_Test
++;
my
(
$pack
,
$file
,
$line
) =
$self
->
caller
;
my
$todo
=
$self
->todo();
my
$result
= {};
share(
$result
);
unless
(
$test
) {
@$result
{
'ok'
,
'actual_ok'
} = ( (
$todo
? 1 : 0 ), 0 );
}
else
{
@$result
{
'ok'
,
'actual_ok'
} = ( 1,
$test
);
}
if
(
defined
$name
) {
$name
=~ s|
$result
->{name} =
$name
;
}
else
{
$result
->{name} =
''
;
}
if
(
$todo
) {
my
$what_todo
=
$todo
;
$result
->{reason} =
$what_todo
;
$result
->{type} =
'todo'
;
}
else
{
$result
->{reason} =
''
;
$result
->{type} =
''
;
}
$Test_Results
[
$Curr_Test
-1] =
$result
;
unless
(
$test
) {
my
$msg
=
$todo
?
"Failed (TODO)"
:
"Failed"
;
$result
->{fail_diag} = (
" $msg test ($file at line $line)\n"
);
}
$result
->{diag} =
""
;
$result
->{_level} =
$Test::Builder::Level
;
$result
->{_depth} = Test::Tester::find_run_tests();
$ctx
->release;
return
$test
? 1 : 0;
}
sub
skip {
my
(
$self
,
$why
) =
@_
;
$why
||=
''
;
my
$ctx
=
$self
->ctx;
lock
(
$Curr_Test
);
$Curr_Test
++;
my
%result
;
share(
%result
);
%result
= (
'ok'
=> 1,
actual_ok
=> 1,
name
=>
''
,
type
=>
'skip'
,
reason
=>
$why
,
diag
=>
""
,
_level
=>
$Test::Builder::Level
,
_depth
=> Test::Tester::find_run_tests(),
);
$Test_Results
[
$Curr_Test
-1] = \
%result
;
$ctx
->release;
return
1;
}
sub
todo_skip {
my
(
$self
,
$why
) =
@_
;
$why
||=
''
;
my
$ctx
=
$self
->ctx;
lock
(
$Curr_Test
);
$Curr_Test
++;
my
%result
;
share(
%result
);
%result
= (
'ok'
=> 1,
actual_ok
=> 0,
name
=>
''
,
type
=>
'todo_skip'
,
reason
=>
$why
,
diag
=>
""
,
_level
=>
$Test::Builder::Level
,
_depth
=> Test::Tester::find_run_tests(),
);
$Test_Results
[
$Curr_Test
-1] = \
%result
;
$ctx
->release;
return
1;
}
sub
diag {
my
(
$self
,
@msgs
) =
@_
;
return
unless
@msgs
;
return
if
$^C;
my
$ctx
=
$self
->ctx;
foreach
(
@msgs
) {
$_
=
'undef'
unless
defined
;
}
push
@msgs
,
"\n"
unless
$msgs
[-1] =~ /\n\Z/;
my
$result
=
$Curr_Test
?
$Test_Results
[
$Curr_Test
- 1] :
$Prem_Diag
;
$result
->{diag} .=
join
(
""
,
@msgs
);
$ctx
->release;
return
0;
}
sub
details {
return
@Test_Results
;
}
sub
note {
}
sub
explain {
return
Test::Builder::explain(
@_
);
}
sub
premature
{
return
$Prem_Diag
->{diag};
}
sub
current_test
{
if
(
@_
> 1)
{
die
"Don't try to change the test number!"
;
}
else
{
return
$Curr_Test
;
}
}
sub
reset
{
$Curr_Test
= 0;
@Test_Results
= ();
$Prem_Diag
= {
diag
=>
""
};
}
1;