X-Git-Url: http://git.shiar.net/perl/plp/.git/blobdiff_plain/e99b3964d659c3718110047b10caae453a4aa1d0..51d3d67a18705467fa51bb66805456a2502505f1:/t/50-cgi.t diff --git a/t/50-cgi.t b/t/50-cgi.t index fec88e3..d29fcd0 100644 --- a/t/50-cgi.t +++ b/t/50-cgi.t @@ -1,6 +1,7 @@ use strict; use warnings; +use Cwd; use File::Spec; use Test::More; @@ -14,7 +15,7 @@ require_ok('PLP::Backend::CGI') or BAIL_OUT(); $PLP::use_cache = 0 if $PLP::use_cache; #TODO: caching on (change file names) -my $base = File::Spec->tmpdir || File::Spec->curdir; +my $base = Cwd::abs_path(File::Spec->tmpdir || File::Spec->curdir); -w $base or BAIL_OUT("$base not writable"); my $testfile = 'testfile.plp'; not -f "$base/$testfile" or BAIL_OUT("$testfile exists"); @@ -49,6 +50,16 @@ sub plp_is { is($output, $expect, $test); } +sub getwarning { + # captures the first warning produced by the given code string + my ($code, $line, $file) = @_; + + local $SIG{__WARN__} = sub { die @_ }; + # warnings module runs at BEGIN, so we need to use icky expression evals + eval qq(# line $line "$file"\n$code; return); + return $@; +}; + %ENV = ( REQUEST_METHOD => 'GET', REQUEST_URI => "/$testfile/test/123", @@ -103,11 +114,10 @@ rename "$base/$testfile", "$base/$testfile.inc"; plp_is('include', "<($testfile.inc)> <: include '$testfile.inc'", "$HEAD\nok ok"); unlink "$base/$testfile.inc"; +my $SYNTAXERR = getwarning("q\cq\n\cq; syntax(error", 1, $testfile); plp_is('fatal error', "runtime\n<: syntax(error :>\nruntime", <Debug information:
syntax error at $testfile line 2, at EOF - (Might be a runaway multi-line \cq\cq string starting on line 1) - +
Debug information:
$SYNTAXERR
TEST SKIP: { @@ -119,6 +129,8 @@ if (open my $dummy, "<", $INCFILE) { # like PLP::source will } my $INCWARN = qq{Can't open "$INCFILE" ($!)}; +my $VOIDWARN = getwarning('42', 2, $testfile); + plp_is('warnings', split /\n\n/, < 2<: 42 :> @@ -128,8 +140,7 @@ plp_is('warnings', split /\n\n/, <