[Perlunit-users] Bio-Patch: Test-Unit on Win32: OutputDebugString at 'assert' failure time?
Status: Beta
Brought to you by:
mca1001
|
From: Phlip <pl...@sy...> - 2002-11-08 20:20:32
|
> use Test::Unit::Debug;
> {
> no warnings 'redefine';
> package Test::Unit::Debug;
> *Test::Unit::Debug::debug = sub {
> my ($package, $filename, $line) = caller();
> print $out "***************************************that's the
> facts, Jack!\n";
> print $out @_ if $DEBUG{$package};
> }
> }
Trying to get that working exceeded my time box, so I went in for a hack.
Firstly, 'debug' was the wrong method to try to override. I'l eventually
figure out how to perform a hostile override, but for now I went with these
adjustments to the actual source.
First I hack Exception.pm so errors are in this format: path\file(line):
sub stringify {
my $self = shift;
my $file = $self->file;
my $line = $self->line;
my $message = $self->text || 'Died';
my $object = $self->object;
my $winFile = $file;
$winFile =~ s/\//\\/g; # "it's under a Big Dubb'ya"!
my $str = "$winFile($line)";
$str .= ': ' . $object->to_string() if $object &&
$object->can('to_string');
$str .= "\n" . $message;
return $str;
}
Next, I transmogrify TestRunner::print_failures:
...
for my $f (@{$result->failures()}) {
chomp(my $f_to_str = $f);
$self->_print("\n") if $i++;
$self->_print("$i) $f_to_str\n");
use Win32::API::OutputDebugString qw(OutputDebugString);
OutputDebugString("$f_to_str\n");
$self->_print("\nAnnotations:\n", $f->object->annotations())
if $f->object->annotations();
}
...
The result: I can use tests to drive development in an app written in C++,
using an enourmous test suite written in Perl. All using OneButtonTesting,
without manually navigating back to failure lines.
--
Phlip
http://www.greencheese.org/SkeletonCrew
-- Have a :-) day --
|