Moose and Test::Builder (was Tech Talk Slides)

Mark Fowler mark at twoshortplanks.com
Wed Feb 1 14:31:49 GMT 2012


So, I've found an interesting problem that I was wondering if the list
could help me with.   The just mentioned Test::WWW::Selenium::More[1]
has an interesting issue[2] that I can't find a way around to do with
stack frames and where exactly it reports a failing test from.

Where in your code Test::Builder reports failing tests from is
controlled by the $Test::Builder::Level package variable. Every time
your test suite introduces a new stack frame within which you don't
want to report the failing test occurring at you need to increase the
$Test::Builder::Level variable in dynamic scope (i.e. use local to
give it a bigger value.)   This is all documented in Test::Builder's
manual[3] and there's a good example in Acme::Test::Buffy[4].

Now let's look at Test::WWW::Selenium::More.  TWSM is a Moose module.
It uses two cool Moose tricks to augment Test::WWW::Selenium.  Firstly
it holds onto a TWS object (in a private attribute called "_selenium")
and uses delegation to create methods in TWSM that correspond directly
to the same named methods in TWS.  Secondly it uses "around" to wrap
extra code again around these methods in order to do things like
altering the return value.  However: both of these tricks add stack
frames, which sadly prevents Test::Builder reporting errors in the
right place.  Oh nos!

Now I'm not sure what to suggest to do to fix it.  I'd normally just
increase the number of stack frames that Test::Builder must look back
through by using $Test::Builder::Level, but I didn't add the extra
stack frames - Moose did.  I don't know how many stack frames Moose
added and even if I were to find out, I wouldn't be able to guarantee
that this number will be the same for all future or previous versions
of Moose.  It would produce some very brittle code.

Anyone got any ideas of what we should do?

Mark.

[1] https://metacpan.org/module/Test::WWW::Selenium::More
    https://github.com/kablamo/Test-WWW-Selenium-More
[2] https://rt.cpan.org/Ticket/Display.html?id=74586
[3] https://metacpan.org/module/Test::Builder#Test-style
[4] https://metacpan.org/source/MARKF/Acme-Test-Buffy-0.02/lib/Acme/Test/Buffy.pm


More information about the london.pm mailing list