2

I recently learned about Module::Starter and used it to build a skeleton for a web app (assortment of CGI scripts along with associated modules). Being able to test my code by running make test is great, but I'd also like to test the CGI scripts with something like Test::WWW::Mechanize. This would require installing the scripts somewhere and configuring a webserver before running the tests, which seems kind of bassackwards.

Does it even make sense to include tests like this in a distribution? My sense is that I should make my modules do as much of the heavy lifting as possible and have the CGI scripts simply call module functions, but one of my main reasons for testing is avoiding security-related regressions in my CGIs.

3
  • 2
    You don't need a whole server, you just need to provide a basic CGI interface. The standard CGI module includes ways to pass arguments to the script when running it from the command line (i.e. without a server). You can then capture the output and match it against what you expected. Note that you can also have author tests which are not executed on install, but only for yourself. This is good for expensive tests, or regression tests. Commented May 29, 2013 at 21:47
  • @amon In addition to answering my main question, thanks for mentioning author tests, I wasn't aware of that capability and it seems like it could come in handy. Commented May 29, 2013 at 21:59
  • @ThisSuitIsBlackNot have a look at Test::WWW::Mechanize::CGI Commented May 29, 2013 at 23:50

1 Answer 1

3

I don't know why you say you need a webserver. A CGI script (written in Perl or anything else) is just an executable program that expects certain inputs and certain environment variables to be set, and writes an HTTP response to standard output.

So mock up something that sets the CGI environment variables, URL encode your input, and compare your output with what you expected.

Sign up to request clarification or add additional context in comments.

2 Comments

I see amon already expressed the same idea. Great minds think alike, and coincidentally, so do ours.
I was clearly over-thinking this. Thanks for the simple and straightforward answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.