chromatic wrote: > On Saturday 24 February 2007 06:47, Eric Hacker wrote: > >> Is it OK to have the return value from a test be something more than >> just true when a test passes? Thus the test might be used as a right >> value in the test script. > > Seems like, in general, the semi-predicate problem. What if the value being > tested should evaluate to false, but the test should pass?
Yeah, I was thinking the same thing. is 1-1, 0 or diag "OMG UNIVERSE BROKEN!"; Just make sure whatever you return evaluates according to the test pass/fail and not its value and you should be fine. You can return a little wrapper object like... # <handwave>I didn't actually try this</handwave> package Test::Result; use overload 'bool' => sub { shift->{ok} }, '""' => sub { shift->{value} }, fallback => 1; sub new { my($class, $ok, $value) = @_; bless { ok => $ok, value => $value }, $class; } 1;