Moose and Test::Builder (was Tech Talk Slides)
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
has an interesting issue 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 and there's a good example in Acme::Test::Buffy.
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?
More information about the london.pm