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

Backport to 3.2 #1479

Merged
merged 4 commits into from
Aug 29, 2023
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
4 changes: 2 additions & 2 deletions core/fiber.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Fiber < Object
#
# See also Fiber::[]=.
#
def self.[]: (Symbol | String) -> untyped
def self.[]: (Symbol) -> untyped

# <!--
# rdoc-file=cont.c
Expand All @@ -99,7 +99,7 @@ class Fiber < Object
#
# See also Fiber::[].
#
def self.[]=: [A] (Symbol | String, A) -> A
def self.[]=: [A] (Symbol, A) -> A

# <!--
# rdoc-file=cont.c
Expand Down
9 changes: 6 additions & 3 deletions lib/rbs/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ def constant_entry(type_name)
end

def normalize_type_name?(name)
if name.class?
normalize_module_name?(name)
else
return normalize_module_name?(name) if name.class?

type_name =
unless name.namespace.empty?
parent = name.namespace.to_type_name
parent = normalize_module_name?(parent)
Expand All @@ -288,6 +288,9 @@ def normalize_type_name?(name)
else
name
end

if type_name?(type_name)
type_name
end
end

Expand Down
34 changes: 34 additions & 0 deletions test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,40 @@ def voice: [X] { () -> X } -> String
end
end

def test_undefined_interface
with_cli do |cli|
Dir.mktmpdir do |dir|
(Pathname(dir) + 'a.rbs').write(<<~RBS)
class Foo
def void: () -> _Void
end
RBS

error = assert_raises RBS::NoTypeFoundError do
cli.run(["-I", dir, "validate"])
end
assert_equal "_Void", error.type_name.to_s
end
end
end

def test_undefined_alias
with_cli do |cli|
Dir.mktmpdir do |dir|
(Pathname(dir) + 'a.rbs').write(<<~RBS)
class Foo
def void: () -> voida
end
RBS

error = assert_raises RBS::NoTypeFoundError do
cli.run(["-I", dir, "validate"])
end
assert_equal "voida", error.type_name.to_s
end
end
end

def test_constant
with_cli do |cli|
cli.run(%w(constant Pathname))
Expand Down
12 changes: 0 additions & 12 deletions test/stdlib/Fiber_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ def test_aref
"(Symbol) -> Integer",
Fiber, :[], :key
)

key = "string"

assert_send_type(
"(String, Integer) -> Integer",
Fiber, :[]=, key, 123
)

assert_send_type(
"(String) -> Integer",
Fiber, :[], key
)
end

def test_blocking?
Expand Down
5 changes: 1 addition & 4 deletions test/stdlib/Kernel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def (obj = BasicObject.new).inspect
def test_pp
pp
pp 1
pp 'a', 2
pp 'a', 2

pp Object.new
end
Expand Down Expand Up @@ -704,9 +704,6 @@ def o.divmod(i)
[0.001, 0.001]
end
sleep o

omit_if(RUBY_VERSION < "3.3.0")
sleep nil
end

def test_syscall
Expand Down
20 changes: 19 additions & 1 deletion test/stdlib/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ class Test::Unit::TestCase
prepend TestSkip
end

class Test::Unit::TestCase
module Printer
def setup
STDERR.puts name
super
end
end

# prepend Printer
end

module Spy
def self.wrap(object, method_name)
spy = WrapSpy.new(object: object, method_name: method_name)
Expand Down Expand Up @@ -460,7 +471,7 @@ def initialize(*args)
def to_ary
@args
end
end
end

class ToHash
def initialize(hash = { 'hello' => 'world' })
Expand Down Expand Up @@ -578,6 +589,11 @@ def self.hook
end
end

# def setup
# STDERR.puts name
# super
# end

def hook
self.class.hook
end
Expand All @@ -591,9 +607,11 @@ def setup
null = StringIO.new
@stdout, @stderr = $stdout, $stderr
$stderr = $stdout = null
super
end

def teardown
super
$stderr, $stdout = @stderr, @stdout
end
end
Expand Down
19 changes: 13 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,22 @@ def assert_sampling_check(builder, sample_size, array)
OptionParser.new do |opts|
opts.on("--name NAME") do |name|
name = name.gsub(/(\A\/)|(\/\Z)/, '')
klass_name, method_name = name.split("#", 2)

constant = (Object.const_get(name) rescue nil)
constant = ObjectSpace.each_object(Class).find do |klass|
if klass.name
klass.name == klass_name || klass.name.end_with?("::#{klass_name}")
end
end

if constant
test_unit_args << "--testcase"
test_unit_args << name
else
test_unit_args << "--name"
test_unit_args << name
if method_name
test_unit_args << "--name"
test_unit_args << "#{constant.name}##{method_name}"
else
test_unit_args << "--testcase"
test_unit_args << constant.name
end
end
end
end.order!(argv)
Expand Down
5 changes: 4 additions & 1 deletion test/test_skip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ def setup
end

def teardown
unless current_result.passed?
case
when passed?
# nop
else
puts "💡You can skip this test `#{name}` by adding the name to `#{SKIP_TESTS_FILE}`"
end

Expand Down