I am trying to write a modulino that will accept various parameters through GetOpt::Long. I want to write unit tests for subs that will behave differently depending on the parameters. A SSCCE modulino and test file demonstrate the problem. The modulino:
package mdlno; use strict; use warnings; use feature 'say'; my $param = shift; say main() unless caller(); sub main { $param //= 'World'; return 'Hello ' . $param; }
Tests:
use strict; use warnings; use Test::More tests => 2; use FindBin qw( $RealBin ); use lib $RealBin; use mdlno; my $rtn = mdlno->main(); is $rtn, 'Hello World', 'Works without parameter'; $mdlno::param = 'and goodbye'; $rtn = mdlno->main(); is $rtn, 'Hello and goodbye', 'Works with parameter';
The first test passes but the second fails. I have tried all sorts of variations including Exporter and local, but using the debugger tells me every time that the address used in the test code differs from the address of the parameter in the modulino. All clues gratefully received.
Regards,
John Davies
In reply to [Solved] Parameter injection for testing by davies
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |