diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-06-08 10:19:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-08 10:19:08 -0700 |
commit | 117310bdc00236c0a7676616ce25b5106775dabc (patch) | |
tree | 3a9711e9446d22bca99c8a56e8ceff723f0c8f04 /test/ruby | |
parent | 8c87efaa8a45166ed977294330c32a4b186b8e7b (diff) | |
download | ruby-117310bdc00236c0a7676616ce25b5106775dabc.tar.gz |
Make ENV.clone warn and ENV.dup raise
ENV.dup returned a plain Object, since all of ENV's behavior is
defined in ENV's singleton class. So using dup makes no sense.
ENV.clone works and is used in some gems, but it doesn't do what
the user expects, since modifying ENV.clone also modifies ENV.
Add a deprecation warning pointing the user to use ENV.to_h
instead.
This also undefines some private initialize* methods in ENV,
since they are not needed.
Fixes [Bug #17767]
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_env.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index 6779c94dde..583b432e3d 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -62,6 +62,46 @@ class TestEnv < Test::Unit::TestCase } end + def test_dup + assert_raise(TypeError) { + ENV.dup + } + end + + def test_clone + warning = /ENV\.clone is deprecated; use ENV\.to_h instead/ + clone = assert_deprecated_warning(warning) { + ENV.clone + } + assert_same(ENV, clone) + + clone = assert_deprecated_warning(warning) { + ENV.clone(freeze: false) + } + assert_same(ENV, clone) + + clone = assert_deprecated_warning(warning) { + ENV.clone(freeze: nil) + } + assert_same(ENV, clone) + + assert_raise(TypeError) { + ENV.clone(freeze: true) + } + assert_raise(ArgumentError) { + ENV.clone(freeze: 1) + } + assert_raise(ArgumentError) { + ENV.clone(foo: false) + } + assert_raise(ArgumentError) { + ENV.clone(1) + } + assert_raise(ArgumentError) { + ENV.clone(1, foo: false) + } + end + def test_has_value val = 'a' val.succ! while ENV.has_value?(val) || ENV.has_value?(val.upcase) |