CPAN::Forum
Test-Exception - Test::Exception and XS code
| Posted on Sun Aug 14 20:19:04 2005 by maddingue |
| Test::Exception and XS code |
|
Hello,
While trying to rewrite 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 = !$@;
my ($dev,$err) = ('','');
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 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.
Any idea?
|
| Direct Responses: 893 | Write a response |
(6)
]