Skip to content

Commit

Permalink
Update to ruby/spec@bd7017f
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Oct 30, 2023
1 parent 14fa5e3 commit ab4781b
Show file tree
Hide file tree
Showing 88 changed files with 1,634 additions and 289 deletions.
4 changes: 4 additions & 0 deletions spec/ruby/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Lint/AssignmentInCondition:
Lint/BooleanSymbol:
Enabled: false

Lint/DeprecatedOpenSSLConstant:
Exclude:
- library/openssl/digest/**/*.rb

Lint/InterpolationCheck:
Enabled: false

Expand Down
1 change: 1 addition & 0 deletions spec/ruby/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ In case there is a bug in MRI and the fix will be backported to previous version
If it is not backported or not likely, use `ruby_version_is` instead.
First, file a bug at https://bugs.ruby-lang.org/.
The problem is `ruby_bug` would make non-MRI implementations fail this spec while MRI itself does not pass it, so it should only be used if the bug is/will be fixed and backported.
Otherwise, non-MRI implementations would have to choose between being incompatible with the latest release of MRI to pass the spec or fail the spec, both which make no sense.

```ruby
ruby_bug '#13669', ''...'3.2' do
Expand Down
6 changes: 6 additions & 0 deletions spec/ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ MSpec can automatically add new top-level constants in this file with:

$ CHECK_LEAKS=save mspec ../mspec/bin/mspec file

### Running Specs on S390x CPU Architecture

Run the specs with `DFLTCC=0` if you see failing specs related to the zlib library on s390x CPU architecture. The failures can happen with the zlib library applying the patch madler/zlib#410 to enable the deflate algorithm producing a different compressed byte stream.

$ DFLTCC=0 ../mspec/bin/mspec

### Contributing and Writing Specs

See [CONTRIBUTING.md](https://github.com/ruby/spec/blob/master/CONTRIBUTING.md) for documentation about contributing and writing specs (guards, matchers, etc).
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/command_line/dash_a_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
end

it "runs the code in loop conditional on Kernel.gets()" do
ruby_exe("puts $F.last", options: "-n -a", escape: true,
ruby_exe("puts $F.last", options: "-n -a",
args: " < #{@names}").should ==
"jones\nfield\ngrey\n"
end

it "sets $-a" do
ruby_exe("puts $-a", options: "-n -a", escape: true,
ruby_exe("puts $-a", options: "-n -a",
args: " < #{@names}").should ==
"true\ntrue\ntrue\n"
end
Expand Down
8 changes: 4 additions & 4 deletions spec/ruby/command_line/dash_l_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
end

it "chomps lines with default separator" do
ruby_exe('puts $_.end_with?("\n")', options: "-n -l", escape: true,
ruby_exe('puts $_.end_with?("\n")', options: "-n -l",
args: " < #{@names}").should ==
"false\nfalse\nfalse\n"
end

it "chomps last line based on $/" do
ruby_exe('BEGIN { $/ = "ones\n" }; puts $_', options: "-W0 -n -l", escape: true,
ruby_exe('BEGIN { $/ = "ones\n" }; puts $_', options: "-W0 -n -l",
args: " < #{@names}").should ==
"alice j\nbob field\njames grey\n"
end

it "sets $\\ to the value of $/" do
ruby_exe("puts $\\ == $/", options: "-W0 -n -l", escape: true,
ruby_exe("puts $\\ == $/", options: "-W0 -n -l",
args: " < #{@names}").should ==
"true\ntrue\ntrue\n"
end

it "sets $-l" do
ruby_exe("puts $-l", options: "-n -l", escape: true,
ruby_exe("puts $-l", options: "-n -l",
args: " < #{@names}").should ==
"true\ntrue\ntrue\n"
end
Expand Down
8 changes: 4 additions & 4 deletions spec/ruby/command_line/dash_n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
end

it "runs the code in loop conditional on Kernel.gets()" do
ruby_exe("puts $_", options: "-n", escape: true,
ruby_exe("puts $_", options: "-n",
args: " < #{@names}").should ==
"alice\nbob\njames\n"
end

it "only evaluates BEGIN blocks once" do
ruby_exe("BEGIN { puts \"hi\" }; puts $_", options: "-n", escape: true,
ruby_exe("BEGIN { puts \"hi\" }; puts $_", options: "-n",
args: " < #{@names}").should ==
"hi\nalice\nbob\njames\n"
end

it "only evaluates END blocks once" do
ruby_exe("puts $_; END {puts \"bye\"}", options: "-n", escape: true,
ruby_exe("puts $_; END {puts \"bye\"}", options: "-n",
args: " < #{@names}").should ==
"alice\nbob\njames\nbye\n"
end
Expand All @@ -29,7 +29,7 @@
$total += 1
END { puts $total }
script
ruby_exe(script, options: "-n", escape: true,
ruby_exe(script, options: "-n",
args: " < #{@names}").should ==
"3\n"
end
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/command_line/dash_p_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
end

it "runs the code in loop conditional on Kernel.gets() and prints $_" do
ruby_exe("$_ = $_.upcase", options: "-p", escape: true,
ruby_exe("$_ = $_.upcase", options: "-p",
args: " < #{@names}").should ==
"ALICE\nBOB\nJAMES\n"
end

it "sets $-p" do
ruby_exe("$_ = $-p", options: "-p", escape: true,
ruby_exe("$_ = $-p", options: "-p",
args: " < #{@names}").should ==
"truetruetrue"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/command_line/dash_upper_f_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
end

it "specifies the field separator pattern for -a" do
ruby_exe("puts $F[0]", options: "-naF:", escape: true,
ruby_exe("puts $F[0]", options: "-naF:",
args: " < #{@passwd}").should ==
"nobody\nroot\ndaemon\n"
end
Expand Down
14 changes: 7 additions & 7 deletions spec/ruby/command_line/rubyopt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

it "adds the -I path to $LOAD_PATH" do
ENV["RUBYOPT"] = "-Ioptrubyspecincl"
result = ruby_exe("puts $LOAD_PATH.grep(/byspecin/)", escape: true)
result = ruby_exe("puts $LOAD_PATH.grep(/byspecin/)")
result.chomp[-15..-1].should == "optrubyspecincl"
end

it "sets $DEBUG to true for '-d'" do
ENV["RUBYOPT"] = '-d'
command = %[puts "value of $DEBUG is \#{$DEBUG}"]
result = ruby_exe(command, escape: true, args: "2>&1")
result = ruby_exe(command, args: "2>&1")
result.should =~ /value of \$DEBUG is true/
end

Expand All @@ -36,27 +36,27 @@

it "sets $VERBOSE to true for '-w'" do
ENV["RUBYOPT"] = '-w'
ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
ruby_exe("p $VERBOSE").chomp.should == "true"
end

it "sets $VERBOSE to true for '-W'" do
ENV["RUBYOPT"] = '-W'
ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
ruby_exe("p $VERBOSE").chomp.should == "true"
end

it "sets $VERBOSE to nil for '-W0'" do
ENV["RUBYOPT"] = '-W0'
ruby_exe("p $VERBOSE", escape: true).chomp.should == "nil"
ruby_exe("p $VERBOSE").chomp.should == "nil"
end

it "sets $VERBOSE to false for '-W1'" do
ENV["RUBYOPT"] = '-W1'
ruby_exe("p $VERBOSE", escape: true).chomp.should == "false"
ruby_exe("p $VERBOSE").chomp.should == "false"
end

it "sets $VERBOSE to true for '-W2'" do
ENV["RUBYOPT"] = '-W2'
ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
ruby_exe("p $VERBOSE").chomp.should == "true"
end

it "suppresses deprecation warnings for '-W:no-deprecated'" do
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/argf/readpartial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
print ARGF.readpartial(#{@stdin.size})
ARGF.readpartial(1) rescue print $!.class
STR
stdin = ruby_exe(ruby_str, args: "< #{@stdin_name}", escape: true)
stdin = ruby_exe(ruby_str, args: "< #{@stdin_name}")
stdin.should == @stdin + "EOFError"
end
end
4 changes: 0 additions & 4 deletions spec/ruby/core/array/bsearch_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@
@array.bsearch_index { |x| -1 }.should be_nil
end

it "returns the middle element when block always returns zero" do
@array.bsearch_index { |x| 0 }.should == 2
end

context "magnitude does not effect the result" do
it "returns the index of any matched elements where element is between 4n <= xn < 8n" do
[1, 2].should include(@array.bsearch_index { |x| (1 - x / 4) * (2**100) })
Expand Down
10 changes: 5 additions & 5 deletions spec/ruby/core/dir/glob_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@
ruby_version_is '3.1' do
it "recursively matches files and directories in nested dot subdirectory except . with 'nested/**/*' from the current directory and option File::FNM_DOTMATCH" do
expected = %w[
nested/.
nested/.dotsubir
nested/.dotsubir/.dotfile
nested/.dotsubir/nondotfile
]
nested/.
nested/.dotsubir
nested/.dotsubir/.dotfile
nested/.dotsubir/nondotfile
]

Dir.glob('nested/**/*', File::FNM_DOTMATCH).sort.should == expected.sort
end
Expand Down
12 changes: 10 additions & 2 deletions spec/ruby/core/exception/detailed_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
RuntimeError.new("new error").detailed_message.should == "new error (RuntimeError)"
end

it "is called by #full_message to allow message customization" do
exception = Exception.new("new error")
def exception.detailed_message(**)
"<prefix>#{message}<suffix>"
end
exception.full_message(highlight: false).should.include? "<prefix>new error<suffix>"
end

it "accepts highlight keyword argument and adds escape control sequences" do
RuntimeError.new("new error").detailed_message(highlight: true).should == "\e[1mnew error (\e[1;4mRuntimeError\e[m\e[1m)\e[m"
end
Expand All @@ -23,13 +31,13 @@
RuntimeError.new("").detailed_message.should == "unhandled exception"
end

it "returns just class name for an instance of RuntimeError sublass with empty message" do
it "returns just class name for an instance of RuntimeError subclass with empty message" do
DetailedMessageSpec::C.new("").detailed_message.should == "DetailedMessageSpec::C"
end

it "returns a generated class name for an instance of RuntimeError anonymous subclass with empty message" do
klass = Class.new(RuntimeError)
klass.new("").detailed_message.should =~ /\A#<Class:0x\h+>\z/
klass.new("").detailed_message.should =~ /\A#<Class:0x\h+>\z/
end
end
end
40 changes: 34 additions & 6 deletions spec/ruby/core/exception/full_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,49 @@
ruby_version_is "3.2" do
it "relies on #detailed_message" do
e = RuntimeError.new("new error")
e.define_singleton_method(:detailed_message) { |**opt| "DETAILED MESSAGE" }
e.define_singleton_method(:detailed_message) { |**| "DETAILED MESSAGE" }

e.full_message.lines.first.should =~ /DETAILED MESSAGE/
end

it "passes all its own keyword arguments to #detailed_message" do
it "passes all its own keyword arguments (with :highlight default value and without :order default value) to #detailed_message" do
e = RuntimeError.new("new error")
opt_ = nil
e.define_singleton_method(:detailed_message) do |**opt|
opt_ = opt
options_passed = nil
e.define_singleton_method(:detailed_message) do |**options|
options_passed = options
"DETAILED MESSAGE"
end

e.full_message(foo: "bar")
opt_.should == { foo: "bar", highlight: Exception.to_tty? }
options_passed.should == { foo: "bar", highlight: Exception.to_tty? }
end

it "converts #detailed_message returned value to String if it isn't a String" do
message = Object.new
def message.to_str; "DETAILED MESSAGE"; end

e = RuntimeError.new("new error")
e.define_singleton_method(:detailed_message) { |**| message }

e.full_message.lines.first.should =~ /DETAILED MESSAGE/
end

it "uses class name if #detailed_message returns nil" do
e = RuntimeError.new("new error")
e.define_singleton_method(:detailed_message) { |**| nil }

e.full_message(highlight: false).lines.first.should =~ /RuntimeError/
e.full_message(highlight: true).lines.first.should =~ /#{Regexp.escape("\e[1;4mRuntimeError\e[m")}/
end

it "uses class name if exception object doesn't respond to #detailed_message" do
e = RuntimeError.new("new error")
class << e
undef :detailed_message
end

e.full_message(highlight: false).lines.first.should =~ /RuntimeError/
e.full_message(highlight: true).lines.first.should =~ /#{Regexp.escape("\e[1;4mRuntimeError\e[m")}/
end
end
end
4 changes: 2 additions & 2 deletions spec/ruby/core/file/flock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
it "returns false if trying to lock an exclusively locked file" do
@file.flock File::LOCK_EX

ruby_exe(<<-END_OF_CODE, escape: true).should == "false"
ruby_exe(<<-END_OF_CODE).should == "false"
File.open('#{@name}', "w") do |f2|
print f2.flock(File::LOCK_EX | File::LOCK_NB).to_s
end
Expand All @@ -40,7 +40,7 @@
it "blocks if trying to lock an exclusively locked file" do
@file.flock File::LOCK_EX

out = ruby_exe(<<-END_OF_CODE, escape: true)
out = ruby_exe(<<-END_OF_CODE)
running = false
t = Thread.new do
Expand Down
6 changes: 6 additions & 0 deletions spec/ruby/core/file/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@
}.should raise_error(Errno::EEXIST, /File exists/)
end

it "does not use the given block and warns to use File::open" do
-> {
@fh = File.new(@file) { raise }
}.should complain(/warning: File::new\(\) does not take block; use File::open\(\) instead/)
end

it "raises a TypeError if the first parameter can't be coerced to a string" do
-> { File.new(true) }.should raise_error(TypeError)
-> { File.new(false) }.should raise_error(TypeError)
Expand Down
Loading

0 comments on commit ab4781b

Please sign in to comment.