Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for ruby 3.4.0 #2181

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ['3.1', '3.2', '3.3', head]
ruby: ['3.1', '3.2', '3.3', '3.4.0-rc1', head]
rubyopt: [""]
job:
- test
include:
- ruby: head
job: stdlib_test rubocop
- ruby: "3.3"
- ruby: "3.4.0-rc1"
job: stdlib_test
- ruby: "3.3"
- ruby: "3.4.0-rc1"
job: test
rubyopt: "--enable-frozen-string-literal"
- ruby: "3.3"
- ruby: "3.4.0-rc1"
job: stdlib_test
rubyopt: "--enable-frozen-string-literal"
- ruby: "3.3"
- ruby: "3.4.0-rc1"
job: lexer templates compile confirm_lexer confirm_templates
- ruby: "3.3"
- ruby: "3.4.0-rc1"
job: rubocop validate test_doc build test_generate_stdlib raap
- ruby: "3.3"
- ruby: "3.4.0-rc1"
job: typecheck_test
env:
RANDOMIZE_STDLIB_TEST_ORDER: "true"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gem "test-unit"
gem "rspec"
gem "rubocop"
gem "rubocop-rubycw"
gem "rubocop-on-rbs" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1')
gem "rubocop-on-rbs"
gem "json"
gem "json-schema"
gem "goodcheck"
Expand Down
4 changes: 2 additions & 2 deletions bin/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
require "set"

IS_LATEST_RUBY = Gem::Version.new(RUBY_VERSION).yield_self do |ruby_version|
Gem::Version.new('3.3.0') <= ruby_version && ruby_version < Gem::Version.new('3.4.0')
Gem::Version.new('3.4.0') <= ruby_version && ruby_version < Gem::Version.new('3.5.0')
end

unless IS_LATEST_RUBY
unless ENV["CI"]
STDERR.puts "⚠️⚠️⚠️⚠️ stdlib test assumes Ruby 3.3 but RUBY_VERSION==#{RUBY_VERSION} ⚠️⚠️⚠️⚠️"
STDERR.puts "⚠️⚠️⚠️⚠️ stdlib test assumes Ruby 3.4 but RUBY_VERSION==#{RUBY_VERSION} ⚠️⚠️⚠️⚠️"
end
end

Expand Down
2 changes: 0 additions & 2 deletions lib/rbs/prototype/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,6 @@ def type_params(mod)
end

def block_from_ast_of(method)
return nil if RUBY_VERSION < '3.1'

begin
ast = RubyVM::AbstractSyntaxTree.of(method)
rescue ArgumentError
Expand Down
26 changes: 9 additions & 17 deletions test/rbs/rb_prototype_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -846,14 +846,8 @@ def test_duplicate_methods

rb = <<-'EOR'
class C
if RUBY_VERSION >= '2.7'
def foo(x, y, z)
do_something_27
end
else
def foo(x, y, z)
do_something
end
def foo(x, y, z)
do_something_27
end
end
EOR
Expand Down Expand Up @@ -1086,21 +1080,19 @@ def foo: (*untyped, **untyped) ?{ (?) -> untyped } -> nil
end
end

if RUBY_VERSION >= '3'
def test_endless_method_definition
parser = RB.new
rb = <<~'RUBY'
def test_endless_method_definition
parser = RB.new
rb = <<~'RUBY'
module M
def foo = 42
end
RUBY
parser.parse(rb)
RUBY
parser.parse(rb)

assert_write parser.decls, <<~RBS
assert_write parser.decls, <<~RBS
module M
def foo: () -> 42
end
RBS
end
RBS
end
end
71 changes: 22 additions & 49 deletions test/rbs/runtime_prototype_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,33 +241,6 @@ def test_decls_for_anonymous_class_or_module
end
end

if RUBY_VERSION >= '2.7' && RUBY_VERSION <= '3.0'
class TestForArgumentForwarding
eval <<~RUBY
def foo(...)
end
RUBY
end

def test_argument_forwarding
SignatureManager.new do |manager|
manager.build do |env|
p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::TestForArgumentForwarding"], env: env, merge: true)

assert_write p.decls, <<-EOF
module RBS
class RuntimePrototypeTest < ::Test::Unit::TestCase
class TestForArgumentForwarding
def foo: (*untyped) { (*untyped) -> untyped } -> untyped
end
end
end
EOF
end
end
end
end

module TestForOverrideModuleName
module M
def self.name() 'FakeNameM' end
Expand Down Expand Up @@ -389,35 +362,35 @@ def initialize: () -> void
end
end

if RUBY_VERSION >= '3.1' && RUBY_VERSION <= "3.3"
class TestForYield
def m1() yield end
def m2() yield 42 end
def m3() yield 42; yield 42, 43 end
eval 'def m4() yield end'
end
class TestForYield
def m1() yield end
def m2() yield 42 end
def m3() yield 42; yield 42, 43 end
eval 'def m4() yield end'
end

def test_for_yield
SignatureManager.new do |manager|
manager.build do |env|
p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::TestForYield"], env: env, merge: true)
def test_for_yield
omit "Ruby 3.4 uses Prism and needs migration" if RUBY_VERSION >= "3.4"

SignatureManager.new do |manager|
manager.build do |env|
p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::TestForYield"], env: env, merge: true)

assert_write p.decls, <<~RBS
module RBS
class RuntimePrototypeTest < ::Test::Unit::TestCase
class TestForYield
def m1: () { () -> untyped } -> untyped
assert_write p.decls, <<~RBS
module RBS
class RuntimePrototypeTest < ::Test::Unit::TestCase
class TestForYield
def m1: () { () -> untyped } -> untyped

def m2: () { (untyped) -> untyped } -> untyped
def m2: () { (untyped) -> untyped } -> untyped

def m3: () { (untyped, untyped) -> untyped } -> untyped
def m3: () { (untyped, untyped) -> untyped } -> untyped

def m4: () -> untyped
end
def m4: () -> untyped
end
end
RBS
end
end
RBS
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions test/rbs/test/hook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
require "rbs/test"
require "logger"

return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')

class RBS::Test::HookTest < Test::Unit::TestCase
class Example
def hello(x, y)
Expand Down
2 changes: 0 additions & 2 deletions test/rbs/test/type_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
require "rbs/test"
require "logger"

return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')

RSPEC_MOCK = -> { double('foo') }

class RBS::Test::TypeCheckTest < Test::Unit::TestCase
Expand Down
30 changes: 14 additions & 16 deletions test/stdlib/IO_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,24 +422,22 @@ class IOWaitTest < Test::Unit::TestCase
testing "::IO"

def test_readyp
if_ruby31 do
# This method returns true|false in Ruby 2.7, nil|IO in 3.0, and true|false in 3.1.
# This method returns true|false in Ruby 2.7, nil|IO in 3.0, and true|false in 3.1.

IO.pipe.tap do |r, w|
assert_send_type(
"() -> untyped",
r, :ready?
)
end
IO.pipe.tap do |r, w|
assert_send_type(
"() -> untyped",
r, :ready?
)
end

IO.pipe.tap do |r, w|
w.write("hello")
IO.pipe.tap do |r, w|
w.write("hello")

assert_send_type(
"() -> untyped",
r, :ready?
)
end
assert_send_type(
"() -> untyped",
r, :ready?
)
end
end

Expand Down Expand Up @@ -491,7 +489,7 @@ def test_nread
end

def test_wait
if_ruby "3.0.0"..."3.2.0" do
if_ruby "3.0.0"..."3.2.0", skip: false do
IO.pipe.tap do |r, w|
w.write("hello")

Expand Down
Loading
Loading