in reply to Re: Test::Code
in thread Test::Code

I agree that the name is bad. I do plan to change it. As for why I might not want to execute the code, think about "HOP." If you were to try and write tests for the parser, you might find it quite a bit easier to write eq_code $code, $expected; than to constantly create correct subs to pass into code and make them work.

A problem can also arise when the code being generated does things that you'd rather not execute. Maybe it starts pulling a value off an iterator but you don't want that to happen yet. Maybe it deletes files, closes a filehandle or does other cleanup work that shouldn't happen yet.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^3: Test::Code
by adrianh (Chancellor) on Aug 13, 2005 at 08:34 UTC
    If you were to try and write tests for the parser, you might find it quite a bit easier to write eq_code $code, $expected; than to constantly create correct subs to pass into code and make them work.

    What I'd probably do would be to start with tests asking it to parse some strings - and see where that would take me. I've test-firsted parsers in the past like this without too much difficulty. I might try it your way next time to see what it's like :-)

    A problem can also arise when the code being generated does things that you'd rather not execute. Maybe it starts pulling a value off an iterator but you don't want that to happen yet. Maybe it deletes files, closes a filehandle or does other cleanup work that shouldn't happen yet.

    In this case I'd want the dangerous stuff off somewhere I could use mock objects and/or dependency injection to make it safely testable.