Skip to content

Commit 49d0399

Browse files
committed
[GR-14806] Update specs
PullRequest: truffleruby/4225
2 parents 5f59b7b + bc599c2 commit 49d0399

File tree

248 files changed

+1207
-763
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+1207
-763
lines changed

lib/cext/ABI_check.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16
1+
17

lib/truffle/truffle/cext.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,10 @@ def rb_class_real(ruby_class)
603603
ruby_class
604604
end
605605

606+
def rb_class_get_superclass(ruby_class)
607+
ruby_class.superclass || false
608+
end
609+
606610
def rb_obj_respond_to(object, name, priv)
607611
object.respond_to?(name, priv != 0)
608612
end

spec/mspec/lib/mspec/helpers/tmp.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
end
1313
SPEC_TEMP_DIR = spec_temp_dir
1414

15-
SPEC_TEMP_UNIQUIFIER = "0"
15+
SPEC_TEMP_UNIQUIFIER = +"0"
1616

1717
at_exit do
1818
begin
@@ -41,6 +41,7 @@ def tmp(name, uniquify = true)
4141
if uniquify and !name.empty?
4242
slash = name.rindex "/"
4343
index = slash ? slash + 1 : 0
44+
name = +name
4445
name.insert index, "#{SPEC_TEMP_UNIQUIFIER.succ!}-"
4546
end
4647

spec/mspec/lib/mspec/mocks/mock.rb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@ def self.stubs
1818
@stubs ||= Hash.new { |h,k| h[k] = [] }
1919
end
2020

21-
def self.replaced_name(obj, sym)
22-
:"__mspec_#{obj.__id__}_#{sym}__"
21+
def self.replaced_name(key)
22+
:"__mspec_#{key.last}__"
2323
end
2424

2525
def self.replaced_key(obj, sym)
26-
[replaced_name(obj, sym), sym]
26+
[obj.__id__, sym]
2727
end
2828

29-
def self.has_key?(keys, sym)
30-
!!keys.find { |k| k.first == sym }
31-
end
32-
33-
def self.replaced?(sym)
34-
has_key?(mocks.keys, sym) or has_key?(stubs.keys, sym)
29+
def self.replaced?(key)
30+
mocks.include?(key) or stubs.include?(key)
3531
end
3632

3733
def self.clear_replaced(key)
@@ -40,8 +36,9 @@ def self.clear_replaced(key)
4036
end
4137

4238
def self.mock_respond_to?(obj, sym, include_private = false)
43-
name = replaced_name(obj, :respond_to?)
44-
if replaced? name
39+
key = replaced_key(obj, :respond_to?)
40+
if replaced? key
41+
name = replaced_name(key)
4542
obj.__send__ name, sym, include_private
4643
else
4744
obj.respond_to? sym, include_private
@@ -59,8 +56,8 @@ def self.install_method(obj, sym, type = nil)
5956
return
6057
end
6158

62-
if (sym == :respond_to? or mock_respond_to?(obj, sym, true)) and !replaced?(key.first)
63-
meta.__send__ :alias_method, key.first, sym
59+
if (sym == :respond_to? or mock_respond_to?(obj, sym, true)) and !replaced?(key)
60+
meta.__send__ :alias_method, replaced_name(key), sym
6461
end
6562

6663
suppress_warning {
@@ -191,7 +188,7 @@ def self.cleanup
191188
next
192189
end
193190

194-
replaced = key.first
191+
replaced = replaced_name(key)
195192
sym = key.last
196193
meta = obj.singleton_class
197194

spec/mspec/spec/mocks/mock_spec.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
RSpec.describe Mock, ".replaced_name" do
2323
it "returns the name for a method that is being replaced by a mock method" do
2424
m = double('a fake id')
25-
expect(Mock.replaced_name(m, :method_call)).to eq(:"__mspec_#{m.object_id}_method_call__")
25+
expect(Mock.replaced_name(Mock.replaced_key(m, :method_call))).to eq(:"__mspec_method_call__")
2626
end
2727
end
2828

2929
RSpec.describe Mock, ".replaced_key" do
3030
it "returns a key used internally by Mock" do
3131
m = double('a fake id')
32-
expect(Mock.replaced_key(m, :method_call)).to eq([:"__mspec_#{m.object_id}_method_call__", :method_call])
32+
expect(Mock.replaced_key(m, :method_call)).to eq([m.object_id, :method_call])
3333
end
3434
end
3535

@@ -42,16 +42,16 @@
4242

4343
it "returns true if a method has been stubbed on an object" do
4444
Mock.install_method @mock, :method_call
45-
expect(Mock.replaced?(Mock.replaced_name(@mock, :method_call))).to be_truthy
45+
expect(Mock.replaced?(Mock.replaced_key(@mock, :method_call))).to be_truthy
4646
end
4747

4848
it "returns true if a method has been mocked on an object" do
4949
Mock.install_method @mock, :method_call, :stub
50-
expect(Mock.replaced?(Mock.replaced_name(@mock, :method_call))).to be_truthy
50+
expect(Mock.replaced?(Mock.replaced_key(@mock, :method_call))).to be_truthy
5151
end
5252

5353
it "returns false if a method has not been stubbed or mocked" do
54-
expect(Mock.replaced?(Mock.replaced_name(@mock, :method_call))).to be_falsey
54+
expect(Mock.replaced?(Mock.replaced_key(@mock, :method_call))).to be_falsey
5555
end
5656
end
5757

@@ -197,11 +197,11 @@
197197

198198
Mock.install_method @mock, :method_call
199199
expect(@mock).to respond_to(:method_call)
200-
expect(@mock).not_to respond_to(Mock.replaced_name(@mock, :method_call))
200+
expect(@mock).not_to respond_to(Mock.replaced_name(Mock.replaced_key(@mock, :method_call)))
201201

202202
Mock.install_method @mock, :method_call, :stub
203203
expect(@mock).to respond_to(:method_call)
204-
expect(@mock).not_to respond_to(Mock.replaced_name(@mock, :method_call))
204+
expect(@mock).not_to respond_to(Mock.replaced_name(Mock.replaced_key(@mock, :method_call)))
205205
end
206206
end
207207

@@ -493,7 +493,7 @@ class MockAndRaiseError < Exception; end
493493
it "removes the replaced method if the mock method overrides an existing method" do
494494
def @mock.already_here() :hey end
495495
expect(@mock).to respond_to(:already_here)
496-
replaced_name = Mock.replaced_name(@mock, :already_here)
496+
replaced_name = Mock.replaced_name(Mock.replaced_key(@mock, :already_here))
497497
Mock.install_method @mock, :already_here
498498
expect(@mock).to respond_to(replaced_name)
499499

@@ -521,10 +521,9 @@ def @mock.already_here() :hey end
521521
replaced_key = Mock.replaced_key(@mock, :method_call)
522522
expect(Mock).to receive(:clear_replaced).with(replaced_key)
523523

524-
replaced_name = Mock.replaced_name(@mock, :method_call)
525-
expect(Mock.replaced?(replaced_name)).to be_truthy
524+
expect(Mock.replaced?(replaced_key)).to be_truthy
526525

527526
Mock.cleanup
528-
expect(Mock.replaced?(replaced_name)).to be_falsey
527+
expect(Mock.replaced?(replaced_key)).to be_falsey
529528
end
530529
end

spec/ruby/command_line/dash_v_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
describe "when used alone" do
88
it "prints version and ends" do
9-
ruby_exe(nil, args: '-v').should include(RUBY_DESCRIPTION)
9+
ruby_exe(nil, args: '-v').sub("+PRISM ", "").should include(RUBY_DESCRIPTION.sub("+PRISM ", ""))
1010
end unless (defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?) ||
1111
(defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?) ||
1212
(ENV['RUBY_MN_THREADS'] == '1')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
frozen = "test".frozen?
3+
interned = "test".equal?("test")
4+
puts "frozen:#{frozen} interned:#{interned}"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: false
2+
frozen = "test".frozen?
3+
interned = "test".equal?("test")
4+
puts "frozen:#{frozen} interned:#{interned}"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
frozen = "test".frozen?
2+
interned = "test".equal?("test")
3+
puts "frozen:#{frozen} interned:#{interned}"

spec/ruby/command_line/frozen_strings_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,50 @@
1919
end
2020
end
2121

22+
describe "The --disable-frozen-string-literal flag causes string literals to" do
23+
24+
it "produce a different object each time" do
25+
ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb"), options: "--disable-frozen-string-literal").chomp.should == "false"
26+
end
27+
28+
end
29+
30+
describe "With neither --enable-frozen-string-literal nor --disable-frozen-string-literal flag set" do
31+
before do
32+
# disable --enable-frozen-string-literal and --disable-frozen-string-literal passed in $RUBYOPT
33+
@rubyopt = ENV["RUBYOPT"]
34+
ENV["RUBYOPT"] = ""
35+
end
36+
37+
after do
38+
ENV["RUBYOPT"] = @rubyopt
39+
end
40+
41+
it "produce a different object each time" do
42+
ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb")).chomp.should == "false"
43+
end
44+
45+
ruby_version_is "3.4" do
46+
it "if file has no frozen_string_literal comment produce different frozen strings each time" do
47+
ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:true interned:false"
48+
end
49+
end
50+
51+
ruby_version_is ""..."3.4" do
52+
it "if file has no frozen_string_literal comment produce different mutable strings each time" do
53+
ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
54+
end
55+
end
56+
57+
it "if file has frozen_string_literal:true comment produce same frozen strings each time" do
58+
ruby_exe(fixture(__FILE__, "string_literal_frozen_comment.rb")).chomp.should == "frozen:true interned:true"
59+
end
60+
61+
it "if file has frozen_string_literal:false comment produce different mutable strings each time" do
62+
ruby_exe(fixture(__FILE__, "string_literal_mutable_comment.rb")).chomp.should == "frozen:false interned:false"
63+
end
64+
end
65+
2266
describe "The --debug flag produces" do
2367
it "debugging info on attempted frozen string modification" do
2468
error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--debug', args: "2>&1")

0 commit comments

Comments
 (0)