Skip to content

Commit 0f027c9

Browse files
authored
Merge pull request jruby#9282 from andrykonchin/update-specs
Update to ruby/spec@af627d6
2 parents a5dba28 + ee1e5b4 commit 0f027c9

197 files changed

Lines changed: 4773 additions & 3061 deletions

File tree

Some content is hidden

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

spec/mspec/lib/mspec/commands/mspec-tag.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def register
112112
MSpec.register_mode :pretend
113113
MSpec.register_mode :unguarded
114114
config[:formatter] = false
115+
config[:xtags] = []
115116
else
116117
raise ArgumentError, "No recognized action given"
117118
end

spec/mspec/lib/mspec/matchers/raise_error.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,15 @@ module MSpecMatchers
9090
private def raise_error(exception = Exception, message = nil, &block)
9191
RaiseErrorMatcher.new(exception, message, &block)
9292
end
93+
94+
# CRuby < 4.1 has inconsistent coercion errors:
95+
# https://bugs.ruby-lang.org/issues/21864
96+
# This matcher ignores the message on CRuby < 4.1
97+
# and checks the message for all other cases, including other Rubies
98+
private def raise_consistent_error(exception = Exception, message = nil, &block)
99+
if RUBY_ENGINE == "ruby" and ruby_version_is ""..."4.1"
100+
message = nil
101+
end
102+
RaiseErrorMatcher.new(exception, message, &block)
103+
end
93104
end

spec/mspec/lib/mspec/runner/formatters/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def register
4646
LeakCheckerAction.new.register
4747
end
4848

49-
if ENV['CHECK_LEAKS'] || ENV['CHECK_CONSTANT_LEAKS']
49+
if (ENV['CHECK_LEAKS'] || ENV['CHECK_CONSTANT_LEAKS']) && ENV['CHECK_CONSTANT_LEAKS'] != 'false'
5050
save = ENV['CHECK_LEAKS'] == 'save' || ENV['CHECK_CONSTANT_LEAKS'] == 'save'
5151
ConstantsLeakCheckerAction.new(save).register
5252
end

spec/mspec/lib/mspec/runner/mspec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ def self.make_tag_dir(path)
365365
# Writes each tag in +tags+ to the tag file. Overwrites the
366366
# tag file if it exists.
367367
def self.write_tags(tags)
368+
return delete_tags if tags.empty?
368369
file = tags_file
369370
make_tag_dir(file)
370371
File.open(file, "w:utf-8") do |f|

spec/mspec/tool/remove_old_guards.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def each_spec_file(&block)
3131
Dir["*/**/*.rb"].each(&block)
3232
end
3333

34+
def each_file(&block)
35+
Dir["**/*"].each { |path|
36+
yield path if File.file?(path)
37+
}
38+
end
39+
3440
def remove_guards(guard, keep)
3541
each_spec_file do |file|
3642
contents = File.binread(file)
@@ -109,7 +115,7 @@ def remove_unused_shared_specs
109115
end
110116

111117
def search(regexp)
112-
each_spec_file do |file|
118+
each_file do |file|
113119
contents = File.binread(file)
114120
if contents =~ regexp
115121
puts file
@@ -136,3 +142,4 @@ def search(regexp)
136142
puts "Search:"
137143
search(/(["'])#{version}\1/)
138144
search(/^\s*#.+#{version}/)
145+
search(/RUBY_VERSION_IS_#{version.tr('.', '_')}/)

spec/ruby/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ ruby/spec is known to be tested in these implementations for every commit:
3030
* [Opal](https://github.com/opal/opal/tree/master/spec)
3131
* [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor)
3232

33-
ruby/spec describes the behavior of Ruby 3.2 and more recent Ruby versions.
34-
More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (3.2.x, 3.3.x, etc), and those are tested in CI.
33+
ruby/spec describes the behavior of Ruby 3.3 and more recent Ruby versions.
34+
More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (3.3.x, 3.4.x, etc), and those are tested in CI.
3535

3636
### Synchronization with Ruby Implementations
3737

spec/ruby/command_line/dash_upper_s_spec.rb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,66 @@
22

33
describe 'The -S command line option' do
44
before :each do
5-
@path = [ENV['PATH'], fixture(__FILE__, "bin")].join(':')
5+
@bin = fixture(__FILE__, "bin")
6+
@path = [ENV['PATH'], @bin].join(File::PATH_SEPARATOR)
67
end
78

89
platform_is_not :windows do
910
# On VirtualBox shared directory (vboxsf) all files are world writable
1011
# and MRI shows warning when including world writable path in ENV['PATH'].
1112
# This is why we are using /success$/ matching in the following cases.
1213

14+
it "runs launcher found in RUBYPATH, but only code after the first /\#!.*ruby.*/-ish line in target file" do
15+
result = ruby_exe(nil, options: '-S hybrid_launcher.sh', env: { 'RUBYPATH' => @bin }, args: '2>&1')
16+
result.should =~ /success$/
17+
end
18+
1319
it "runs launcher found in PATH, but only code after the first /\#!.*ruby.*/-ish line in target file" do
1420
result = ruby_exe(nil, options: '-S hybrid_launcher.sh', env: { 'PATH' => @path }, args: '2>&1')
1521
result.should =~ /success$/
1622
end
1723

24+
it "runs launcher found in RUBYPATH" do
25+
result = ruby_exe(nil, options: '-S launcher.rb', env: { 'RUBYPATH' => @bin }, args: '2>&1')
26+
result.should =~ /success$/
27+
end
28+
1829
it "runs launcher found in PATH" do
1930
result = ruby_exe(nil, options: '-S launcher.rb', env: { 'PATH' => @path }, args: '2>&1')
2031
result.should =~ /success$/
2132
end
2233

34+
it "runs launcher found in RUBYPATH and sets the exit status to 1 if it fails" do
35+
result = ruby_exe(nil, options: '-S dash_s_fail', env: { 'RUBYPATH' => @bin }, args: '2>&1', exit_status: 1)
36+
result.should =~ /\bdie\b/
37+
$?.exitstatus.should == 1
38+
end
39+
2340
it "runs launcher found in PATH and sets the exit status to 1 if it fails" do
2441
result = ruby_exe(nil, options: '-S dash_s_fail', env: { 'PATH' => @path }, args: '2>&1', exit_status: 1)
2542
result.should =~ /\bdie\b/
2643
$?.exitstatus.should == 1
2744
end
45+
46+
ruby_version_is "4.1" do
47+
describe "if the script name contains separator" do
48+
before(:each) do
49+
@bin = File.dirname(@bin)
50+
@path = [ENV['PATH'], @bin].join(File::PATH_SEPARATOR)
51+
end
52+
53+
it "does not search launcher in RUBYPATH" do
54+
result = ruby_exe(nil, options: '-S bin/launcher.rb', env: { 'RUBYPATH' => @bin }, args: '2>&1', exit_status: 1)
55+
result.should =~ /LoadError/
56+
$?.should_not.success?
57+
end
58+
59+
it "does not search launcher in PATH" do
60+
result = ruby_exe(nil, options: '-S bin/launcher.rb', env: { 'PATH' => @path }, args: '2>&1', exit_status: 1)
61+
result.should =~ /LoadError/
62+
$?.should_not.success?
63+
end
64+
end
65+
end
2866
end
2967
end

spec/ruby/command_line/error_message_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@
88
out = ruby_exe("end #syntax error", args: "2> #{File::NULL}", exit_status: 1)
99
out.chomp.should.empty?
1010
end
11+
12+
it "is not modified with extra escaping of control characters and backslashes" do
13+
out = ruby_exe('raise "\e[31mRed\e[0m error\\\\message"', args: "2>&1", exit_status: 1)
14+
out.chomp.should include("\e[31mRed\e[0m error\\message")
15+
end
1116
end
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# encoding: binary
2+
require_relative '../../../spec_helper'
3+
require_relative '../fixtures/classes'
4+
require_relative 'shared/basic'
5+
require_relative 'shared/numeric_basic'
6+
require_relative 'shared/integer'
7+
8+
ruby_version_is "4.1" do
9+
describe "Array#pack with format 'R'" do
10+
it_behaves_like :array_pack_basic, 'R'
11+
it_behaves_like :array_pack_basic_non_float, 'R'
12+
it_behaves_like :array_pack_arguments, 'R'
13+
it_behaves_like :array_pack_numeric_basic, 'R'
14+
it_behaves_like :array_pack_integer, 'R'
15+
16+
it "encodes a ULEB128 integer" do
17+
[ [[0], "\x00"],
18+
[[1], "\x01"],
19+
[[127], "\x7f"],
20+
[[128], "\x80\x01"],
21+
[[0x3fff], "\xff\x7f"],
22+
[[0x4000], "\x80\x80\x01"],
23+
[[0xffffffff], "\xff\xff\xff\xff\x0f"],
24+
[[0x100000000], "\x80\x80\x80\x80\x10"],
25+
[[0xffff_ffff_ffff_ffff], "\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01"],
26+
[[0xffff_ffff_ffff_ffff_ffff_ffff], "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x1f"],
27+
].should be_computed_by(:pack, "R")
28+
end
29+
30+
it "encodes multiple values with '*' modifier" do
31+
[1, 2].pack("R*").should == "\x01\x02"
32+
[127, 128].pack("R*").should == "\x7f\x80\x01"
33+
end
34+
35+
it "raises an ArgumentError when passed a negative value" do
36+
-> { [-1].pack("R") }.should raise_error(ArgumentError)
37+
-> { [-100].pack("R") }.should raise_error(ArgumentError)
38+
end
39+
40+
it "round-trips values through pack and unpack" do
41+
values = [0, 1, 127, 128, 0x3fff, 0x4000, 0xffffffff, 0x100000000]
42+
values.pack("R*").unpack("R*").should == values
43+
end
44+
end
45+
46+
describe "Array#pack with format 'r'" do
47+
it_behaves_like :array_pack_basic, 'r'
48+
it_behaves_like :array_pack_basic_non_float, 'r'
49+
it_behaves_like :array_pack_arguments, 'r'
50+
it_behaves_like :array_pack_numeric_basic, 'r'
51+
it_behaves_like :array_pack_integer, 'r'
52+
53+
it "encodes a SLEB128 integer" do
54+
[ [[0], "\x00"],
55+
[[1], "\x01"],
56+
[[-1], "\x7f"],
57+
[[-2], "\x7e"],
58+
[[127], "\xff\x00"],
59+
[[128], "\x80\x01"],
60+
[[-127], "\x81\x7f"],
61+
[[-128], "\x80\x7f"],
62+
].should be_computed_by(:pack, "r")
63+
end
64+
65+
it "encodes larger positive numbers" do
66+
[0x3fff].pack("r").should == "\xff\xff\x00"
67+
[0x4000].pack("r").should == "\x80\x80\x01"
68+
end
69+
70+
it "encodes larger negative numbers" do
71+
[-0x3fff].pack("r").should == "\x81\x80\x7f"
72+
[-0x4000].pack("r").should == "\x80\x80\x7f"
73+
end
74+
75+
it "encodes very large numbers" do
76+
[0xffff_ffff_ffff_ffff_ffff_ffff].pack("r").should == "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x1F"
77+
[-0xffff_ffff_ffff_ffff_ffff_ffff].pack("r").should == "\x81\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x60"
78+
end
79+
80+
it "encodes multiple values with '*' modifier" do
81+
[0, 1, -1].pack("r*").should == "\x00\x01\x7f"
82+
end
83+
84+
it "round-trips values through pack and unpack" do
85+
values = [0, 1, -1, 127, -127, 128, -128, 0x3fff, -0x3fff, 0x4000, -0x4000]
86+
values.pack("r*").unpack("r*").should == values
87+
end
88+
end
89+
end

spec/ruby/core/array/pack/shared/basic.rb

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

3535
it "raise ArgumentError when a directive is unknown" do
3636
# additional directive ('a') is required for the X directive
37-
-> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/)
37+
-> { [@obj, @obj].pack("a K" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'K'/)
3838
-> { [@obj, @obj].pack("a 0" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive '0'/)
3939
-> { [@obj, @obj].pack("a :" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive ':'/)
4040
end

0 commit comments

Comments
 (0)