summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-12-15 16:26:16 -0800
committerFather Chrysostomos <sprout@cpan.org>2011-12-15 16:26:16 -0800
commit7d69d4a61be1619f90910462eac42234c874712e (patch)
tree6c7be0f836c3bb4cd3b20c091c4362a22e8c02fd /t
parentb22bbcf0786b5b4b9edfde241ba29141bb99f219 (diff)
downloadperl-7d69d4a61be1619f90910462eac42234c874712e.tar.gz
Disable $[ under 5.16
This adds the array_base feature to feature.pm Perl_feature_is_enabled has been modified to use PL_curcop, rather than PL_hintgv, so it can work with run-time hints as well. (PL_curcop holds the current state op at run time, and &PL_compiling at compile time, so it works for both.) The hints in $^H are not stored in the same place at compile time and run time, so the FEATURE_IS_ENABLED macro has been modified to check first whether PL_curop == &PL_compiling. Since array_base is on by default with no hint for it in %^H, it is a ‘negative’ feature, whose entry in %^H turns it off. feature.pm has been modified to support such negative features. The new FEATURE_IS_ENABLED_d can check whether such default features are enabled. This does make things less efficient, as every version declaration now loads feature.pm to disable all features (including turning off array_base, which entails adding an entry to %^H) before loading the new bundle. I have plans to make this more efficient.
Diffstat (limited to 't')
-rw-r--r--t/lib/feature/bundle19
-rw-r--r--t/lib/feature/implicit37
-rw-r--r--t/op/array_base.t29
-rw-r--r--t/op/override.t9
4 files changed, 84 insertions, 10 deletions
diff --git a/t/lib/feature/bundle b/t/lib/feature/bundle
index 05708e538e..7e1479f4e3 100644
--- a/t/lib/feature/bundle
+++ b/t/lib/feature/bundle
@@ -78,3 +78,22 @@ EXPECT
custom sub
custom sub
custom sub
+########
+# :default and $[
+# SKIP ? not defined DynaLoader::boot_DynaLoader
+no feature;
+use feature ":default";
+$[ = 1;
+print qw[a b c][2], "\n";
+use feature ":5.16"; # should not disable anything; no feature does that
+print qw[a b c][2], "\n";
+no feature;
+print qw[a b c][2], "\n";
+use feature ":5.16";
+print qw[a b c][2], "\n";
+EXPECT
+Use of assignment to $[ is deprecated at - line 4.
+b
+b
+c
+c
diff --git a/t/lib/feature/implicit b/t/lib/feature/implicit
index e2ae95a19d..010ce8c628 100644
--- a/t/lib/feature/implicit
+++ b/t/lib/feature/implicit
@@ -25,11 +25,12 @@ say defined $INC{"feature.pm"} ? "Helloworld" : "Good bye";
EXPECT
Helloworld
########
-# VERSION requirement, doesn't call feature->import for < 5.9.5
+# VERSION requirement, imports :default feature for < 5.9.5
BEGIN { ++$INC{"feature.pm"} }
-sub feature::import { print "improting\n" }
+sub feature::import { print $_[1], "\n" }
use 5.8.8;
EXPECT
+:default
########
# VERSION requirement, doesn't load anything with require
require 5.9.5;
@@ -78,3 +79,35 @@ EXPECT
yes
evalbytes sub
say sub
+########
+# No $[ under 5.15
+# SKIP ? not defined DynaLoader::boot_DynaLoader
+use v5.14;
+no warnings 'deprecated';
+$[ = 1;
+print qw[a b c][2], "\n";
+use v5.15;
+print qw[a b c][2], "\n";
+EXPECT
+b
+c
+########
+# $[ under < 5.10
+# SKIP ? not defined DynaLoader::boot_DynaLoader
+use feature 'say'; # make sure it is loaded and modifies %^H; we are test-
+use v5.8.8; # ing to make sure it does not disable $[
+no warnings 'deprecated';
+$[ = 1;
+print qw[a b c][2], "\n";
+EXPECT
+b
+########
+# $[ under < 5.10 after use v5.15
+# SKIP ? not defined DynaLoader::boot_DynaLoader
+use v5.15;
+use v5.8.8;
+no warnings 'deprecated';
+$[ = 1;
+print qw[a b c][2], "\n";
+EXPECT
+b
diff --git a/t/op/array_base.t b/t/op/array_base.t
index 34404d491f..a276240c37 100644
--- a/t/op/array_base.t
+++ b/t/op/array_base.t
@@ -1,17 +1,40 @@
#!perl -w
use strict;
-no warnings 'deprecated';
BEGIN {
require './test.pl';
- skip_all_if_miniperl();
+
+ plan (tests => my $tests = 11);
+
+ # Run these at BEGIN time, before arybase loads
+ use v5.15;
+ is(eval('$[ = 1; 123'), undef);
+ like($@, qr/\AAssigning non-zero to \$\[ is no longer possible/);
+
+ if (is_miniperl()) {
+ # skip the rest
+ SKIP: { skip ("no arybase.xs on miniperl", $tests-2) }
+ exit;
+ }
}
-plan (tests => 4);
+no warnings 'deprecated';
is(eval('$['), 0);
is(eval('$[ = 0; 123'), 123);
is(eval('$[ = 1; 123'), 123);
+$[ = 1;
ok $INC{'arybase.pm'};
+use v5.15;
+is(eval('$[ = 1; 123'), undef);
+like($@, qr/\AAssigning non-zero to \$\[ is no longer possible/);
+is $[, 0, '$[ is 0 under 5.16';
+$_ = "hello";
+/l/g;
+my $pos = \pos;
+is $$pos, 3;
+$$pos = 1;
+is $$pos, 1;
+
1;
diff --git a/t/op/override.t b/t/op/override.t
index be39cf9330..b38c3938a1 100644
--- a/t/op/override.t
+++ b/t/op/override.t
@@ -49,13 +49,12 @@ is( $r, "Foo.pm" );
eval "use Foo::Bar";
is( $r, join($dirsep, "Foo", "Bar.pm") );
-# Under PERL_UNICODE, %^H is set, causing Perl_utilize to require
-# feature.pm after 5.006, in order to turn off features. Stop that
-# from interfering with this test by unsetting HINT_LOCALIZE_HH.
+# use VERSION also loads feature.pm.
{
- BEGIN { $^H &= ~0x00020000 } # HINT_LOCALIZE_HH
+ my @r;
+ local *CORE::GLOBAL::require = sub { push @r, shift; 1; };
eval "use 5.006";
- is( $r, "5.006" );
+ like( " @r ", qr " 5\.006 " );
}
{