gpt4 book ai didi

perl - 外部程序的假 CGI 环境

转载 作者:行者123 更新时间:2023-12-01 11:57:10 24 4
gpt4 key购买 nike

假设我有一个 CGI 脚本,不一定是用 Perl 编写的,我想对其进行单元测试。

当然,我可以只使用网络服务器和 LWP::UserAgent,但我认为这有点矫枉过正。

那么,我怎样才能在 perl 中运行 CGI 程序呢?例如。在伪代码中:

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

我找到了 this advice但我还是更喜欢现成的模块。

最佳答案

我认为CGI::Test是你要找的。我自己没有用过它,但文档说,

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.

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.

关于perl - 外部程序的假 CGI 环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5895473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com