Skip to content

Commit

Permalink
[GR-14806] Update ruby/spec
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4442
  • Loading branch information
andrykonchin committed Jan 7, 2025
2 parents d4d37ce + bff2520 commit b709cfb
Show file tree
Hide file tree
Showing 83 changed files with 1,300 additions and 1,374 deletions.
3 changes: 3 additions & 0 deletions spec/mspec/lib/mspec/commands/mspec-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def options(argv = ARGV)
options.doc "\n When to perform it"
options.action_filters

options.doc "\n Launchable"
options.launchable

options.doc "\n Help!"
options.debug
options.version MSpec::VERSION
Expand Down
88 changes: 88 additions & 0 deletions spec/mspec/lib/mspec/runner/formatters/launchable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
module LaunchableFormatter
def self.extend_object(obj)
super
obj.init
end

def self.setDir(dir)
@@path = File.join(dir, "#{rand.to_s}.json")
self
end

def init
@timer = nil
@tests = []
end

def before(state = nil)
super
@timer = TimerAction.new
@timer.start
end

def after(state = nil)
super
@timer.finish
file = MSpec.file
return if file.nil? || state&.example.nil? || exception?

@tests << {:test => state, :file => file, :exception => false, duration: @timer.elapsed}
end

def exception(exception)
super
@timer.finish
file = MSpec.file
return if file.nil?

@tests << {:test => exception, :file => file, :exception => true, duration: @timer.elapsed}
end

def finish
super

require_relative '../../../../../../tool/lib/launchable'

@writer = writer = Launchable::JsonStreamWriter.new(@@path)
@writer.write_array('testCases')
at_exit {
@writer.close
}

repo_path = File.expand_path("#{__dir__}/../../../../../../")

@tests.each do |t|
testcase = t[:test].description
relative_path = t[:file].delete_prefix("#{repo_path}/")
# The test path is a URL-encoded representation.
# https://github.com/launchableinc/cli/blob/v1.81.0/launchable/testpath.py#L18
test_path = {file: relative_path, testcase: testcase}.map{|key, val|
"#{encode_test_path_component(key)}=#{encode_test_path_component(val)}"
}.join('#')

status = 'TEST_PASSED'
if t[:exception]
message = t[:test].message
backtrace = t[:test].backtrace
e = "#{message}\n#{backtrace}"
status = 'TEST_FAILED'
end

@writer.write_object(
{
testPath: test_path,
status: status,
duration: t[:duration],
createdAt: Time.now.to_s,
stderr: e,
stdout: nil
}
)
end
end

private
def encode_test_path_component component
component.to_s.gsub('%', '%25').gsub('=', '%3D').gsub('#', '%23').gsub('&', '%26').tr("\x00-\x08", "")
end
end
9 changes: 9 additions & 0 deletions spec/mspec/lib/mspec/utils/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ def debug
end
end

def launchable
on("--launchable-test-reports", "DIR",
"DIR The directory for reporting test results in Launchable JSON format") do |o|
require 'mspec/runner/formatters/launchable'
config[:launchable] = LaunchableFormatter.setDir(o)
end
end

def all
configure {}
env
Expand All @@ -508,5 +516,6 @@ def all
action_filters
actions
debug
launchable
end
end
8 changes: 7 additions & 1 deletion spec/mspec/lib/mspec/utils/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,14 @@ def config_formatter
end

if config[:formatter]
config[:formatter].new(config[:output])
config[:formatter] = config[:formatter].new(config[:output])
end

if config[:launchable]
config[:formatter].extend config[:launchable]
end

config[:formatter]
end

# Callback for enabling custom actions, etc. This version is a
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ Also `have_constant`, `have_private_instance_method`, `have_singleton_method`, e
}
```

##### should_not raise_error
##### `should_not raise_error`

**To avoid!** Instead, use an expectation testing what the code in the lambda does.
**Avoid this!** Instead, use an expectation testing what the code in the lambda does.
If an exception is raised, it will fail the example anyway.

```ruby
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ For *testing* the development version of a Ruby implementation, one should alway
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).
Running specs on a Ruby implementation can be done with:

```
```console
$ cd ruby_implementation/spec/ruby
# Add ../ruby_implementation/bin in PATH, or pass -t /path/to/bin/ruby
$ ../mspec/bin/mspec
Expand Down
22 changes: 18 additions & 4 deletions spec/ruby/core/dir/close_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@

it "does not raise an IOError even if the Dir instance is closed" do
dir = Dir.open DirSpecs.mock_dir
dir.close
dir.close
dir.close.should == nil
dir.close.should == nil

-> { dir.fileno }.should raise_error(IOError, /closed directory/)
guard -> { dir.respond_to? :fileno } do
-> { dir.fileno }.should raise_error(IOError, /closed directory/)
end
end

it "returns nil" do
dir = Dir.open DirSpecs.mock_dir
dir.close.should == nil
end

ruby_version_is '3.3' do
ruby_version_is '3.3'...'3.4' do
guard -> { Dir.respond_to? :for_fd } do
it "does not raise an error even if the file descriptor is closed with another Dir instance" do
dir = Dir.open DirSpecs.mock_dir
Expand All @@ -36,4 +38,16 @@
end
end
end

ruby_version_is '3.4' do
guard -> { Dir.respond_to? :for_fd } do
it "raises an error if the file descriptor is closed with another Dir instance" do
dir = Dir.open DirSpecs.mock_dir
dir_new = Dir.for_fd(dir.fileno)
dir.close

-> { dir_new.close }.should raise_error(Errno::EBADF, 'Bad file descriptor - closedir')
end
end
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerator/each_with_index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../spec_helper'
require_relative '../../shared/enumerator/with_index'
require_relative 'shared/with_index'
require_relative '../enumerable/shared/enumeratorized'

describe "Enumerator#each_with_index" do
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerator/each_with_object_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../spec_helper'
require_relative '../../shared/enumerator/with_object'
require_relative 'shared/with_object'

describe "Enumerator#each_with_object" do
it_behaves_like :enum_with_object, :each_with_object
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerator/enum_for_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../spec_helper'
require_relative '../../shared/enumerator/enum_for'
require_relative 'shared/enum_for'

describe "Enumerator#enum_for" do
it_behaves_like :enum_for, :enum_for
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require_relative '../../spec_helper'
require_relative '../../../spec_helper'

describe :enum_with_index, shared: true do

require_relative '../../fixtures/enumerator/classes'
require_relative '../fixtures/classes'

before :each do
@origin = [1, 2, 3, 4]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../../spec_helper'
require_relative '../../../spec_helper'

describe :enum_with_object, shared: true do
before :each do
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/core/enumerator/to_enum_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative '../../spec_helper'
require_relative '../../shared/enumerator/enum_for'
require_relative 'shared/enum_for'

describe "Enumerator#to_enum" do
it_behaves_like :enum_for, :enum_for
it_behaves_like :enum_for, :to_enum
end
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerator/with_index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../spec_helper'
require_relative '../../shared/enumerator/with_index'
require_relative 'shared/with_index'
require_relative '../enumerable/shared/enumeratorized'

describe "Enumerator#with_index" do
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerator/with_object_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../spec_helper'
require_relative '../../shared/enumerator/with_object'
require_relative 'shared/with_object'

describe "Enumerator#with_object" do
it_behaves_like :enum_with_object, :with_object
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/env/inspect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

it "returns a String that looks like a Hash with real data" do
ENV["foo"] = "bar"
ENV.inspect.should =~ /\{.*"foo"=>"bar".*\}/
ENV.inspect.should =~ /\{.*"foo" *=> *"bar".*\}/
ENV.delete "foo"
end

Expand Down
12 changes: 7 additions & 5 deletions spec/ruby/core/fiber/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@
key = :"#{self.class.name}#.#{self.object_id}"
Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
end
end

it "can't use invalid keys" do
invalid_keys = [Object.new, "Foo", 12]
invalid_keys.each do |key|
-> { Fiber[key] }.should raise_error(TypeError)
end
ruby_bug "#20978", "3.2"..."3.4" do
it "can use keys as strings" do
key = Object.new
def key.to_str; "Foo"; end
Fiber[key] = 42
Fiber["Foo"].should == 42
end
end

Expand Down
Loading

0 comments on commit b709cfb

Please sign in to comment.