diff options
author | Father Chrysostomos <sprout@cpan.org> | 2014-08-09 22:09:17 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2014-08-09 22:09:17 -0700 |
commit | 672794ca55bc11c78c1244bba9039f731071e1bf (patch) | |
tree | 241fbe3c02fcc944142b0c0082e7c68f1c36e6b8 /t | |
parent | f51551f7eae700328787f130fa35783726046e35 (diff) | |
download | perl-672794ca55bc11c78c1244bba9039f731071e1bf.tar.gz |
Make ‘require $tied_undef’ behave consistently
As of f04d2c345 perl does not give uninitialized warnings for ‘require
undef’. But the check was not happening soon enough, causing tied
variables to behave erratically:
$ ./perl -Ilib -we 'sub TIESCALAR{bless[]}sub FETCH{undef}sub STORE{}tie $x,""; $x="a"; require $x'
Use of uninitialized value $x in require at -e line 1.
Missing or undefined argument to require at -e line 1.
(Uninit warning where muggle variables lack one.)
$ ./perl -Ilib -we 'sub TIESCALAR{bless[]}sub FETCH{undef}sub STORE{}tie $x,""; $x=3; require $x'
Invalid version format (non-numeric data) at -e line 1.
(undef being treated as a version string.)
We have to call get-magic on the argument before we check its
definedness.
Diffstat (limited to 't')
-rw-r--r-- | t/op/require_override.t | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/t/op/require_override.t b/t/op/require_override.t index 40f794d068..7f9ee65e50 100644 --- a/t/op/require_override.t +++ b/t/op/require_override.t @@ -7,7 +7,7 @@ BEGIN { require './test.pl'; } -plan(tests => 6); +plan(tests => 10); my @warns; local $SIG{__WARN__}= sub { push @warns, $_[0] }; @@ -21,6 +21,30 @@ like($error, qr/Missing or undefined argument to require/, "Make sure we got the @warns= (); $error= undef; +sub TIESCALAR{bless[]} +sub STORE{} +sub FETCH{} +tie my $x, ""; +$x = "x"; +eval 'require $x; 1' or $error = $@; +ok(0 == @warns, + 'no warnings from require $tied_undef_after_str_assignment'); +like($error, qr/^Missing or undefined argument to require/, + "Make sure we got the error we expect"); + +@warns= (); +$error= undef; + +$x = 3; +eval 'require $x; 1' or $error = $@; +ok(0 == @warns, + 'no warnings from require $tied_undef_after_num_assignment'); +like($error, qr/^Missing or undefined argument to require/, + "Make sure we got the error we expect"); + +@warns= (); +$error= undef; + *CORE::GLOBAL::require = *CORE::GLOBAL::require = sub { }; eval "require; 1" or $error = $@; ok(1, "Check that eval 'require' on overloaded require does not segv"); |