Skip to content

Commit 79b5c20

Browse files
committed
[GR-20446] Fix recently imported specs
PullRequest: truffleruby/4309
2 parents ceac0cf + 0d4e18f commit 79b5c20

23 files changed

+122
-78
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ Compatibility:
3535
* Joni has been updated from 2.1.44 to 2.2.1 (@andrykonchin).
3636
* Fix `Hash#to_h` called with a block and pass key and value to the block as separate arguments (#3607, @andrykonchin).
3737
* Fix `StringIO#initialize` and preserve initial string's encoding when mode is `w` so the initial string is truncated (#3599, @andrykonchin).
38+
* Fix `IO#{autoclose=,autoclose?}` and raise `IOError` when io is closed (@andrykonchin).
39+
* Fix `Thread#{thread_variable_get,thread_variable_set,thread_variable?,key?,[],[]=,fetch}` and convert a non-String/Symbol thread-local variable name to String using `#to_str` (@andrykonchin).
40+
* Fix formatting in `Exception#full_message` when `RuntimeError` is not handled and `highlight` option is specified (@andrykonchin).
41+
* Fix `String#encode` and convert fallback values into String using `#to_str` (@andrykonchin).
42+
* Fix `Kernel.warn` and don't call `Warning#warn` if a specified category is disabled (@andrykonchin).
3843

3944
Performance:
4045

spec/ruby/core/exception/full_message_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@
7979
err.full_message(highlight: true).should !~ /unhandled exception/
8080
err.full_message(highlight: false).should !~ /unhandled exception/
8181
end
82+
83+
it "adds escape sequences to highlight some strings if the message is not specified and :highlight option is specified" do
84+
e = RuntimeError.new("")
85+
86+
full_message = e.full_message(highlight: true, order: :top).lines
87+
full_message[0].should.end_with? "\e[1;4munhandled exception\e[m\n"
88+
89+
full_message = e.full_message(highlight: true, order: :bottom).lines
90+
full_message[0].should == "\e[1mTraceback\e[m (most recent call last):\n"
91+
full_message[-1].should.end_with? "\e[1;4munhandled exception\e[m\n"
92+
93+
full_message = e.full_message(highlight: false, order: :top).lines
94+
full_message[0].should.end_with? "unhandled exception\n"
95+
96+
full_message = e.full_message(highlight: false, order: :bottom).lines
97+
full_message[0].should == "Traceback (most recent call last):\n"
98+
full_message[-1].should.end_with? "unhandled exception\n"
99+
end
82100
end
83101

84102
describe "generic Error" do

spec/ruby/core/thread/element_reference_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@
3737
t2["value"].should == 2
3838
end
3939

40+
it "converts a key that is neither String nor Symbol with #to_str" do
41+
key = mock('value')
42+
key.should_receive(:to_str).and_return('value')
43+
44+
th = Thread.new do
45+
Thread.current[:value] = 1
46+
end.join
47+
48+
th[key].should == 1
49+
end
50+
4051
it "raises exceptions on the wrong type of keys" do
4152
-> { Thread.current[nil] }.should raise_error(TypeError)
4253
-> { Thread.current[5] }.should raise_error(TypeError)

spec/ruby/core/thread/element_set_spec.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,33 @@
1212
th.freeze
1313
-> {
1414
th[:foo] = "bar"
15-
}.should raise_error(FrozenError, /frozen/)
15+
}.should raise_error(FrozenError, "can't modify frozen thread locals")
1616
end.join
1717
end
1818

19+
it "accepts Strings and Symbols" do
20+
t1 = Thread.new do
21+
Thread.current[:value] = 1
22+
end.join
23+
t2 = Thread.new do
24+
Thread.current["value"] = 2
25+
end.join
26+
27+
t1[:value].should == 1
28+
t2[:value].should == 2
29+
end
30+
31+
it "converts a key that is neither String nor Symbol with #to_str" do
32+
key = mock('value')
33+
key.should_receive(:to_str).and_return('value')
34+
35+
th = Thread.new do
36+
Thread.current[key] = 1
37+
end.join
38+
39+
th[:value].should == 1
40+
end
41+
1942
it "raises exceptions on the wrong type of keys" do
2043
-> { Thread.current[nil] = true }.should raise_error(TypeError)
2144
-> { Thread.current[5] = true }.should raise_error(TypeError)

spec/ruby/core/thread/key_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
@th.key?(:stanley.to_s).should == false
1717
end
1818

19+
it "converts a key that is neither String nor Symbol with #to_str" do
20+
key = mock('key')
21+
key.should_receive(:to_str).and_return('oliver')
22+
23+
@th.key?(key).should == true
24+
end
25+
1926
it "raises exceptions on the wrong type of keys" do
2027
-> { Thread.current.key? nil }.should raise_error(TypeError)
2128
-> { Thread.current.key? 5 }.should raise_error(TypeError)

spec/ruby/core/thread/thread_variable_get_spec.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@
4141
@t.thread_variable_get(:a).should be_nil
4242
end
4343

44-
it "does not raise a TypeError if the key is neither Symbol nor String, nor responds to #to_str" do
45-
@t.thread_variable_get(123).should be_nil
46-
end
47-
48-
it "does not try to convert the key with #to_sym" do
49-
key = mock('key')
50-
key.should_not_receive(:to_sym)
51-
@t.thread_variable_get(key).should be_nil
44+
ruby_bug "#20606", ""..."3.4" do
45+
it "raises a TypeError if the key is neither Symbol nor String, nor responds to #to_str" do
46+
-> { @t.thread_variable_get(123) }.should raise_error(TypeError, /123 is not a symbol/)
47+
end
48+
49+
it "does not try to convert the key with #to_sym" do
50+
key = mock('key')
51+
key.should_not_receive(:to_sym)
52+
-> { @t.thread_variable_get(key) }.should raise_error(TypeError)
53+
end
5254
end
5355
end

spec/ruby/core/thread/thread_variable_set_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@
5151
end
5252

5353
it "raises a TypeError if the key is neither Symbol nor String, nor responds to #to_str" do
54-
-> { @t.thread_variable_set(123, 1) }.should raise_error(TypeError, '123 is not a symbol')
54+
-> { @t.thread_variable_set(123, 1) }.should raise_error(TypeError, /123 is not a symbol/)
5555
end
5656

5757
it "does not try to convert the key with #to_sym" do
5858
key = mock('key')
5959
key.should_not_receive(:to_sym)
60-
-> { @t.thread_variable_set(key, 42) }.should raise_error(TypeError, "#{key.inspect} is not a symbol")
60+
-> { @t.thread_variable_set(key, 42) }.should raise_error(TypeError, /#{key.inspect} is not a symbol/)
6161
end
6262
end

spec/ruby/core/thread/thread_variable_spec.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@
4141
@t.thread_variable?(:a).should be_false
4242
end
4343

44-
it "does not raise a TypeError if the key is neither Symbol nor String, nor responds to #to_str" do
45-
@t.thread_variable?(123).should be_false
46-
end
47-
48-
it "does not try to convert the key with #to_sym" do
49-
key = mock('key')
50-
key.should_not_receive(:to_sym)
51-
@t.thread_variable?(key).should be_false
44+
ruby_bug "#20606", ""..."3.4" do
45+
it "raises a TypeError if the key is neither Symbol nor String, nor responds to #to_str" do
46+
-> { @t.thread_variable?(123) }.should raise_error(TypeError, /123 is not a symbol/)
47+
end
48+
49+
it "does not try to convert the key with #to_sym" do
50+
key = mock('key')
51+
key.should_not_receive(:to_sym)
52+
-> { @t.thread_variable?(key) }.should raise_error(TypeError)
53+
end
5254
end
5355
end

spec/ruby/core/warning/warn_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def Warning.warn(msg)
121121
end
122122
end
123123

124-
ruby_bug '#19530', ''...'3.4' do
124+
ruby_bug '#20573', ''...'3.4' do
125125
it "isn't called by Kernel.warn when category is :deprecated but Warning[:deprecated] is false" do
126126
warn_deprecated = Warning[:deprecated]
127127
begin

spec/tags/core/exception/detailed_message_tags.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)