Add a new test for Safe
Rafael Garcia-Suarez [Tue, 5 Feb 2008 14:00:00 +0000 (14:00 +0000)]
p4raw-id: //depot/perl@33237

MANIFEST
ext/Safe/t/safeload.t [new file with mode: 0644]

index 2c3dd58..a49b81b 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -1006,6 +1006,7 @@ ext/re/t/re.t                     see if re pragma works
 ext/Safe/t/safe1.t             See if Safe works
 ext/Safe/t/safe2.t             See if Safe works
 ext/Safe/t/safe3.t             See if Safe works
+ext/Safe/t/safeload.t          Tests that some modules can be loaded by Safe
 ext/Safe/t/safeops.t           Tests that all ops can be trapped by Safe
 ext/Safe/t/safeuniversal.t     Tests Safe with functions from universal.c
 ext/SDBM_File/Makefile.PL      SDBM extension makefile writer
diff --git a/ext/Safe/t/safeload.t b/ext/Safe/t/safeload.t
new file mode 100644 (file)
index 0000000..6817c2c
--- /dev/null
@@ -0,0 +1,30 @@
+#!perl
+
+BEGIN {
+    if ($ENV{PERL_CORE}) {
+       chdir 't' if -d 't';
+       @INC = '../lib';
+    }
+    require Config;
+    import Config;
+    if ($Config{'extensions'} !~ /\bOpcode\b/) {
+       print "1..0\n";
+       exit 0;
+    }
+    # Can we load the version module ?
+    eval { require version; 1 } or do {
+       print "1..0 # no version.pm\n";
+       exit 0;
+    };
+    delete $INC{"version.pm"};
+}
+
+use strict;
+use Test::More;
+use Safe;
+plan(tests => 1);
+
+my $c = new Safe;
+$c->permit(qw(require caller));
+my $r = $c->reval(q{ use version; 1 });
+ok( defined $r, "Can load version.pm in a Safe compartment" ) or diag $@;