summaryrefslogtreecommitdiff
path: root/test/ruby/test_env.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_env.rb')
-rw-r--r--test/ruby/test_env.rb60
1 files changed, 16 insertions, 44 deletions
diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb
index 87ccd5102b..4b5f18e7bb 100644
--- a/test/ruby/test_env.rb
+++ b/test/ruby/test_env.rb
@@ -69,25 +69,20 @@ class TestEnv < Test::Unit::TestCase
end
def test_clone
- warning = /ENV\.clone is deprecated; use ENV\.to_h instead/
- clone = assert_deprecated_warning(warning) {
+ message = /Cannot clone ENV/
+ assert_raise_with_message(TypeError, message) {
ENV.clone
}
- assert_same(ENV, clone)
-
- clone = assert_deprecated_warning(warning) {
+ assert_raise_with_message(TypeError, message) {
ENV.clone(freeze: false)
}
- assert_same(ENV, clone)
-
- clone = assert_deprecated_warning(warning) {
+ assert_raise_with_message(TypeError, message) {
ENV.clone(freeze: nil)
}
- assert_same(ENV, clone)
-
- assert_raise(TypeError) {
+ assert_raise_with_message(TypeError, message) {
ENV.clone(freeze: true)
}
+
assert_raise(ArgumentError) {
ENV.clone(freeze: 1)
}
@@ -494,12 +489,20 @@ class TestEnv < Test::Unit::TestCase
ENV["baz"] = "qux"
ENV.update({"baz"=>"quux","a"=>"b"})
check(ENV.to_hash.to_a, [%w(foo bar), %w(baz quux), %w(a b)])
+ ENV.update
+ check(ENV.to_hash.to_a, [%w(foo bar), %w(baz quux), %w(a b)])
+ ENV.update({"foo"=>"zot"}, {"c"=>"d"})
+ check(ENV.to_hash.to_a, [%w(foo zot), %w(baz quux), %w(a b), %w(c d)])
ENV.clear
ENV["foo"] = "bar"
ENV["baz"] = "qux"
ENV.update({"baz"=>"quux","a"=>"b"}) {|k, v1, v2| k + "_" + v1 + "_" + v2 }
check(ENV.to_hash.to_a, [%w(foo bar), %w(baz baz_qux_quux), %w(a b)])
+ ENV.update {|k, v1, v2| k + "_" + v1 + "_" + v2 }
+ check(ENV.to_hash.to_a, [%w(foo bar), %w(baz baz_qux_quux), %w(a b)])
+ ENV.update({"foo"=>"zot"}, {"c"=>"d"}) {|k, v1, v2| k + "_" + v1 + "_" + v2 }
+ check(ENV.to_hash.to_a, [%w(foo foo_bar_zot), %w(baz baz_qux_quux), %w(a b), %w(c d)])
end
def test_huge_value
@@ -609,8 +612,8 @@ class TestEnv < Test::Unit::TestCase
<<-"end;"
envvars_to_check = [
"foo\0bar",
- "#{'\xa1\xa1'}".force_encoding(Encoding::UTF_16LE),
- "foo".force_encoding(Encoding::ISO_2022_JP),
+ "#{'\xa1\xa1'}".dup.force_encoding(Encoding::UTF_16LE),
+ "foo".dup.force_encoding(Encoding::ISO_2022_JP),
]
envvars_to_check.each do |#{var_name}|
#{str_for_yielding_exception_class(code_str)}
@@ -680,37 +683,6 @@ class TestEnv < Test::Unit::TestCase
end;
end
- def test_clone_in_ractor
- assert_ractor(<<-"end;")
- r = Ractor.new do
- original_warning_state = Warning[:deprecated]
- Warning[:deprecated] = false
-
- begin
- Ractor.yield ENV.clone.object_id
- Ractor.yield ENV.clone(freeze: false).object_id
- Ractor.yield ENV.clone(freeze: nil).object_id
-
- #{str_for_yielding_exception_class("ENV.clone(freeze: true)")}
- #{str_for_yielding_exception_class("ENV.clone(freeze: 1)")}
- #{str_for_yielding_exception_class("ENV.clone(foo: false)")}
- #{str_for_yielding_exception_class("ENV.clone(1)")}
- #{str_for_yielding_exception_class("ENV.clone(1, foo: false)")}
-
- ensure
- Warning[:deprecated] = original_warning_state
- end
- end
- assert_equal(ENV.object_id, r.take)
- assert_equal(ENV.object_id, r.take)
- assert_equal(ENV.object_id, r.take)
- #{str_for_assert_raise_on_yielded_exception_class(TypeError, "r")}
- 4.times do
- #{str_for_assert_raise_on_yielded_exception_class(ArgumentError, "r")}
- end
- end;
- end
-
def test_has_value_in_ractor
assert_ractor(<<-"end;")
r = Ractor.new do