Re: [Perlunit-devel] oh dear
Status: Beta
Brought to you by:
mca1001
From: Adam S. <ad...@sp...> - 2001-12-21 12:06:12
|
Piers Cawley (pdc...@bo...) wrote: > Adam Spiers <ad...@sp...> writes: > > Adam Spiers (ad...@sp...) wrote: > >> Think I just found some bad brokenness, although it could be just me > >> getting hopelessly confused as my brain gets trampled into mush by a > >> quagmire of exceptions and assertions. I have a testcase: > >> > >> sub test_this_should_fail { > >> my $self = shift; > >> $self->assert(sub { $_[0] eq $_[1] or die "$_[0] ne $_[1]" }, 'a', 'b'); > >> } > >> > >> which does not fail. In fact it behaves identically to > >> > >> sub test_this_should_fail { > >> my $self = shift; > >> $self->assert(sub { $_[0] eq $_[1] or die "$_[0] ne $_[1]" }, 'a', 'a'); > >> } > >> > >> Can anyone reproduce with latest CVS? > > > > Ignore that. The problem is that the die() from within a > > Assertion::CodeRef produces an Error::Simple, which gets turned into a > > Test::Unit::Failure too far up the stack, so if > > test_this_should_fail() is in AssertTest.pm, it won't work with > > check_failures(). Argh. What to do? > > Hmm... I'm thinking. All I've come up with so far is to change check_failures() to recognise with Error::Simple and treat it as a Test::Unit::Failure. But AFAICS T::U::Assertion::CodeRef is the only place which seems to consider a die() as a Test::Unit::Failure rather than a Test::Unit::Error, and I don't understand how this inconsistency can work, since a die from inside a T::U::Assertion::CodeRef will be indistinguishable from (say) a syntax error inside one. I only just figured out the die() -> Error::Simple -> Test::Unit::Error stuff yesterday, so I may be misunderstanding things, in which case, please let me know! If I'm right however, some possible solutions occur to me: - Change T::U::Assertion::CodeRef::do_assertion to rethrow die() exceptions as Test::Unit::Failures. Almost ideal, except for the serious flaw that syntax errors in the coderef turn up as failures. - Change the semantics of T::U::Assertion::CodeRefs so that on failure they return($failure_msg) rather than die($failure_msg), and on success they return zero (a la shell)? That would be very easy to implement, although confusing in that it's the exact opposite of Perl's notions of true/false. - Change the semantics of T::U::Assertion::CodeRefs so that on failure they throw a Test::Unit::Failure rather than a die(). In that case, it would be better to drop the current requirement that a coderef has to return true to indicate success, since it would no longer be necessary. The third option is my preference. |