Hello all,
I have posted this question on CPAN Forum but nobody answered, so I
also post it here in case someone has an idea.
While rewriting Net::Pcap test suite, I quickly stumbled upon this
problem: it looks like Test::Exception can't catch croak() or die()
thrown from XS code. Here is an example:
use strict;
use Test::More tests => 1;
use Net::Pcap;
eval "use Test::Exception";
my $has_test_exception = !$@;
SKIP: {
skip "Test::Exception not available", 1 unless
$has_test_exception;
dies_ok {
$dev = Net::Pcap::lookupdev(undef)
} '/^arg1 not a reference/',
"calling lookupdev() with no reference"
}
When executed, this script gives the following:
$ perl 02-lookupdev.t
1..1
arg1 not a hash ref at 02-lookupdev.t line 15.
# Looks like your test died before it could output anything.
I checked that the exception can be caught using eval{} or eval"":
$ perl -MNet::Pcap -le 'eval{Net::Pcap::lookupdev(undef)}; print
"after"'
after
But if I try to do the same thing with Test::Exception, wrapping the
lookupdev() call within an eval{}, it throws me a new kind of error:
$ perl 02-lookupdev.t
1..1
Can't call method "dies_ok" without a package or object reference
at 02-lookupdev.t line 14.
# Looks like your test died before it could output anything.
Using the parens form of dies_ok() resolves the syntax error but then
the test always successes.
Am I doing something wrong?
Sébastien Aperghis-Tramoni
-- - --- -- - -- - --- -- - --- -- - --[ http://maddingue.org ]
Close the world, txEn eht nepO