From c9cbaccbfecee703aef31834907f10f325622116 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Wed, 1 Jun 2016 17:54:26 -0700 Subject: [PATCH] switch 17_version_cgi.t to use DebbugsTest::HTTPServer --- t/17_version_cgi.t | 84 +++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 53 deletions(-) diff --git a/t/17_version_cgi.t b/t/17_version_cgi.t index 35d75c4..cfdc980 100644 --- a/t/17_version_cgi.t +++ b/t/17_version_cgi.t @@ -1,64 +1,42 @@ # -*- mode: cperl;-*- -use Test::More; - use warnings; use strict; -plan tests => 2; - -my $port = 11343; - -our $child_pid = undef; - -END{ - if (defined $child_pid) { - my $temp_exit = $?; - kill(15,$child_pid); - waitpid(-1,0); - $? = $temp_exit; - } -} - -my $pid = fork; -die "Unable to fork child" if not defined $pid; -if ($pid) { - $child_pid = $pid; - # Wait for two seconds to let the child start - sleep 2; -} -else { - # UGH. - package SillyWebServer; - use HTTP::Server::Simple; - use base qw(HTTP::Server::Simple::CGI::Environment HTTP::Server::Simple); - sub handler { - my $fh; - open($fh,'-|',-e './cgi/version.cgi'? './cgi/version.cgi' : '../cgi/version.cgi'); - my $headers; - my $status = 200; - while (<$fh>) { - if (/^\s*$/ and $status) { - print "HTTP/1.1 $status OK\n"; - print $headers; - $status = 0; - print $_; - } elsif ($status) { - $headers .= $_; - if (/^Status:\s*(\d+)/i) { - $status = $1; - } - } else { - print $_; +use Test::More; +# The test functions are placed here to make things easier +use lib qw(t/lib); +use DebbugsTest qw(:all); + +plan tests => 3; + +my $port = 11344; + +my $version_cgi_handler = sub { + my $fh; + open($fh,'-|',-e './cgi/version.cgi'? './cgi/version.cgi' : '../cgi/version.cgi'); + my $headers; + my $status = 200; + while (<$fh>) { + if (/^\s*$/ and $status) { + print "HTTP/1.1 $status OK\n"; + print $headers; + $status = 0; + print $_; + } elsif ($status) { + $headers .= $_; + if (/^Status:\s*(\d+)/i) { + $status = $1; } - + } else { + print $_; } - } - my $server = SillyWebServer->new($port); - $server->run(); - exit 0; -} + } +}; + +ok(DebbugsTest::HTTPServer::fork_and_create_webserver($version_cgi_handler,$port), + 'forked HTTP::Server::Simple successfully'); use LWP::UserAgent; my $ua = LWP::UserAgent->new; -- 2.39.2