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

Migrate to test-unit to make test run on Ruby 3.1 #556

Merged
merged 13 commits into from
Dec 28, 2020
11 changes: 9 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
container_tag:
- master-nightly-focal
- 3.0-focal
- 2.7-bionic
job:
Expand All @@ -26,12 +27,18 @@ jobs:
run: |
apt-get update
apt-get install -y libdb-dev
- name: Install
- name: Install bundler
run: |
ruby -v
gem install bundler
- name: bundle config set with
run: |
echo "NO_MINITEST=true" >> $GITHUB_ENV
bundle config set --local without 'minitest'
if: "contains(matrix.container_tag, 'master-nightly')"
- name: bin/setup
run: |
bin/setup
- name: Run test
run: |
bundle exec rake ${{ matrix.job }}
if: "!(matrix.job == 'stdlib_test' && contains(matrix.container_tag, '2.6'))"
8 changes: 6 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ gemspec

# Development dependencies
gem "rake"
gem "minitest"
gem "test-unit"
gem "test-unit-rr"
gem "rspec"
gem "racc"
gem "rubocop"
gem "rubocop-rubycw"
gem "minitest-reporters"
gem "json"
gem "json-schema"
gem 'stackprof'
Expand All @@ -23,3 +23,7 @@ gem "rbs-amber", path: "test/assets/test-gem"
group :ide, optional: true do
gem "ruby-debug-ide"
end

group :minitest do
gem "minitest"
end
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace :generate do
require_relative "test_helper"

<%- unless class_methods.empty? -%>
class <%= klass %>SingletonTest < Minitest::Test
class <%= klass %>SingletonTest < Test::Unit::TestCase
include TypeAssertions

# library "pathname", "set", "securerandom" # Declare library signatures to load
Expand All @@ -133,7 +133,7 @@ namespace :generate do
<%- end -%>

<%- unless instance_methods.empty? -%>
class <%= klass %>Test < Minitest::Test
class <%= klass %>Test < Test::Unit::TestCase
include TypeAssertions

# library "pathname", "set", "securerandom" # Declare library signatures to load
Expand Down
9 changes: 4 additions & 5 deletions bin/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

require "set"

IS_RUBY_27 = Gem::Version.new(RUBY_VERSION).yield_self do |ruby_version|
Gem::Version.new('2.7.0') <= ruby_version &&
ruby_version <= Gem::Version.new('2.8.0')
IS_LATEST_RUBY = Gem::Version.new(RUBY_VERSION).yield_self do |ruby_version|
Gem::Version.new('3.0.0') <= ruby_version && ruby_version < Gem::Version.new('3.1.0')
end

unless IS_RUBY_27
STDERR.puts "⚠️⚠️⚠️⚠️ stdlib test assumes Ruby 2.7 but RUBY_VERSION==#{RUBY_VERSION} ⚠️⚠️⚠️⚠️"
unless IS_LATEST_RUBY
STDERR.puts "⚠️⚠️⚠️⚠️ stdlib test assumes Ruby 3.0 but RUBY_VERSION==#{RUBY_VERSION} ⚠️⚠️⚠️⚠️"
end

KNOWN_FAILS = %w(dbm).map do |lib|
Expand Down
2 changes: 1 addition & 1 deletion goodcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ rules:
end
pass:
- |
class IntegerTest < Minitest::Test
class IntegerTest < Test::Unit::TestCase
include TypeAssertions

testing "Integer"
Expand Down
1 change: 0 additions & 1 deletion lib/rbs/test/setup_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def to_double_class(double_suite)
nil
end
end

end
end
end
2 changes: 1 addition & 1 deletion test/assets/test1/hello.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(name:, email:)
end
end

class Kaigi::ConferenceTest < Minitest::Test
class Kaigi::ConferenceTest < Test::Unit::TestCase
def test_1
conference = Kaigi::Conference.new

Expand Down
2 changes: 1 addition & 1 deletion test/rbs/ancestor_builder_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::AncestorBuilderTest < Minitest::Test
class RBS::AncestorBuilderTest < Test::Unit::TestCase
include TestHelper

AST = RBS::AST
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/buffer_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::BufferTest < Minitest::Test
class RBS::BufferTest < Test::Unit::TestCase
Buffer = RBS::Buffer

def test_buffer
Expand Down
8 changes: 4 additions & 4 deletions test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "stringio"
require "rbs/cli"

class RBS::CliTest < Minitest::Test
class RBS::CliTest < Test::Unit::TestCase
include TestHelper

CLI = RBS::CLI
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_paths
end

def test_paths_with_gem
skip unless has_gem?("rbs-amber")
omit unless has_gem?("rbs-amber")

with_cli do |cli|
cli.run(%w(-r rbs-amber paths))
Expand All @@ -223,14 +223,14 @@ def test_vendor
with_cli do |cli|
cli.run(%w(vendor --vendor-dir=dir1))

assert_operator Pathname(d) + "dir1/core", :directory?
assert_predicate Pathname(d) + "dir1/core", :directory?
end
end
end
end

def test_vendor_gem
skip unless has_gem?("rbs-amber")
omit unless has_gem?("rbs-amber")

Dir.mktmpdir do |d|
Dir.chdir(d) do
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/comment_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::CommentTest < Minitest::Test
class RBS::CommentTest < Test::Unit::TestCase
include TestHelper

def test_concat
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/constant_table_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::ConstantTableTest < Minitest::Test
class RBS::ConstantTableTest < Test::Unit::TestCase
include TestHelper

ConstantTable = RBS::ConstantTable
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/definition_builder_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::DefinitionBuilderTest < Minitest::Test
class RBS::DefinitionBuilderTest < Test::Unit::TestCase
include TestHelper

AST = RBS::AST
Expand Down
6 changes: 3 additions & 3 deletions test/rbs/environment_loader_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::EnvironmentLoaderTest < Minitest::Test
class RBS::EnvironmentLoaderTest < Test::Unit::TestCase
include TestHelper

Environment = RBS::Environment
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_loading_twice
end

def test_loading_from_gem
skip unless has_gem?("rbs-amber")
omit unless has_gem?("rbs-amber")

mktmpdir do |path|
repo = RBS::Repository.new()
Expand All @@ -149,7 +149,7 @@ def test_loading_from_gem
end

def test_loading_from_gem_without_rbs
skip unless has_gem?("minitest")
omit if skip_minitest?

mktmpdir do |path|
repo = RBS::Repository.new()
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/environment_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::EnvironmentTest < Minitest::Test
class RBS::EnvironmentTest < Test::Unit::TestCase
include TestHelper

Environment = RBS::Environment
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/environment_walker_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::EnvironmentWalkerTest < Minitest::Test
class RBS::EnvironmentWalkerTest < Test::Unit::TestCase
include TestHelper

Environment = RBS::Environment
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/factory_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::FactoryTest < Minitest::Test
class RBS::FactoryTest < Test::Unit::TestCase
include TestHelper

def test_type_name
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/location_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::LocationTest < Minitest::Test
class RBS::LocationTest < Test::Unit::TestCase
Buffer = RBS::Buffer
Location = RBS::Location

Expand Down
2 changes: 1 addition & 1 deletion test/rbs/method_builder_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::MethodBuilderTest < Minitest::Test
class RBS::MethodBuilderTest < Test::Unit::TestCase
include TestHelper

AST = RBS::AST
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/method_type_parsing_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::MethodTypeParsingTest < Minitest::Test
class RBS::MethodTypeParsingTest < Test::Unit::TestCase
Parser = RBS::Parser
Buffer = RBS::Buffer
Types = RBS::Types
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/rb_prototype_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::RbPrototypeTest < Minitest::Test
class RBS::RbPrototypeTest < Test::Unit::TestCase
RB = RBS::Prototype::RB

include TestHelper
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/rbi_prototype_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::RbiPrototypeTest < Minitest::Test
class RBS::RbiPrototypeTest < Test::Unit::TestCase
RBI = RBS::Prototype::RBI

include TestHelper
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/repository_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::RepositoryTest < Minitest::Test
class RBS::RepositoryTest < Test::Unit::TestCase
Repository = RBS::Repository

def dir
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/runtime_prototype_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::RuntimePrototypeTest < Minitest::Test
class RBS::RuntimePrototypeTest < Test::Unit::TestCase
Runtime = RBS::Prototype::Runtime
DefinitionBuilder = RBS::DefinitionBuilder

Expand Down
2 changes: 1 addition & 1 deletion test/rbs/schema_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "test_helper"
require "json_validator"

class RBS::SchemaTest < Minitest::Test
class RBS::SchemaTest < Test::Unit::TestCase
include TestHelper

def test_location_schema
Expand Down
8 changes: 4 additions & 4 deletions test/rbs/signature_parsing_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class RBS::SignatureParsingTest < Minitest::Test
class RBS::SignatureParsingTest < Test::Unit::TestCase
Parser = RBS::Parser
Buffer = RBS::Buffer
Types = RBS::Types
Expand Down Expand Up @@ -1079,12 +1079,12 @@ def to_i: () -> Integer
EOF
decls[0].members[0].tap do |member|
assert_instance_of Members::MethodDefinition, member
assert_operator member, :overload?
assert_predicate member, :overload?
end

decls[0].members[1].tap do |member|
assert_instance_of Members::MethodDefinition, member
refute_operator member, :overload?
refute_predicate member, :overload?
end
end
end
Expand All @@ -1098,7 +1098,7 @@ module Steep
EOF
decls[0].members[0].tap do |member|
assert_instance_of Members::MethodDefinition, member
assert_operator member, :overload?
assert_predicate member, :overload?
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions test/rbs/test/hook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

class RBS::Test::HookTest < Minitest::Test
class RBS::Test::HookTest < Test::Unit::TestCase
class Example
def hello(x, y)
raise "Aborting" if y == 0
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_hook_operator
traces[0].tap do |t|
assert_instance_of RBS::Test::CallTrace, t
assert_equal :+, t.method_name
assert_operator t.method_call, :return?
assert_predicate t.method_call, :return?
assert_equal [30], t.method_call.arguments
assert_equal :plus, t.method_call.return_value
end
Expand All @@ -79,7 +79,7 @@ def test_hook_no_block_no_exn
traces[0].tap do |t|
assert_instance_of RBS::Test::CallTrace, t
assert_equal :hello, t.method_name
assert_operator t.method_call, :return?
assert_predicate t.method_call, :return?
assert_equal [1,2], t.method_call.arguments
assert_equal 3, t.method_call.return_value
end
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_hook_no_block_exn
assert_instance_of RBS::Test::CallTrace, t
assert_equal :hello, t.method_name
assert_equal [1, 0], t.method_call.arguments
assert_operator t.method_call, :exception?
assert_predicate t.method_call, :exception?
assert_instance_of RuntimeError, t.method_call.exception
assert_equal "Aborting", t.method_call.exception.message
end
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_hook_with_block

assert_equal :world, t.method_name

assert_operator t.method_call, :return?
assert_predicate t.method_call, :return?
assert_equal [1,2], t.method_call.arguments
assert_equal :world, t.method_call.return_value

Expand Down Expand Up @@ -205,10 +205,10 @@ def test_hook_singleton_method

assert_equal :foo, t.method_name

assert_operator t.method_call, :return?
assert_predicate t.method_call, :return?
assert_equal [{ x: "x", hello: :world }], t.method_call.arguments
assert_equal "x", t.method_call.return_value
assert_operator t, :block_given
assert_predicate t, :block_given
assert_empty t.block_calls
end
end
Expand Down
Loading