On Fri, Jul 09, 2004 at 11:00:28AM -0400, Michael G Schwern wrote:
> Never underestimate The Damian.
For a moment I though I had.
> #!/usr/bin/perl -w
>
> use Hook::LexWrap;
> use Test::Builder;
> use Term::ANSIColor;
>
> wrap *Test::Builder::diag, pre => sub {
> $_[1] = color('red') . $_[1];
> $_[-2] =~ s/$/color 'reset'/e;
> };
>
> use Test::More tests => 1;
>
> fail("Its fun to COLOR!");
>
> Seems altering the elements of @_ works but adding them does not. He's
> relying on @_ aliasing rather than passing @_ around explicitly. I guess
> only the elements of @_ are aliased, not the whole array.
Add
diag("Its fun to COLOR!");
to the above to see why I doubted.
When you call fail(), the message gets stuffed into a variable and then
passed to the wrapped sub but calling diag directly means $_[1] is a
constant and the wrapper dies with
Modification of a read-only value attempted at sch line 8.
> > While you're here, any chance you'd consider converting Test::Builder to be
> > hash based rather than class based with a way of creating new instances.
> > Obviously there should be only 1 real Test::Builder object but allowing
> > other instances would make test-module testing easier and test nesting
> > (suites of suites etc) possible,
>
> Yes, this is planned for 0.50. If nothing else it will let Test::Builder
> test itself and make Mark Fowler handy.
I did it about a year ago. I'll dig out the patch and see if it still
applies,
F