CGI-style perl scripts are hard to test in this style:
def test_it_says_hello_to_a_person
get '/home.pl', :name => 'Simon'
assert last_response.body.include?('Simon')
end
(Note: the code is in ruby, using Rack::Test
).
But if I can turn static file to a PSGI application
(A code reference, accept $env
as parameter, return [$status, $header, $body]
), things will be easy, and Plack::Test
will do the rest.
I am reading PSGI specification, generally I can see the route to this. But I still want to know is there any existence wheel to this?
Also, I think Plack::Test
's interface is not as beautiful as Rack::Test
, any Alternatives?
I think you want to look at Plack::App::WrapCGI. When you give it a Perl script as an argument, it uses a technique similar to ModPerl::Registry to compile your CGI script into a PSGI app. And even if it can't figure out how to do that, it has the ability to emulate a complete CGI environment from a PSGI environment, meaning that it can fork and exec a bona fide CGI script (even one written in another language) and run it under any sort of Plack handler, including Plack::Test.