Upgrade to PathTools-3.17
[p5sagit/p5-mst-13.2.git] / ext / Cwd / t / taint.t
index 74e2d65..c92dbe3 100644 (file)
@@ -1,21 +1,35 @@
 #!./perl -Tw
 # Testing Cwd under taint mode.
 
+use strict;
+
 BEGIN {
-    chdir 't' if -d 't';
-    @INC = '../lib';
+    if ($ENV{PERL_CORE}) {
+        chdir 't';
+        @INC = '../lib';
+    }
 }
-
 use Cwd;
-use Test::More tests => 2;
+chdir 't';
 
-# The normal kill() trick is not portable.
-sub is_tainted { 
-    return ! eval { eval("#" . substr(join("", @_), 0, 0)); 1 };
-}
+use File::Spec;
+use lib File::Spec->catdir('t', 'lib');
+use Test::More tests => 17;
 
-my $cwd;
-eval { $cwd = getcwd; };
-is( $@, '',                 'getcwd() does not explode under taint mode' );
-ok( is_tainted($cwd),       "its return value is tainted" );
+use Scalar::Util qw/tainted/;
+
+my @Functions = qw(getcwd cwd fastcwd fastgetcwd
+                   abs_path fast_abs_path
+                   realpath fast_realpath
+                  );
+
+foreach my $func (@Functions) {
+    no strict 'refs';
+    my $cwd;
+    eval { $cwd = &{'Cwd::'.$func} };
+    is( $@, '',                "$func() should not explode under taint mode" );
+    ok( tainted($cwd), "its return value should be tainted" );
+}
 
+# Previous versions of Cwd tainted $^O
+is !tainted($^O), 1, "\$^O should not be tainted";