Skip to content

Commit 82d3a4a

Browse files
committed
[GR-14806] Update specs
PullRequest: truffleruby/3932
2 parents 1c80de9 + fd29c20 commit 82d3a4a

Some content is hidden

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

51 files changed

+378
-176
lines changed

doc/contributor/workflow.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ When working on a feature from the next version of Ruby, add the spec file in
322322
the corresponding files list in `spec/truffleruby.next-specs` so that the specs
323323
are run in CI too.
324324

325+
However this does not work for C-API specs,
326+
because those use `#ifdef RUBY_VERSION_IS_3_2` and that version cannot be faked.
327+
325328
## How to fix a failing MRI test
326329

327330
Remove the exclusion of either the file (`test/mri/failing.exclude`) or the

lib/truffle/stringio.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def syswrite(str)
107107

108108
class StringIO
109109

110+
VERSION = '3.0.1' # Same version as the default gem in CRuby 3.1.3
111+
110112
include Enumerable
111113
include Truffle::CExt.rb_define_module_under(IO, 'generic_readable')
112114
include Truffle::CExt.rb_define_module_under(IO, 'generic_writable')

spec/ruby/command_line/dash_upper_u_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
options: '-U').should == 'UTF-8'
77
end
88

9+
it "sets Encoding.default_internal to UTF-8 when RUBYOPT is empty or only spaces" do
10+
ruby_exe('p Encoding.default_internal',
11+
options: '-U', env: { 'RUBYOPT' => '' }).should == "#<Encoding:UTF-8>\n"
12+
ruby_exe('p Encoding.default_internal',
13+
options: '-U', env: { 'RUBYOPT' => ' ' }).should == "#<Encoding:UTF-8>\n"
14+
end
15+
916
it "does nothing different if specified multiple times" do
1017
ruby_exe('print Encoding.default_internal.name',
1118
options: '-U -U').should == 'UTF-8'

spec/ruby/core/basicobject/instance_eval_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ def foo
8484

8585
end
8686

87+
ruby_version_is "3.3" do
88+
it "uses the caller location as default location" do
89+
f = Object.new
90+
f.instance_eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1]
91+
end
92+
end
93+
8794
it "has access to receiver's instance variables" do
8895
BasicObjectSpecs::IVars.new.instance_eval { @secret }.should == 99
8996
BasicObjectSpecs::IVars.new.instance_eval("@secret").should == 99

spec/ruby/core/binding/eval_spec.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@
6060
bind.eval("#foo\n__LINE__", "(test)", 88).should == 89
6161
end
6262

63-
it "uses (eval) as __FILE__ if single argument given" do
64-
obj = BindingSpecs::Demo.new(1)
65-
bind = obj.get_binding
66-
bind.eval("__FILE__").should == '(eval)'
63+
ruby_version_is ""..."3.3" do
64+
it "uses (eval) as __FILE__ if single argument given" do
65+
obj = BindingSpecs::Demo.new(1)
66+
bind = obj.get_binding
67+
bind.eval("__FILE__").should == '(eval)'
68+
end
6769
end
6870

6971
it "uses 1 as __LINE__" do
@@ -104,4 +106,10 @@
104106

105107
bind.eval("'bar'.foo").should == "foo"
106108
end
109+
110+
ruby_version_is "3.3" do
111+
it "uses the caller location as default filename" do
112+
binding.eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1]
113+
end
114+
end
107115
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "FalseClass#singleton_method" do
4+
ruby_version_is '3.3' do
5+
it "raises regardless of whether FalseClass defines the method" do
6+
-> { false.singleton_method(:foo) }.should raise_error(NameError)
7+
begin
8+
def (false).foo; end
9+
-> { false.singleton_method(:foo) }.should raise_error(NameError)
10+
ensure
11+
FalseClass.send(:remove_method, :foo)
12+
end
13+
end
14+
end
15+
end

spec/ruby/core/kernel/eval_spec.rb

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,37 @@ class Object
159159
end
160160
end
161161

162-
it "uses (eval) filename if none is provided" do
163-
eval("__FILE__").should == "(eval)"
164-
eval("__FILE__", binding).should == "(eval)"
165-
eval("__FILE__", binding, "success").should == "success"
166-
eval("eval '__FILE__', binding").should == "(eval)"
167-
eval("eval '__FILE__', binding", binding).should == "(eval)"
168-
eval("eval '__FILE__', binding", binding, 'success').should == '(eval)'
169-
eval("eval '__FILE__', binding, 'success'", binding).should == 'success'
170-
end
162+
ruby_version_is ""..."3.3" do
163+
it "uses (eval) filename if none is provided" do
164+
eval("__FILE__").should == "(eval)"
165+
eval("__FILE__", binding).should == "(eval)"
166+
eval("__FILE__", binding, "success").should == "success"
167+
eval("eval '__FILE__', binding").should == "(eval)"
168+
eval("eval '__FILE__', binding", binding).should == "(eval)"
169+
eval("eval '__FILE__', binding", binding, 'success').should == '(eval)'
170+
eval("eval '__FILE__', binding, 'success'", binding).should == 'success'
171+
end
171172

172-
it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do
173-
eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1]
173+
it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do
174+
eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1]
175+
end
174176
end
175177

178+
ruby_version_is "3.3" do
179+
it "uses (eval at __FILE__:__LINE__) if none is provided" do
180+
eval("__FILE__").should == "(eval at #{__FILE__}:#{__LINE__})"
181+
eval("__FILE__", binding).should == "(eval at #{__FILE__}:#{__LINE__})"
182+
eval("__FILE__", binding, "success").should == "success"
183+
eval("eval '__FILE__', binding").should == "(eval at (eval at #{__FILE__}:#{__LINE__}):1)"
184+
eval("eval '__FILE__', binding", binding).should == "(eval at (eval at #{__FILE__}:#{__LINE__}):1)"
185+
eval("eval '__FILE__', binding", binding, 'success').should == "(eval at success:1)"
186+
eval("eval '__FILE__', binding, 'success'", binding).should == 'success'
187+
end
188+
189+
it 'uses (eval at __FILE__:__LINE__) for __FILE__ and 1 for __LINE__ with a binding argument' do
190+
eval("[__FILE__, __LINE__]", binding).should == ["(eval at #{__FILE__}:#{__LINE__})", 1]
191+
end
192+
end
176193
# Found via Rubinius bug github:#149
177194
it "does not alter the value of __FILE__ in the binding" do
178195
first_time = EvalSpecs.call_eval
@@ -209,6 +226,20 @@ class Object
209226
-> { eval("return :eval") }.call.should == :eval
210227
end
211228

229+
it "returns from the method calling #eval when evaluating 'return'" do
230+
def eval_return(n)
231+
eval("return n*2")
232+
end
233+
-> { eval_return(3) }.call.should == 6
234+
end
235+
236+
it "returns from the method calling #eval when evaluating 'return' in BEGIN" do
237+
def eval_return(n)
238+
eval("BEGIN {return n*3}")
239+
end
240+
-> { eval_return(4) }.call.should == 12
241+
end
242+
212243
it "unwinds through a Proc-style closure and returns from a lambda-style closure in the closure chain" do
213244
code = fixture __FILE__, "eval_return_with_lambda.rb"
214245
ruby_exe(code).chomp.should == "a,b,c,eval,f"

spec/ruby/core/module/const_get_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
-> { ConstantSpecs.const_get("CS_CONST1", false) }.should raise_error(NameError)
106106
end
107107

108-
it "returns a constant whose module is defined the the toplevel" do
108+
it "returns a constant whose module is defined the toplevel" do
109109
ConstantSpecs.const_get("ConstantSpecsTwo::Foo").should == :cs_two_foo
110110
ConstantSpecsThree.const_get("ConstantSpecsTwo::Foo").should == :cs_three_foo
111111
end

spec/ruby/core/module/name_spec.rb

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,6 @@
66
Module.new.name.should be_nil
77
end
88

9-
ruby_version_is "3.3" do
10-
it "can assign a temporary name" do
11-
m = Module.new
12-
m.name.should be_nil
13-
14-
m.set_temporary_name("fake_name")
15-
m.name.should == "fake_name"
16-
17-
m.set_temporary_name(nil)
18-
m.name.should be_nil
19-
end
20-
21-
it "can't assign empty string as name" do
22-
m = Module.new
23-
-> { m.set_temporary_name("") }.should raise_error(ArgumentError, "empty class/module name")
24-
end
25-
26-
it "can't assign a constant name as a temporary name" do
27-
m = Module.new
28-
-> { m.set_temporary_name("Object") }.should raise_error(ArgumentError, "name must not be valid constant name")
29-
end
30-
31-
it "can't assign name to permanent module" do
32-
-> { Object.set_temporary_name("fake_name") }.should raise_error(RuntimeError, "can't change permanent name")
33-
end
34-
35-
it "can assign a temporary name to a nested module" do
36-
m = Module.new
37-
module m::N; end
38-
m::N.name.should =~ /\A#<Module:0x\h+>::N\z/
39-
40-
m::N.set_temporary_name("fake_name")
41-
m::N.name.should == "fake_name"
42-
43-
m::N.set_temporary_name(nil)
44-
m::N.name.should be_nil
45-
end
46-
47-
it "can update the name when assigned to a constant" do
48-
m = Module.new
49-
m::N = Module.new
50-
m::N.name.should =~ /\A#<Module:0x\h+>::N\z/
51-
m::N.set_temporary_name(nil)
52-
53-
m::M = m::N
54-
m::M.name.should =~ /\A#<Module:0x\h+>::M\z/m
55-
end
56-
end
57-
589
it "is not nil when assigned to a constant in an anonymous module" do
5910
m = Module.new
6011
m::N = Module.new
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
require_relative '../../spec_helper'
2+
3+
ruby_version_is "3.3" do
4+
describe "Module#set_temporary_name" do
5+
it "can assign a temporary name" do
6+
m = Module.new
7+
m.name.should be_nil
8+
9+
m.set_temporary_name("fake_name")
10+
m.name.should == "fake_name"
11+
12+
m.set_temporary_name(nil)
13+
m.name.should be_nil
14+
end
15+
16+
it "can assign a temporary name which is not a valid constant path" do
17+
m = Module.new
18+
m.set_temporary_name("a::B")
19+
m.name.should == "a::B"
20+
21+
m.set_temporary_name("Template['foo.rb']")
22+
m.name.should == "Template['foo.rb']"
23+
end
24+
25+
it "can't assign empty string as name" do
26+
m = Module.new
27+
-> { m.set_temporary_name("") }.should raise_error(ArgumentError, "empty class/module name")
28+
end
29+
30+
it "can't assign a constant name as a temporary name" do
31+
m = Module.new
32+
-> { m.set_temporary_name("Object") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion")
33+
end
34+
35+
it "can't assign a constant path as a temporary name" do
36+
m = Module.new
37+
-> { m.set_temporary_name("A::B") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion")
38+
-> { m.set_temporary_name("::A") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion")
39+
-> { m.set_temporary_name("::A::B") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion")
40+
end
41+
42+
it "can't assign name to permanent module" do
43+
-> { Object.set_temporary_name("fake_name") }.should raise_error(RuntimeError, "can't change permanent name")
44+
end
45+
46+
it "can assign a temporary name to a nested module" do
47+
m = Module.new
48+
module m::N; end
49+
m::N.name.should =~ /\A#<Module:0x\h+>::N\z/
50+
51+
m::N.set_temporary_name("fake_name")
52+
m::N.name.should == "fake_name"
53+
54+
m::N.set_temporary_name(nil)
55+
m::N.name.should be_nil
56+
end
57+
58+
it "can update the name when assigned to a constant" do
59+
m = Module.new
60+
m::N = Module.new
61+
m::N.name.should =~ /\A#<Module:0x\h+>::N\z/
62+
m::N.set_temporary_name(nil)
63+
64+
m::M = m::N
65+
m::M.name.should =~ /\A#<Module:0x\h+>::M\z/m
66+
end
67+
end
68+
end

0 commit comments

Comments
 (0)