test in directories provided by Test::Spec
[perl/plp/.git] / t / 50-cgi.t
index cd10ee47381c916c4f7cf9fced66c13b0ca7d7ed..7ef973b5205151c38715cc5cdbd41a4e507a9ac7 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Cwd qw(cwd);
+use File::Spec;
 use Test::More;
 
 eval { require PerlIO::scalar };
@@ -14,11 +14,12 @@ require_ok('PLP::Backend::CGI') or BAIL_OUT();
 $PLP::use_cache = 0 if $PLP::use_cache;
 #TODO: caching on (change file names)
 
-my $base = -w '/tmp' ? '/tmp' : cwd();
+my $base = 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");
 
-open ORGOUT, '>&', STDOUT;
+open ORGOUT, '>&', *STDOUT;
 
 sub plp_is {
        my ($test, $plp, $expect) = @_;
@@ -106,6 +107,15 @@ $HEAD
 </td></tr></table>
 TEST
 
+SKIP: {
+
+my $INCFILE = File::Spec->rel2abs("$base/missinginclude");
+if (open my $dummy, "<", $INCFILE) {  # like PLP::source will
+       fail("file missinginclude shouldn't exist");
+       skip("missinginclude tests", 2);
+}
+my $INCWARN = qq{Can't open "$INCFILE" ($!)};
+
 plp_is('warnings', split /\n\n/, <<TEST, 2);
 1
 <: use warnings :>
@@ -129,16 +139,16 @@ Useless use of a constant in void context at $testfile line 4.
 warning at $testfile line 6.
 
 4
-<table border=1 class="PLPerror"><tr><td><b>Debug information:</b><br>Can't open "$base/missinginclude" (No such file or directory) at $testfile line 8.
+<table border=1 class="PLPerror"><tr><td><b>Debug information:</b><br>$INCWARN at $testfile line 8.
 </td></tr></table>
 5
-<table border=1 class="PLPerror"><tr><td><b>Debug information:</b><br>Can't open "$base/missinginclude" (No such file or directory) at $testfile line 10.
+<table border=1 class="PLPerror"><tr><td><b>Debug information:</b><br>$INCWARN at $testfile line 10.
 </td></tr></table>
 TEST
 
 plp_is('$PLP::ERROR',
        '<: $PLP::ERROR = sub {print "Oh no: $_[0]"} :> <(missinginclude)>.',
-       qq{$HEAD\n Oh no: Can't open "$base/missinginclude" (No such file or directory) at $testfile line 1.\n\n}
+       qq{$HEAD\n Oh no: $INCWARN at $testfile line 1.\n\n}
 );
 
 #TODO: 404
@@ -149,6 +159,8 @@ plp_is('$PLP::DEBUG',
        "Content-Type: text/plain\n\nContent-Type: text/html\n\n1"
 );
 
+}
+
 plp_is('utf8', '<: use open qw/:std :utf8/; print chr 191', <<TEST);
 Content-Type: text/html; charset=utf-8
 X-PLP-Version: $PLP::VERSION