Skip to content

Commit c051dff

Browse files
committed
[GR-14806] Update specs.
PullRequest: truffleruby/2025
2 parents 32e210e + 518d2d4 commit c051dff

File tree

199 files changed

+918
-543
lines changed

Some content is hidden

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

199 files changed

+918
-543
lines changed

spec/mspec/lib/mspec/utils/warnings.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
require 'mspec/guards/version'
22

3-
if RUBY_ENGINE == "ruby"
3+
# Always enable deprecation warnings when running MSpec, as ruby/spec tests for them,
4+
# and like in most test frameworks, all warnings should be enabled by default (same as -w).
5+
if Object.const_defined?(:Warning) and Warning.respond_to?(:[]=)
6+
Warning[:deprecated] = true
7+
end
8+
9+
if Object.const_defined?(:Warning) and Warning.respond_to?(:warn)
410
def Warning.warn(message)
511
# Suppress any warning inside the method to prevent recursion
612
verbose = $VERBOSE

spec/mspec/tool/sync/sync-rubyspec.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,16 @@ def rebase_commits(impl)
157157
end
158158
end
159159

160+
def new_commits?(impl)
161+
Dir.chdir(SOURCE_REPO) do
162+
diff = `git diff master #{impl.rebased_branch}`
163+
!diff.empty?
164+
end
165+
end
166+
160167
def test_new_specs
161168
require "yaml"
162169
Dir.chdir(SOURCE_REPO) do
163-
diff = `git diff master`
164-
abort "#{BRIGHT_YELLOW}No new commits, aborting#{RESET}" if diff.empty?
165-
166170
workflow = YAML.load_file(".github/workflows/ci.yml")
167171
job_name = MSPEC ? "test" : "specs"
168172
versions = workflow.dig("jobs", job_name, "strategy", "matrix", "ruby")
@@ -195,8 +199,8 @@ def verify_commits(impl)
195199
def fast_forward_master(impl)
196200
Dir.chdir(SOURCE_REPO) do
197201
sh "git", "checkout", "master"
198-
sh "git", "merge", "--ff-only", "#{impl.name}-rebased"
199-
sh "git", "branch", "--delete", "#{impl.name}-rebased"
202+
sh "git", "merge", "--ff-only", impl.rebased_branch
203+
sh "git", "branch", "--delete", impl.rebased_branch
200204
end
201205
end
202206

@@ -215,10 +219,15 @@ def main(impls)
215219
update_repo(impl)
216220
filter_commits(impl)
217221
rebase_commits(impl)
218-
test_new_specs
219-
verify_commits(impl)
220-
fast_forward_master(impl)
221-
check_ci
222+
if new_commits?(impl)
223+
test_new_specs
224+
verify_commits(impl)
225+
fast_forward_master(impl)
226+
check_ci
227+
else
228+
STDERR.puts "#{BRIGHT_YELLOW}No new commits#{RESET}"
229+
fast_forward_master(impl)
230+
end
222231
end
223232
end
224233

spec/ruby/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
The Ruby Spec Suite, abbreviated `ruby/spec`, is a test suite for the behavior of the Ruby programming language.
77

8+
### Description and Motivation
9+
810
It is not a standardized specification like the ISO one, and does not aim to become one.
911
Instead, it is a practical tool to describe and test the behavior of Ruby with code.
1012

@@ -30,20 +32,24 @@ ruby/spec is known to be tested in these implementations for every commit:
3032
ruby/spec describes the behavior of Ruby 2.5 and more recent Ruby versions.
3133
More precisely, every latest stable MRI release should [pass](https://travis-ci.org/ruby/spec) all specs of ruby/spec (2.5.x, 2.6.x, 2.7.x, etc), and those are tested in TravisCI.
3234

35+
### Synchronization with Ruby Implementations
36+
3337
The specs are synchronized both ways around once a month by @eregon between ruby/spec, MRI, JRuby and TruffleRuby.
3438
Each of these repositories has a full copy of the specs under `spec/ruby` to ease editing specs.
3539
Any of these repositories can be used to add or edit specs, use what is most convenient for you.
3640

37-
For *testing* a Ruby implementation, one should always test against the implementation's copy of the specs under `spec/ruby`, as that's what the Ruby implementation tests against in their CI.
41+
For *testing* the development version of a Ruby implementation, one should always test against that implementation's copy of the specs under `spec/ruby`, as that's what the Ruby implementation tests against in their CI.
3842
Also, this repository doesn't always contain the latest spec changes from MRI (it's synchronized monthly), and does not contain tags (specs marked as failing on that Ruby implementation).
39-
Running specs in a Ruby implementation can be done with:
43+
Running specs on a Ruby implementation can be done with:
4044

4145
```
4246
$ cd ruby_implementation/spec/ruby
4347
# Add ../ruby_implementation/bin in PATH, or pass -t /path/to/bin/ruby
4448
$ ../mspec/bin/mspec
4549
```
4650

51+
### Specs for old Ruby versions
52+
4753
For older specs try these commits:
4854
* Ruby 2.0.0-p647 - [Suite](https://github.com/ruby/spec/commit/245862558761d5abc676843ef74f86c9bcc8ea8d) using [MSpec](https://github.com/ruby/mspec/commit/f90efa068791064f955de7a843e96e2d7d3041c2) (may encounter 2 failures)
4955
* Ruby 2.1.9 - [Suite](https://github.com/ruby/spec/commit/f029e65241374386077ac500add557ae65069b55) using [MSpec](https://github.com/ruby/mspec/commit/55568ea3918c6380e64db8c567d732fa5781efed)

spec/ruby/command_line/feature_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@
3737
ruby_exe("p 'foo'.frozen?", options: "--disable-frozen-string-literal").chomp.should == "false"
3838
end
3939

40-
it "can be used with all" do
40+
it "can be used with all for enable" do
4141
e = "p [defined?(Gem), defined?(DidYouMean), $VERBOSE, 'foo'.frozen?]"
4242
env = {'RUBYOPT' => '-w'}
43-
ruby_exe(e, options: "--enable=all", env: env).chomp.should == "[\"constant\", \"constant\", true, true]"
43+
# Use a single variant here because it can be quite slow as it might enable jit, etc
4444
ruby_exe(e, options: "--enable-all", env: env).chomp.should == "[\"constant\", \"constant\", true, true]"
45+
end
46+
47+
it "can be used with all for disable" do
48+
e = "p [defined?(Gem), defined?(DidYouMean), $VERBOSE, 'foo'.frozen?]"
49+
env = {'RUBYOPT' => '-w'}
4550
ruby_exe(e, options: "--disable=all", env: env).chomp.should == "[nil, nil, false, false]"
4651
ruby_exe(e, options: "--disable-all", env: env).chomp.should == "[nil, nil, false, false]"
4752
end

spec/ruby/core/binding/eval_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
bind2.local_variables.should == []
2424
end
2525

26-
ruby_version_is ""..."2.8" do
26+
ruby_version_is ""..."3.0" do
2727
it "inherits __LINE__ from the enclosing scope" do
2828
obj = BindingSpecs::Demo.new(1)
2929
bind = obj.get_binding
@@ -50,7 +50,7 @@
5050
end
5151
end
5252

53-
ruby_version_is "2.8" do
53+
ruby_version_is "3.0" do
5454
it "starts with line 1 if single argument is given" do
5555
obj = BindingSpecs::Demo.new(1)
5656
bind = obj.get_binding
@@ -89,15 +89,15 @@
8989
bind.eval("#foo\n__LINE__", "(test)", 88).should == 89
9090
end
9191

92-
ruby_version_is ""..."2.8" do
92+
ruby_version_is ""..."3.0" do
9393
it "inherits __FILE__ from the enclosing scope" do
9494
obj = BindingSpecs::Demo.new(1)
9595
bind = obj.get_binding
9696
suppress_warning {bind.eval("__FILE__")}.should == obj.get_file_of_binding
9797
end
9898
end
9999

100-
ruby_version_is "2.8" do
100+
ruby_version_is "3.0" do
101101
it "Uses (eval) as __FILE__ if single argument given" do
102102
obj = BindingSpecs::Demo.new(1)
103103
bind = obj.get_binding

spec/ruby/core/complex/to_c_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "Complex#to_c" do
4+
it "returns self" do
5+
value = Complex(1, 5)
6+
value.to_c.should equal(value)
7+
end
8+
9+
it 'returns the same value' do
10+
Complex(1, 5).to_c.should == Complex(1, 5)
11+
end
12+
end

spec/ruby/core/env/delete_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
ScratchPad.recorded.should == "foo"
3131
end
3232

33-
ruby_version_is "2.8" do
33+
ruby_version_is "3.0" do
3434
it "returns the result of given block if the named environment variable does not exist" do
3535
ENV.delete("foo")
3636
ENV.delete("foo") { |name| "bar" }.should == "bar"

spec/ruby/core/exception/no_method_error_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def inspect
104104
end
105105
end
106106

107-
ruby_version_is "2.8" do
107+
ruby_version_is "3.0" do
108108
it "uses #name to display the receiver if it is a class or a module" do
109109
klass = Class.new { def self.name; "MyClass"; end }
110110
begin

spec/ruby/core/exception/top_level_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
it "the Exception#cause is printed to STDERR with backtraces" do
1010
code = <<-RUBY
1111
def raise_cause
12-
raise "the cause"
12+
raise "the cause"
1313
end
1414
def raise_wrapped
1515
raise "wrapped"
@@ -22,7 +22,7 @@ def raise_wrapped
2222
RUBY
2323
lines = ruby_exe(code, args: "2>&1").lines
2424
lines.reject! { |l| l.include?('rescue in') }
25-
lines.map! { |l| l.split(':')[2..-1].join(':').chomp }
25+
lines.map! { |l| l.chomp[/:(in.+)/, 1] }
2626
lines.should == ["in `raise_wrapped': wrapped (RuntimeError)",
2727
"in `<main>'",
2828
"in `raise_cause': the cause (RuntimeError)",

spec/ruby/core/hash/except_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require_relative '../../spec_helper'
2+
3+
ruby_version_is "3.0" do
4+
describe "Hash#except" do
5+
before :each do
6+
@hash = { a: 1, b: 2, c: 3 }
7+
end
8+
9+
it "returns a new duplicate hash without arguments" do
10+
ret = @hash.except
11+
ret.should_not equal(@hash)
12+
ret.should == @hash
13+
end
14+
15+
it "returns a hash without the requested subset" do
16+
@hash.except(:c, :a).should == { b: 2 }
17+
end
18+
19+
it "ignores keys not present in the original hash" do
20+
@hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 }
21+
end
22+
23+
it "returns an instance of a subclass" do
24+
klass = Class.new(Hash)
25+
h = klass.new
26+
h[:bar] = 12
27+
h[:foo] = 42
28+
r = h.except(:foo)
29+
r.should == {bar: 12}
30+
r.class.should == klass
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)