diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index dce16c017..55125be15 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -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" diff --git a/Gemfile b/Gemfile index 0220f9792..b47b73cc3 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/bin/test_runner.rb b/bin/test_runner.rb index 05af15b06..c63113ba3 100755 --- a/bin/test_runner.rb +++ b/bin/test_runner.rb @@ -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 diff --git a/lib/rbs/prototype/runtime.rb b/lib/rbs/prototype/runtime.rb index 60b417b44..a6aad3634 100644 --- a/lib/rbs/prototype/runtime.rb +++ b/lib/rbs/prototype/runtime.rb @@ -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 diff --git a/test/rbs/rb_prototype_test.rb b/test/rbs/rb_prototype_test.rb index 0a35ef40b..23c6f5fec 100644 --- a/test/rbs/rb_prototype_test.rb +++ b/test/rbs/rb_prototype_test.rb @@ -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 @@ -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 diff --git a/test/rbs/runtime_prototype_test.rb b/test/rbs/runtime_prototype_test.rb index ddf97d9ad..dd10fbdbb 100644 --- a/test/rbs/runtime_prototype_test.rb +++ b/test/rbs/runtime_prototype_test.rb @@ -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 @@ -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 diff --git a/test/rbs/test/hook_test.rb b/test/rbs/test/hook_test.rb index a783d0fbc..2685f918b 100644 --- a/test/rbs/test/hook_test.rb +++ b/test/rbs/test/hook_test.rb @@ -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) diff --git a/test/rbs/test/type_check_test.rb b/test/rbs/test/type_check_test.rb index 40c852dfa..7e62be648 100644 --- a/test/rbs/test/type_check_test.rb +++ b/test/rbs/test/type_check_test.rb @@ -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 diff --git a/test/stdlib/IO_test.rb b/test/stdlib/IO_test.rb index 90a820e1d..91f456f65 100644 --- a/test/stdlib/IO_test.rb +++ b/test/stdlib/IO_test.rb @@ -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 @@ -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") diff --git a/test/stdlib/Module_test.rb b/test/stdlib/Module_test.rb index ff37178e4..b1f1cce48 100644 --- a/test/stdlib/Module_test.rb +++ b/test/stdlib/Module_test.rb @@ -318,106 +318,98 @@ def self.bar; end end def test_attr - if RUBY_VERSION >= '3.0' - mod = Module.new - assert_send_type( - "(*interned arg0) -> Array[Symbol]", - mod, :attr, :foo - ) - end + mod = Module.new + assert_send_type( + "(*interned arg0) -> Array[Symbol]", + mod, :attr, :foo + ) end def test_attr_reader - if RUBY_VERSION >= '3.0' - mod = Module.new + mod = Module.new - assert_send_type( - "(Symbol) -> Array[Symbol]", - mod, :attr_reader, :foo - ) + assert_send_type( + "(Symbol) -> Array[Symbol]", + mod, :attr_reader, :foo + ) - assert_send_type( - "(Symbol, Symbol) -> Array[Symbol]", - mod, :attr_reader, :foo, :bar - ) + assert_send_type( + "(Symbol, Symbol) -> Array[Symbol]", + mod, :attr_reader, :foo, :bar + ) - assert_send_type( - "(String) -> Array[Symbol]", - mod, :attr_reader, "foo" - ) + assert_send_type( + "(String) -> Array[Symbol]", + mod, :attr_reader, "foo" + ) - assert_send_type( - "(String, String) -> Array[Symbol]", - mod, :attr_reader, "foo", "bar" - ) + assert_send_type( + "(String, String) -> Array[Symbol]", + mod, :attr_reader, "foo", "bar" + ) - assert_send_type( - "(Symbol, String) -> Array[Symbol]", - mod, :attr_reader, :foo, "bar" - ) - end + assert_send_type( + "(Symbol, String) -> Array[Symbol]", + mod, :attr_reader, :foo, "bar" + ) end def test_attr_writer - if RUBY_VERSION >= '3.0' - mod = Module.new + mod = Module.new - assert_send_type( - "(Symbol) -> Array[Symbol]", - mod, :attr_writer, :foo - ) + assert_send_type( + "(Symbol) -> Array[Symbol]", + mod, :attr_writer, :foo + ) - assert_send_type( - "(Symbol, Symbol) -> Array[Symbol]", - mod, :attr_writer, :foo, :bar - ) + assert_send_type( + "(Symbol, Symbol) -> Array[Symbol]", + mod, :attr_writer, :foo, :bar + ) - assert_send_type( - "(String) -> Array[Symbol]", - mod, :attr_writer, "foo" - ) + assert_send_type( + "(String) -> Array[Symbol]", + mod, :attr_writer, "foo" + ) - assert_send_type( - "(String, String) -> Array[Symbol]", - mod, :attr_writer, "foo", "bar" - ) + assert_send_type( + "(String, String) -> Array[Symbol]", + mod, :attr_writer, "foo", "bar" + ) - assert_send_type( - "(Symbol, String) -> Array[Symbol]", - mod, :attr_writer, :foo, "bar" - ) - end + assert_send_type( + "(Symbol, String) -> Array[Symbol]", + mod, :attr_writer, :foo, "bar" + ) end def test_attr_accessor - if RUBY_VERSION >= '3.0' - mod = Module.new + mod = Module.new - assert_send_type( - "(Symbol) -> Array[Symbol]", - mod, :attr_accessor, :foo - ) + assert_send_type( + "(Symbol) -> Array[Symbol]", + mod, :attr_accessor, :foo + ) - assert_send_type( - "(Symbol, Symbol) -> Array[Symbol]", - mod, :attr_accessor, :foo, :bar - ) + assert_send_type( + "(Symbol, Symbol) -> Array[Symbol]", + mod, :attr_accessor, :foo, :bar + ) - assert_send_type( - "(String) -> Array[Symbol]", - mod, :attr_accessor, "foo" - ) + assert_send_type( + "(String) -> Array[Symbol]", + mod, :attr_accessor, "foo" + ) - assert_send_type( - "(String, String) -> Array[Symbol]", - mod, :attr_accessor, "foo", "bar" - ) + assert_send_type( + "(String, String) -> Array[Symbol]", + mod, :attr_accessor, "foo", "bar" + ) - assert_send_type( - "(Symbol, String) -> Array[Symbol]", - mod, :attr_accessor, :foo, "bar" - ) - end + assert_send_type( + "(Symbol, String) -> Array[Symbol]", + mod, :attr_accessor, :foo, "bar" + ) end def test_set_temporary_name diff --git a/test/stdlib/Net_HTTP_test.rb b/test/stdlib/Net_HTTP_test.rb index 9b75b4bc7..c30253d10 100644 --- a/test/stdlib/Net_HTTP_test.rb +++ b/test/stdlib/Net_HTTP_test.rb @@ -15,25 +15,25 @@ def test_get assert_send_type "(String, String) -> nil", Net::HTTP, :get_print, 'www.ruby-lang.org', '/en' assert_send_type "(URI::Generic, Hash[String, String]) -> nil", - Net::HTTP, :get_print, URI("https://www.ruby-lang.org"), {"Accept" => "text/html"} if RUBY_VERSION >= '3.0' + Net::HTTP, :get_print, URI("https://www.ruby-lang.org"), {"Accept" => "text/html"} assert_send_type "(URI::Generic, Hash[Symbol, String]) -> nil", - Net::HTTP, :get_print, URI("https://www.ruby-lang.org"), {Accept: "text/html"} if RUBY_VERSION >= '3.0' + Net::HTTP, :get_print, URI("https://www.ruby-lang.org"), {Accept: "text/html"} assert_send_type "(URI::Generic) -> String", Net::HTTP, :get, URI("https://www.ruby-lang.org") assert_send_type "(String, String) -> String", Net::HTTP, :get, 'www.ruby-lang.org', '/en' assert_send_type "(URI::Generic, Hash[String, String]) -> String", - Net::HTTP, :get, URI("https://www.ruby-lang.org"), {"Accept" => "text/html"} if RUBY_VERSION >= '3.0' + Net::HTTP, :get, URI("https://www.ruby-lang.org"), {"Accept" => "text/html"} assert_send_type "(URI::Generic, Hash[Symbol, String]) -> String", - Net::HTTP, :get, URI("https://www.ruby-lang.org"), {Accept: "text/html"} if RUBY_VERSION >= '3.0' + Net::HTTP, :get, URI("https://www.ruby-lang.org"), {Accept: "text/html"} assert_send_type "(URI::Generic) -> Net::HTTPResponse", Net::HTTP, :get_response, URI("https://www.ruby-lang.org") assert_send_type "(String, String) -> Net::HTTPResponse", Net::HTTP, :get_response, 'www.ruby-lang.org', '/en' assert_send_type "(URI::Generic, Hash[String, String]) -> Net::HTTPResponse", - Net::HTTP, :get_response, URI("https://www.ruby-lang.org"), {"Accept" => "text/html"} if RUBY_VERSION >= '3.0' + Net::HTTP, :get_response, URI("https://www.ruby-lang.org"), {"Accept" => "text/html"} assert_send_type "(URI::Generic, Hash[Symbol, String]) -> Net::HTTPResponse", - Net::HTTP, :get_response, URI("https://www.ruby-lang.org"), {Accept: "text/html"} if RUBY_VERSION >= '3.0' + Net::HTTP, :get_response, URI("https://www.ruby-lang.org"), {Accept: "text/html"} ensure $stdout = STDOUT end diff --git a/test/stdlib/Ractor_test.rb b/test/stdlib/Ractor_test.rb index b5f996681..b16167022 100644 --- a/test/stdlib/Ractor_test.rb +++ b/test/stdlib/Ractor_test.rb @@ -1,10 +1,5 @@ require_relative "test_helper" -if RUBY_VERSION < '3' - warn 'Ractor is not available on Ruby 2🐫 Skip the test' - return -end - class RactorSingletonTest < Test::Unit::TestCase include TestHelper diff --git a/test/stdlib/Range_test.rb b/test/stdlib/Range_test.rb index f91dd7ce7..070adfc11 100644 --- a/test/stdlib/Range_test.rb +++ b/test/stdlib/Range_test.rb @@ -96,7 +96,7 @@ def test_min def test_percent (1..10).%(2) - if_ruby(..."3.4.0") do + if_ruby(..."3.4.0", skip: false) do ('A'...'Z').%(2) { |s| s.downcase } end end @@ -110,7 +110,7 @@ def test_size def test_step (1..10).step (1..10).step(2) - if_ruby(..."3.4.0") do + if_ruby(..."3.4.0", skip: false) do ('A'...'Z').step { |s| s.downcase } ('A'...'Z').step(2) { |s| s.downcase } end diff --git a/test/stdlib/String_test.rb b/test/stdlib/String_test.rb index 60795707c..e9afa2804 100644 --- a/test/stdlib/String_test.rb +++ b/test/stdlib/String_test.rb @@ -1695,8 +1695,6 @@ def test_unpack assert_send_type '(string) { (Integer | Float | String | nil) -> void } -> nil', packed, :unpack, template do end - next if RUBY_VERSION < '3.1' - with_int 0 do |offset| assert_send_type '(string, offset: int) -> Array[Integer | Float | String | nil]', packed, :unpack, template, offset: offset @@ -1714,8 +1712,6 @@ def test_unpack1 assert_send_type "(string) -> #{type}", packed, :unpack1, template_string - next if RUBY_VERSION < '3.1' - with_int 0 do |offset| assert_send_type "(string, offset: int) -> #{type}", packed, :unpack1, template_string, offset: offset diff --git a/test/stdlib/UnboundMethod_test.rb b/test/stdlib/UnboundMethod_test.rb index 69d4e1417..8f9f65f13 100644 --- a/test/stdlib/UnboundMethod_test.rb +++ b/test/stdlib/UnboundMethod_test.rb @@ -13,7 +13,7 @@ def all_params(a, b=3, *c, d: 1, e:, **f, &g) end def only_ddd(...) end def tailing_ddd(a, ...) end def no_kwargs(**nil) end - eval "def shorthand(*, **, &) end" unless RUBY_VERSION < '3.1' + eval "def shorthand(*, **, &) end" end def test_eq @@ -84,8 +84,6 @@ def test_parameters assert_send_type '() -> ::Method::param_types', ParamMeths.instance_method(:no_kwargs), :parameters - omit_if(RUBY_VERSION < '3.1') - assert_send_type '() -> ::Method::param_types', ParamMeths.instance_method(:shorthand), :parameters end diff --git a/test/stdlib/Warning_test.rb b/test/stdlib/Warning_test.rb index 901a8e197..d66fbe01a 100644 --- a/test/stdlib/Warning_test.rb +++ b/test/stdlib/Warning_test.rb @@ -57,8 +57,6 @@ def test_warn assert_send_type "(::String) -> nil", TestClass.new, :warn, 'message' - omit_if(RUBY_VERSION < "3.0") - WARNING_CATEGORIES.each do |category| assert_send_type "(::String, category: #{category.inspect}) -> nil", Warning, :warn, 'message', category: category diff --git a/test/stdlib/test_helper.rb b/test/stdlib/test_helper.rb index 541261b73..beea49803 100644 --- a/test/stdlib/test_helper.rb +++ b/test/stdlib/test_helper.rb @@ -23,7 +23,7 @@ def setup end module VersionHelper - def if_ruby(range) + def if_ruby(range, skip: true) r = Range.new( range.begin&.yield_self {|b| Gem::Version.new(b) }, range.end&.yield_self {|e| Gem::Version.new(e) }, @@ -33,27 +33,17 @@ def if_ruby(range) if r === Gem::Version.new(RUBY_VERSION) yield else - notify "Skipping test: #{r} !== #{RUBY_VERSION}" + if skip + notify "Skipping test: #{r} !== #{RUBY_VERSION}" + end end end - - def if_ruby3(&block) - if_ruby("3.0.0"..."4.0.0", &block) - end - - def if_ruby30(&block) - if_ruby("3.0.0"..."3.1.0", &block) - end - - def if_ruby31(&block) - if_ruby("3.1.0"..."3.2.0", &block) - end end module WithStdlibAliases def with_timeout(seconds: 1, nanoseconds: 0) unless block_given? - return RBS::UnitTest::Convertibles::WithAliases::WithEnum.new( + return RBS::UnitTest::WithAliases::WithEnum.new( to_enum(__method__, seconds: seconds, nanoseconds: nanoseconds) ) end