I’m writing unit tests using Test::More and Test::Output. I use Test::More to validate the return values and I plan to use Test::Output to validate the stdout produced by my subroutines.
I am attempting to write test cases for a subroutine whose stdout is dependent on the arguments sent. Test::Output::stdout_like(code reference, regexp, test description) looks to have the functionality I want, however I am struggling to construct a code reference which contains an argument.
I presume this is a common practice within Perl unit testing scripts. Can anyone offer an example?
Side note, thanks to Kurt W. Leucht for his Perl unit testing introduction: Perl build, unit testing, code coverage: A complete working example
No you can’t directly include an arg within a coderef.
To pass an arg to a coderef you need to actually call it:
But to get something working with
Test::Outputyou can wrap calls to the subroutines you want to test in an another subroutine:And, this is doing the same thing using an anonymous subroutine: