开发者

Fake CGI environment for an external program

开发者 https://www.devze.com 2023-03-03 16:33 出处:网络
Suppose I have a CGI script, not necessarily written in Perl, and I want to unit test that. Of course I can just use a web-server and LWP::UserAgent but I think that\'s a bit of overkill.

Suppose I have a CGI script, not necessarily written in Perl, and I want to unit test that.

Of course I can just use a web-server and LWP::UserAgent but I think that's a bit of overkill.

So, how can I run a CGI program from within perl? E.g. in pseudocode:

my $reply = fake_cgi("/path/to/prog.cgi", foo=>"bar", count=>1);
like ($reply->content, qr/<title>/, "Title is always present");

I've found this advice but I开发者_运维知识库'd still prefer a ready-made module.


I think CGI::Test is what your looking for. I haven't used it my self but it's docs say,

The CGI::Test module provides a CGI regression test framework which allows you to run your CGI programs offline, i.e. outside a web server, and interact with them programmatically, without the need to type data and click from a web browser.

and

Note that the CGI scripts you can test with CGI::Test need not be implemented in Perl at all. As far as this framework is concerned, CGI scripts are executables that are run on a CGI-like environment and which produce an output.


A CGI program can be executed like a normal application. It takes its input params from STDIN and ENV (environment variables). So you have to call with the properly variables, and read the STDOUT of the program.

0

精彩评论

暂无评论...
验证码 换一张
取 消