Skip to content

Commit 87c4ebd

Browse files
committed
Fix tests using assert_raise_with_message on US-ASCII systems
On systems where the Encoding.default_internal defaults to US-ASCII instead of UTF-8, some tests using assert_raise_with_message can fail since it no longer changes Encoding.default_internal in 79f5202. This tests explicitly uses EnvUtil.with_default_internal on systems where these tests fail.
1 parent db3d82b commit 87c4ebd

File tree

9 files changed

+60
-29
lines changed

9 files changed

+60
-29
lines changed

test/-ext-/symbol/test_type.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,20 @@ def test_attrset
123123

124124
def test_check_id_invalid_type
125125
cx = EnvUtil.labeled_class("X\u{1f431}")
126-
assert_raise_with_message(TypeError, /X\u{1F431}/) {
127-
Bug::Symbol.pinneddown?(cx)
128-
}
126+
EnvUtil.with_default_internal(Encoding::UTF_8) do
127+
assert_raise_with_message(TypeError, /X\u{1F431}/) {
128+
Bug::Symbol.pinneddown?(cx)
129+
}
130+
end
129131
end
130132

131133
def test_check_symbol_invalid_type
132134
cx = EnvUtil.labeled_class("X\u{1f431}")
133-
assert_raise_with_message(TypeError, /X\u{1F431}/) {
134-
Bug::Symbol.find(cx)
135-
}
135+
EnvUtil.with_default_internal(Encoding::UTF_8) do
136+
assert_raise_with_message(TypeError, /X\u{1F431}/) {
137+
Bug::Symbol.find(cx)
138+
}
139+
end
136140
end
137141

138142
def test_const_name_type

test/ruby/test_class.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,11 @@ def xyzzy
696696
def test_namescope_error_message
697697
m = Module.new
698698
o = m.module_eval "class A\u{3042}; self; end.new"
699-
assert_raise_with_message(TypeError, /A\u{3042}/) {
700-
o::Foo
701-
}
699+
EnvUtil.with_default_internal(Encoding::UTF_8) do
700+
assert_raise_with_message(TypeError, /A\u{3042}/) {
701+
o::Foo
702+
}
703+
end
702704
end
703705

704706
def test_redefinition_mismatch

test/ruby/test_float.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,9 @@ def o.to_f; inf = Float::INFINITY; inf/inf; end
861861
assert_raise(Encoding::CompatibilityError) {Float("0".encode("utf-32le"))}
862862
assert_raise(Encoding::CompatibilityError) {Float("0".encode("iso-2022-jp"))}
863863

864-
assert_raise_with_message(ArgumentError, /\u{1f4a1}/) {Float("\u{1f4a1}")}
864+
EnvUtil.with_default_internal(Encoding::UTF_8) do
865+
assert_raise_with_message(ArgumentError, /\u{1f4a1}/) {Float("\u{1f4a1}")}
866+
end
865867
end
866868

867869
def test_invalid_str

test/ruby/test_integer.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ def obj.to_i; "str"; end
158158
assert_raise(Encoding::CompatibilityError, bug6192) {Integer("0".encode("utf-32le"))}
159159
assert_raise(Encoding::CompatibilityError, bug6192) {Integer("0".encode("iso-2022-jp"))}
160160

161-
assert_raise_with_message(ArgumentError, /\u{1f4a1}/) {Integer("\u{1f4a1}")}
161+
EnvUtil.with_default_internal(Encoding::UTF_8) do
162+
assert_raise_with_message(ArgumentError, /\u{1f4a1}/) {Integer("\u{1f4a1}")}
163+
end
162164

163165
obj = Struct.new(:s).new(%w[42 not-an-integer])
164166
def obj.to_str; s.shift; end

test/ruby/test_method.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,10 @@ def o.bar; end
284284
assert_raise(TypeError) { m.bind(Object.new) }
285285

286286
cx = EnvUtil.labeled_class("X\u{1f431}")
287-
assert_raise_with_message(TypeError, /X\u{1f431}/) do
288-
o.method(cx)
287+
EnvUtil.with_default_internal(Encoding::UTF_8) do
288+
assert_raise_with_message(TypeError, /X\u{1f431}/) do
289+
o.method(cx)
290+
end
289291
end
290292
end
291293

@@ -315,9 +317,12 @@ def o.bar; :bar; end
315317
assert_raise(TypeError) do
316318
Class.new.class_eval { define_method(:bar, o.method(:bar)) }
317319
end
320+
318321
cx = EnvUtil.labeled_class("X\u{1f431}")
319-
assert_raise_with_message(TypeError, /X\u{1F431}/) do
320-
Class.new {define_method(cx) {}}
322+
EnvUtil.with_default_internal(Encoding::UTF_8) do
323+
assert_raise_with_message(TypeError, /X\u{1F431}/) do
324+
Class.new {define_method(cx) {}}
325+
end
321326
end
322327
end
323328

test/ruby/test_module.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,8 +1291,11 @@ def test_const_set_invalid_name
12911291
assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-16le"), :foo) }
12921292
assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-32be"), :foo) }
12931293
assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-32le"), :foo) }
1294+
12941295
cx = EnvUtil.labeled_class("X\u{3042}")
1295-
assert_raise_with_message(TypeError, /X\u{3042}/) { c1.const_set(cx, :foo) }
1296+
EnvUtil.with_default_internal(Encoding::UTF_8) do
1297+
assert_raise_with_message(TypeError, /X\u{3042}/) { c1.const_set(cx, :foo) }
1298+
end
12961299
end
12971300

12981301
def test_const_get_invalid_name

test/ruby/test_numeric.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,24 @@ def test_coerce
1818
assert_raise_with_message(TypeError, /can't be coerced into /) {1|:foo}
1919
assert_raise_with_message(TypeError, /can't be coerced into /) {1^:foo}
2020

21-
assert_raise_with_message(TypeError, /:\u{3042}/) {1+:"\u{3042}"}
22-
assert_raise_with_message(TypeError, /:\u{3042}/) {1&:"\u{3042}"}
23-
assert_raise_with_message(TypeError, /:\u{3042}/) {1|:"\u{3042}"}
24-
assert_raise_with_message(TypeError, /:\u{3042}/) {1^:"\u{3042}"}
21+
EnvUtil.with_default_internal(Encoding::UTF_8) do
22+
assert_raise_with_message(TypeError, /:\u{3042}/) {1+:"\u{3042}"}
23+
assert_raise_with_message(TypeError, /:\u{3042}/) {1&:"\u{3042}"}
24+
assert_raise_with_message(TypeError, /:\u{3042}/) {1|:"\u{3042}"}
25+
assert_raise_with_message(TypeError, /:\u{3042}/) {1^:"\u{3042}"}
26+
27+
assert_raise_with_message(TypeError, /:\u{3044}/) {1+"\u{3044}".to_sym}
28+
assert_raise_with_message(TypeError, /:\u{3044}/) {1&"\u{3044}".to_sym}
29+
assert_raise_with_message(TypeError, /:\u{3044}/) {1|"\u{3044}".to_sym}
30+
assert_raise_with_message(TypeError, /:\u{3044}/) {1^"\u{3044}".to_sym}
31+
end
32+
2533
EnvUtil.with_default_internal(Encoding::US_ASCII) do
2634
assert_raise_with_message(TypeError, /:"\\u3042"/) {1+:"\u{3042}"}
2735
assert_raise_with_message(TypeError, /:"\\u3042"/) {1&:"\u{3042}"}
2836
assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"}
2937
assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"}
3038
end
31-
assert_raise_with_message(TypeError, /:\u{3044}/) {1+"\u{3044}".to_sym}
32-
assert_raise_with_message(TypeError, /:\u{3044}/) {1&"\u{3044}".to_sym}
33-
assert_raise_with_message(TypeError, /:\u{3044}/) {1|"\u{3044}".to_sym}
34-
assert_raise_with_message(TypeError, /:\u{3044}/) {1^"\u{3044}".to_sym}
3539

3640
bug10711 = '[ruby-core:67405] [Bug #10711]'
3741
exp = "1.2 can't be coerced into Integer"

test/ruby/test_process.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,19 @@ def test_rlimit_name
114114
}
115115
assert_raise(ArgumentError) { Process.getrlimit(:FOO) }
116116
assert_raise(ArgumentError) { Process.getrlimit("FOO") }
117-
assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) { Process.getrlimit("\u{30eb 30d3 30fc}") }
117+
118+
EnvUtil.with_default_internal(Encoding::UTF_8) do
119+
assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) { Process.getrlimit("\u{30eb 30d3 30fc}") }
120+
end
118121
end
119122

120123
def test_rlimit_value
121124
return unless rlimit_exist?
122125
assert_raise(ArgumentError) { Process.setrlimit(:FOO, 0) }
123126
assert_raise(ArgumentError) { Process.setrlimit(:CORE, :FOO) }
124-
assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) { Process.setrlimit("\u{30eb 30d3 30fc}", 0) }
127+
EnvUtil.with_default_internal(Encoding::UTF_8) do
128+
assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) { Process.setrlimit("\u{30eb 30d3 30fc}", 0) }
129+
end
125130
assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) { Process.setrlimit(:CORE, "\u{30eb 30d3 30fc}") }
126131
with_tmpchdir do
127132
s = run_in_child(<<-'End')

test/ruby/test_rational.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,13 @@ def test_conv
117117
assert_equal(Rational(111, 1000), Rational('1.11e-1'))
118118
assert_raise(TypeError){Rational(nil)}
119119
assert_raise(ArgumentError){Rational('')}
120-
assert_raise_with_message(ArgumentError, /\u{221a 2668}/) {
121-
Rational("\u{221a 2668}")
122-
}
120+
121+
EnvUtil.with_default_internal(Encoding::UTF_8) do
122+
assert_raise_with_message(ArgumentError, /\u{221a 2668}/) {
123+
Rational("\u{221a 2668}")
124+
}
125+
end
126+
123127
assert_warning('') {
124128
assert_predicate(Rational('1e-99999999999999999999'), :zero?)
125129
}

0 commit comments

Comments
 (0)