our
@EXPORT
=
qw(throws_errno_ok)
;
my
$CLASS
= __PACKAGE__;
my
%cache
;
BEGIN {
%cache
=
map
{
$_
=>
$_
} 0 .. 255;
foreach
my
$name
(
@Errno::EXPORT_OK
, @{
$Errno::EXPORT_TAGS
{
'POSIX'
} } ) {
my
$sv
=
$Errno::
{
$name
};
next
unless
$$sv
;
$cache
{
int
$$sv
} =
$name
;
}
$cache
{0} =
'No error'
;
}
sub
throws_errno_ok (&$$) {
my
(
$sub
,
$errno
,
$message
) =
@_
;
my
$builder
=
$CLASS
->builder;
my
$pass
= 1;
local
$@;
try
{
$sub
->();
$pass
= 0;
}
catch
{};
my
$found
=
int
$!;
$pass
= 0
unless
$found
==
$errno
;
$builder
->ok(
$pass
,
$message
);
unless
(
$pass
) {
$builder
->diag(
"expected: $cache{$errno}"
);
$builder
->diag(
"found: $cache{$found}"
);
}
return
$pass
;
}
1;