|XP is just a number|
Re: Eliminating duplicated code in multiple test scripts using Test::Moreby kcott (Canon)
|on Jul 20, 2013 at 07:42 UTC||Need Help??|
One issue I see with this is that you need to know how many tests are in TMod::sub1() in order to specify tests => 5 in t1.pl. If that's intended to be common code, then whenever the common code changes all test scripts that use it will also need to be changed.
One way around this would be to use Test::More's subtest() function. Consider this slight rewrite of the code you posted.
With this setup, you can add, remove or change the tests in TMod::sub1() without ever needing to change any of the calling scripts. You could also pass arguments to TMod::sub1() to control which tests are run with sub1() dynamically determining the value for plan tests => $num_tests; (again, without requiring any changes to the calling scripts).