DEBUG
=>
$ENV
{DEVICE_RFXCOM_TEST_HELPERS_DEBUG}
};
our
%EXPORT_TAGS
= (
'all'
=> [
qw(
test_error
test_warn
test_output
)
] );
our
@EXPORT_OK
= ( @{
$EXPORT_TAGS
{
'all'
} } );
our
@EXPORT
=
qw()
;
our
$VERSION
=
qw/$Revision$/
[1];
sub
test_error {
my
$sub
=
shift
;
eval
{
$sub
->() };
my
$error
= $@;
if
(
$error
) {
$error
=~ s/\s+at (\S+|\(
eval
\d+\)(\[[^]]+\])?) line \d+\.?\s*$//g;
$error
=~ s/\s+at (\S+|\(
eval
\d+\)(\[[^]]+\])?) line \d+\.?\s*$//g;
$error
=~ s/ \(\
@INC
contains:.*?\)$//;
}
return
$error
;
}
sub
test_warn {
my
$sub
=
shift
;
my
$warn
;
local
$SIG
{__WARN__} =
sub
{
$warn
.=
$_
[0]; };
eval
{
$sub
->(); };
die
$@
if
($@);
if
(
$warn
) {
$warn
=~ s/\s+at (\S+|\(
eval
\d+\)(\[[^]]+\])?) line \d+\.?\s*$//g;
$warn
=~ s/\s+at (\S+|\(
eval
\d+\)(\[[^]]+\])?) line \d+\.?\s*$//g;
$warn
=~ s/ \(\
@INC
contains:.*?\)$//;
}
return
$warn
;
}
sub
test_output {
my
(
$sub
,
$fh
) =
@_
;
my
(
$tmpfh
,
$tmpfile
) = tempfile();
open
my
$oldfh
,
">&"
,
$fh
or
die
"Can't dup \$fh: $!"
;
open
$fh
,
">&"
,
$tmpfh
or
die
"Can't dup \$tmpfh: $!"
;
$sub
->();
open
$fh
,
">&"
,
$oldfh
or
die
"Can't dup \$oldfh: $!"
;
$tmpfh
->flush;
open
my
$rfh
,
'<'
,
$tmpfile
;
local
$/;
undef
$/;
my
$c
= <
$rfh
>;
close
$rfh
;
unlink
$tmpfile
;
$tmpfh
->
close
;
return
$c
;
}
1;