Skip to content

Commit bb5f54c

Browse files
committed
[GR-14806] Update specs
PullRequest: truffleruby/3837
2 parents d52835e + 3d6729f commit bb5f54c

File tree

68 files changed

+1264
-134
lines changed

Some content is hidden

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

68 files changed

+1264
-134
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ local composition_environment = utils.add_inclusion_tracking(part_definitions, "
552552
"ruby-test-svm-graal-core-darwin-aarch64-17": $.platform.darwin_aarch64 + $.jdk.v17 + $.env.native + gate + native_tests,
553553
"ruby-test-svm-graal-core-darwin-aarch64-20": $.platform.darwin_aarch64 + $.jdk.v20 + $.env.native + gate + native_tests,
554554
"ruby-test-svm-graal-enterprise-linux": $.platform.linux + $.jdk.v17 + $.env.native_ee + $.env.gdb_svm + gate + native_tests + $.env.host_inlining_log,
555-
"ruby-test-svm-graal-enterprise-darwin-aarch64 ": $.platform.darwin_aarch64 + $.jdk.v17 + $.env.native_ee + gate + native_tests,
555+
"ruby-test-svm-graal-enterprise-darwin-aarch64": $.platform.darwin_aarch64 + $.jdk.v17 + $.env.native_ee + gate + native_tests,
556556
},
557557

558558
local other_rubies = {

spec/ruby/.rubocop_todo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Lint/RescueException:
9898
- 'core/dir/fileno_spec.rb'
9999
- 'core/exception/cause_spec.rb'
100100
- 'core/exception/no_method_error_spec.rb'
101+
- 'core/fiber/kill_spec.rb'
101102
- 'core/kernel/fixtures/autoload_frozen.rb'
102103
- 'core/kernel/raise_spec.rb'
103104
- 'core/module/autoload_spec.rb'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@@@This line is not value Ruby
22
#!ruby
3-
puts 'success'
3+
puts 'success'

spec/ruby/core/array/assoc_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
s1 = ["colors", "red", "blue", "green"]
77
s2 = [:letters, "a", "b", "c"]
88
s3 = [4]
9-
s4 = ["colors", "cyan", "yellow", "magenda"]
9+
s4 = ["colors", "cyan", "yellow", "magenta"]
1010
s5 = [:letters, "a", "i", "u"]
1111
s_nil = [nil, nil]
1212
a = [s1, s2, s3, s4, s5, s_nil]

spec/ruby/core/array/fill_spec.rb

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@
5252
end
5353

5454
it "raises an ArgumentError if 4 or more arguments are passed when no block given" do
55-
-> { [].fill('a') }.should_not raise_error(ArgumentError)
56-
57-
-> { [].fill('a', 1) }.should_not raise_error(ArgumentError)
58-
59-
-> { [].fill('a', 1, 2) }.should_not raise_error(ArgumentError)
55+
[].fill('a').should == []
56+
[].fill('a', 1).should == []
57+
[].fill('a', 1, 2).should == [nil, 'a', 'a']
6058
-> { [].fill('a', 1, 2, true) }.should raise_error(ArgumentError)
6159
end
6260

@@ -65,11 +63,9 @@
6563
end
6664

6765
it "raises an ArgumentError if 3 or more arguments are passed when a block given" do
68-
-> { [].fill() {|i|} }.should_not raise_error(ArgumentError)
69-
70-
-> { [].fill(1) {|i|} }.should_not raise_error(ArgumentError)
71-
72-
-> { [].fill(1, 2) {|i|} }.should_not raise_error(ArgumentError)
66+
[].fill() {|i|}.should == []
67+
[].fill(1) {|i|}.should == []
68+
[].fill(1, 2) {|i|}.should == [nil, nil, nil]
7369
-> { [].fill(1, 2, true) {|i|} }.should raise_error(ArgumentError)
7470
end
7571

@@ -213,23 +209,23 @@
213209

214210
# See: https://blade.ruby-lang.org/ruby-core/17481
215211
it "does not raise an exception if the given length is negative and its absolute value does not exceed the index" do
216-
-> { [1, 2, 3, 4].fill('a', 3, -1)}.should_not raise_error(ArgumentError)
217-
-> { [1, 2, 3, 4].fill('a', 3, -2)}.should_not raise_error(ArgumentError)
218-
-> { [1, 2, 3, 4].fill('a', 3, -3)}.should_not raise_error(ArgumentError)
212+
[1, 2, 3, 4].fill('a', 3, -1).should == [1, 2, 3, 4]
213+
[1, 2, 3, 4].fill('a', 3, -2).should == [1, 2, 3, 4]
214+
[1, 2, 3, 4].fill('a', 3, -3).should == [1, 2, 3, 4]
219215

220-
-> { [1, 2, 3, 4].fill(3, -1, &@never_passed)}.should_not raise_error(ArgumentError)
221-
-> { [1, 2, 3, 4].fill(3, -2, &@never_passed)}.should_not raise_error(ArgumentError)
222-
-> { [1, 2, 3, 4].fill(3, -3, &@never_passed)}.should_not raise_error(ArgumentError)
216+
[1, 2, 3, 4].fill(3, -1, &@never_passed).should == [1, 2, 3, 4]
217+
[1, 2, 3, 4].fill(3, -2, &@never_passed).should == [1, 2, 3, 4]
218+
[1, 2, 3, 4].fill(3, -3, &@never_passed).should == [1, 2, 3, 4]
223219
end
224220

225221
it "does not raise an exception even if the given length is negative and its absolute value exceeds the index" do
226-
-> { [1, 2, 3, 4].fill('a', 3, -4)}.should_not raise_error(ArgumentError)
227-
-> { [1, 2, 3, 4].fill('a', 3, -5)}.should_not raise_error(ArgumentError)
228-
-> { [1, 2, 3, 4].fill('a', 3, -10000)}.should_not raise_error(ArgumentError)
222+
[1, 2, 3, 4].fill('a', 3, -4).should == [1, 2, 3, 4]
223+
[1, 2, 3, 4].fill('a', 3, -5).should == [1, 2, 3, 4]
224+
[1, 2, 3, 4].fill('a', 3, -10000).should == [1, 2, 3, 4]
229225

230-
-> { [1, 2, 3, 4].fill(3, -4, &@never_passed)}.should_not raise_error(ArgumentError)
231-
-> { [1, 2, 3, 4].fill(3, -5, &@never_passed)}.should_not raise_error(ArgumentError)
232-
-> { [1, 2, 3, 4].fill(3, -10000, &@never_passed)}.should_not raise_error(ArgumentError)
226+
[1, 2, 3, 4].fill(3, -4, &@never_passed).should == [1, 2, 3, 4]
227+
[1, 2, 3, 4].fill(3, -5, &@never_passed).should == [1, 2, 3, 4]
228+
[1, 2, 3, 4].fill(3, -10000, &@never_passed).should == [1, 2, 3, 4]
233229
end
234230

235231
it "tries to convert the second and third arguments to Integers using #to_int" do

spec/ruby/core/dir/fchdir_spec.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@
22
require_relative 'fixtures/common'
33

44
ruby_version_is '3.3' do
5-
has_fchdir = begin
6-
dir = Dir.new('.')
7-
Dir.fchdir(dir.fileno)
8-
true
9-
rescue NotImplementedError, NoMethodError
10-
false
11-
ensure
12-
dir.close
13-
end
14-
15-
guard -> { has_fchdir } do
5+
guard -> { Dir.respond_to? :fchdir } do
166
describe "Dir.fchdir" do
177
before :all do
188
DirSpecs.create_mock_dirs
@@ -67,7 +57,7 @@
6757
end
6858
end
6959

70-
guard_not -> { has_fchdir } do
60+
guard_not -> { Dir.respond_to? :fchdir } do
7161
describe "Dir.fchdir" do
7262
it "raises NotImplementedError" do
7363
-> { Dir.fchdir 1 }.should raise_error(NotImplementedError)

spec/ruby/core/encoding/replicate_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@
6767
end
6868
end
6969

70+
ruby_version_is "3.2"..."3.3" do
71+
it "warns about deprecation" do
72+
-> {
73+
Encoding::US_ASCII.replicate('MY-US-ASCII')
74+
}.should complain(/warning: Encoding#replicate is deprecated and will be removed in Ruby 3.3; use the original encoding instead/)
75+
end
76+
end
77+
7078
ruby_version_is "3.3" do
7179
it "has been removed" do
7280
Encoding::US_ASCII.should_not.respond_to?(:replicate, true)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
require_relative '../../spec_helper'
2+
3+
ruby_version_is "3.2" do
4+
describe "Enumerator.product" do
5+
it "returns a Cartesian product of enumerators" do
6+
enum = Enumerator.product(1..2, ["A", "B"])
7+
enum.to_a.should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
8+
end
9+
10+
it "accepts a list of enumerators of any length" do
11+
enum = Enumerator.product(1..2)
12+
enum.to_a.should == [[1], [2]]
13+
14+
enum = Enumerator.product(1..2, ["A"])
15+
enum.to_a.should == [[1, "A"], [2, "A"]]
16+
17+
enum = Enumerator.product(1..2, ["A"], ["B"])
18+
enum.to_a.should == [[1, "A", "B"], [2, "A", "B"]]
19+
20+
enum = Enumerator.product(2..3, ["A"], ["B"], ["C"])
21+
enum.to_a.should == [[2, "A", "B", "C"], [3, "A", "B", "C"]]
22+
end
23+
24+
it "returns an enumerator with an empty array when no arguments passed" do
25+
enum = Enumerator.product
26+
enum.to_a.should == [[]]
27+
end
28+
29+
it "returns an instance of Enumerator::Product" do
30+
enum = Enumerator.product
31+
enum.class.should == Enumerator::Product
32+
end
33+
34+
it "accepts infinite enumerators and returns infinite enumerator" do
35+
enum = Enumerator.product(1.., ["A", "B"])
36+
enum.take(5).should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"], [3, "A"]]
37+
enum.size.should == Float::INFINITY
38+
end
39+
40+
it "accepts a block" do
41+
elems = []
42+
enum = Enumerator.product(1..2, ["X", "Y"]) { elems << _1 }
43+
44+
elems.should == [[1, "X"], [1, "Y"], [2, "X"], [2, "Y"]]
45+
end
46+
47+
it "reject keyword arguments" do
48+
-> {
49+
Enumerator.product(1..3, foo: 1, bar: 2)
50+
}.should raise_error(ArgumentError, "unknown keywords: :foo, :bar")
51+
end
52+
53+
it "calls only #each_entry method on arguments" do
54+
object = Object.new
55+
def object.each_entry
56+
yield 1
57+
yield 2
58+
end
59+
60+
enum = Enumerator.product(object, ["A", "B"])
61+
enum.to_a.should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
62+
end
63+
64+
it "raises NoMethodError when argument doesn't respond to #each_entry" do
65+
-> {
66+
Enumerator.product(Object.new).to_a
67+
}.should raise_error(NoMethodError, /undefined method `each_entry' for/)
68+
end
69+
70+
it "calls #each_entry lazily" do
71+
Enumerator.product(Object.new).should be_kind_of(Enumerator)
72+
end
73+
74+
it "iterates through consuming enumerator elements only once" do
75+
a = [1, 2, 3]
76+
i = 0
77+
78+
enum = Enumerator.new do |y|
79+
while i < a.size
80+
y << a[i]
81+
i += 1
82+
end
83+
end
84+
85+
Enumerator.product(['a', 'b'], enum).to_a.should == [["a", 1], ["a", 2], ["a", 3]]
86+
end
87+
end
88+
end

spec/ruby/core/env/clone_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "ENV#clone" do
4+
it "raises ArgumentError when keyword argument 'freeze' is neither nil nor boolean" do
5+
-> {
6+
ENV.clone(freeze: 1)
7+
}.should raise_error(ArgumentError)
8+
end
9+
10+
it "raises ArgumentError when keyword argument is not 'freeze'" do
11+
-> {
12+
ENV.clone(foo: nil)
13+
}.should raise_error(ArgumentError)
14+
end
15+
16+
ruby_version_is "3.2" do
17+
it "raises TypeError" do
18+
-> {
19+
ENV.clone
20+
}.should raise_error(TypeError, /Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash/)
21+
end
22+
end
23+
end

spec/ruby/core/env/dup_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "ENV#dup" do
4+
ruby_version_is "3.1" do
5+
it "raises TypeError" do
6+
-> {
7+
ENV.dup
8+
}.should raise_error(TypeError, /Cannot dup ENV, use ENV.to_h to get a copy of ENV as a hash/)
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)