The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl
#
# 09-cgi.t
#
# cgi test script
#
# run the cgi-test and check the resulting output
#

use strict; use warnings;
use File::Basename qw(dirname);
use File::Spec;
use PDF::Create;
use Test::More tests => 2;
use Config;

my $pdfname = $0;
$pdfname =~ s/\.t/\.pdf/;
my $cginame = File::Spec->catfile(dirname($0) . "/09-cgi-script.pl");

#
# run the cgi
#
my @out = `$Config{"perlpath"} $cginame`;
#shift @out;
#shift @out;
#diag $out;
diag $pdfname;
if (open my $fh, '>', $pdfname) {
	print $fh @out;
	close $fh;
}

ok scalar(@out), "CGI executes";

################################################################
#
# Check the resulting pdf for errors with pdftotext
#
SKIP: {
	skip '/usr/bin/pdftotext not installed', 1 if (! -x '/usr/bin/pdftotext');
    my $out = `/usr/bin/pdftotext $pdfname /dev/null 2>&1`;
    ok( $out eq "", "pdftotext $out");
}