How can I test a standalone Perl script?

前端 未结 7 1495
太阳男子
太阳男子 2021-02-01 05:07

I have written a small Perl script and now I would like to create a test suite for it. I thought it would be nice to be able to use the script as a module, import t

7条回答
  •  青春惊慌失措
    2021-02-01 05:45

    It depends on whether you want to test the script itself, or test the subs that make up the script. If you want to test the script, then an external test would be more appropriate, e.g. a shell script. If you want to test the functions that make up the script, then you can either write those tests as more functions within the script or refactor the elements into a Perl module and test the module (which you say you don't want to do).

    If the script is small enough, then refactoring might not be necessary. Simply add a '-test' command line argument and call into a test sub, which in turn tests everything else. If doing this, I like to print out a progress indicator of some kind (e.g. a '.' for every test that passes).

    If the script is more complex, though, you may want to consider refactoring bits into one or more modules and testing them with Test::Simple or Test::More.

提交回复
热议问题