On Thu Jan 05 17:28:56 2012, ANDK wrote:
Show quoted text
This module’s tests are relying on buggy hint scoping and implementation details of the
feature pragma.
The values of $^H and %^H come into effect at the end of the innermost currently-running
BEGIN block. So for eval to localise them at run time is a bug, because it prevents a BEGIN
block or an import called by such (whether implicit or no) from setting %^H in eval.
The attached patch stops the tests from relying on that bug and actually tests for features
themselves instead of feature hints.
diff -rup Modern-Perl-1.20120106-H3S9HL/t/base.t Modern-Perl-1.20120106-H3S9HL-copy/t/base.t
--- Modern-Perl-1.20120106-H3S9HL/t/base.t 2012-01-05 16:26:11.000000000 -0800
+++ Modern-Perl-1.20120106-H3S9HL-copy/t/base.t 2012-01-19 14:16:51.000000000 -0800
@@ -56,8 +56,10 @@ if ($] > 5.011003)
{
eval q|
use Modern::Perl;
- ok exists $^H{feature_unicode},
+ BEGIN {
+ ok exists $^H{feature_unicode},
'... and should unilaterally enable unicode_strings, when available';
+ }
|;
}
diff -rup Modern-Perl-1.20120106-H3S9HL/t/year_imports.t Modern-Perl-1.20120106-H3S9HL-copy/t/year_imports.t
--- Modern-Perl-1.20120106-H3S9HL/t/year_imports.t 2012-01-05 16:26:11.000000000 -0800
+++ Modern-Perl-1.20120106-H3S9HL-copy/t/year_imports.t 2012-01-19 14:42:50.000000000 -0800
@@ -4,48 +4,71 @@ use Test::More 0.98;
use Modern::Perl ();
-eval q|
- Modern::Perl->import( '2009' );
- my @features = grep /^feature_/, keys %^H;
- is @features, 3, 'use Modern::Perl 2009 should enable three features';
- ok exists $^H{feature_switch}, '... switch';
- ok exists $^H{feature_say}, '... say';
- ok exists $^H{feature_state}, '... and state';
-|;
-
-my @features = grep /^feature_/, keys %^H;
-is @features, 0, 'use Modern::Perl () should enable no features';
-
-eval q|
- Modern::Perl->import( '2010' );
- my @features = grep /^feature_/, keys %^H;
- is @features, 3, 'use Modern::Perl 2010 should enable three features';
- ok exists $^H{feature_switch}, '... switch';
- ok exists $^H{feature_say}, '... say';
- ok exists $^H{feature_state}, '... and state';
-|;
-
-eval q|
- Modern::Perl->import( '2011' );
- my @features = grep /^feature_/, keys %^H;
- is @features, 4, 'use Modern::Perl 2011 should enable four features';
- ok exists $^H{feature_switch}, '... switch';
- ok exists $^H{feature_say}, '... say';
- ok exists $^H{feature_state}, '... state';
- ok exists $^H{feature_unicode}, '... and unicode_strings';
-| if $] >= 5.012;
-
-eval q|
- Modern::Perl->import( '2012' );
- my @features = grep /^feature_/, keys %^H;
- is @features, 4, 'use Modern::Perl 2012 should enable four features';
- ok exists $^H{feature_switch}, '... switch';
- ok exists $^H{feature_say}, '... say';
- ok exists $^H{feature_state}, '... state';
- ok exists $^H{feature_unicode}, '... and unicode_strings';
-| if $] >= 5.014;
-
-@features = grep /^feature_/, keys %^H;
-is @features, 0, '... but none should leak out';
+$SIG{__WARN__} = sub {
+ return if $_[0] =~ /Number found where operator expected/;
+ return if $_[0] =~ /Do you need to predeclare/;
+ return if $_[0] =~ /future reserved word/;
+ warn shift
+};
+
+eval 'sub { given (0){} }';
+isn't $@, "", 'use Modern::Perl () does not enable switch';
+eval 'sub { say 0 }';
+isn't $@, "", 'use Modern::Perl () does not enable say';
+eval 'state $x';
+isn't $@, "", 'use Modern::Perl () does not enable state';
+is uc "\xdf", "\xdf", 'Modern::Perl () does not enable unicode_strings';
+
+{
+ use Modern::Perl +2009;
+ eval 'sub { given (0){} }';
+ is $@, "", 'use Modern::Perl 2009 enables switch';
+ eval 'sub { say 0 }';
+ is $@, "", 'use Modern::Perl 2009 enables say';
+ eval 'state $x';
+ is $@, "", 'use Modern::Perl 2009 enables state';
+ is uc "\xdf", "\xdf", 'but not unicode_strings';
+}
+
+{
+ use Modern::Perl +2010;
+ eval 'sub { given (0){} }';
+ is $@, "", 'use Modern::Perl 2010 enables switch';
+ eval 'sub { say 0 }';
+ is $@, "", 'use Modern::Perl 2010 enables say';
+ eval 'state $x';
+ is $@, "", 'use Modern::Perl 2010 enables state';
+ is uc "\xdf", "\xdf", 'but not unicode_strings';
+}
+
+if ($] >= 5.012) {
+ use Modern::Perl +2011;
+ eval 'sub { given (0){} }';
+ is $@, "", 'use Modern::Perl 2011 enables switch';
+ eval 'sub { say 0 }';
+ is $@, "", 'use Modern::Perl 2011 enables say';
+ eval 'state $x';
+ is $@, "", 'use Modern::Perl 2011 enables state';
+ is uc "\xdf", "SS", '2011 enables unicode_strings';
+}
+
+if ($] >= 5.014) {
+ use Modern::Perl +2011;
+ eval 'sub { given (0){} }';
+ is $@, "", 'use Modern::Perl 2011 enables switch';
+ eval 'sub { say 0 }';
+ is $@, "", 'use Modern::Perl 2011 enables say';
+ eval 'state $x';
+ is $@, "", 'use Modern::Perl 2011 enables state';
+ is uc "\xdf", "SS", '2011 enables unicode_strings';
+}
+
+eval 'sub { given (0){} }';
+isn't $@, "", 'switch feature does not leak out';
+eval 'sub { say 0 }';
+isn't $@, "", 'say feature does not leak out';
+eval 'state $x';
+isn't $@, "", 'state feature does not leak out';
+is uc "\xdf", "\xdf", 'unicode_strings feature does not leak out';
done_testing;