Skip to content

Commit

Permalink
Merge pull request #177 from soutaro/fix-validation
Browse files Browse the repository at this point in the history
Fix signature validation
  • Loading branch information
soutaro authored Aug 2, 2020
2 parents dfc367b + 77540a5 commit 4d7f122
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/steep/server/signature_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def validate_signature(target, timestamp:)
target.signature_files.each_key.with_object({}) do |path, hash|
hash[path] = []
end
when Project::Target::SignatureOtherErrorStatus
Steep.log_error status.error
{}
else
Steep.logger.info "Unexpected target status: #{status.class}"
{}
Expand Down
6 changes: 5 additions & 1 deletion lib/steep/signature/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def validate
validate_decl
validate_const
validate_global
validate_alias
end

def validate_type(type)
Expand Down Expand Up @@ -99,6 +100,7 @@ def validate_const
env.constant_decls.each do |name, entry|
rescue_validation_errors do
Steep.logger.debug "Validating constant `#{name}`..."
builder.ensure_namespace!(name.namespace, location: entry.decl.location)
validate_type entry.decl.type
end
end
Expand All @@ -117,7 +119,9 @@ def validate_alias
env.alias_decls.each do |name, entry|
rescue_validation_errors do
Steep.logger.debug "Validating alias `#{name}`..."
validate_type(entry.decl.type)
builder.expand_alias(name).tap do |type|
validate_type(type)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion steep.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "rainbow", ">= 2.2.2", "< 4.0"
spec.add_runtime_dependency "listen", "~> 3.1"
spec.add_runtime_dependency "language_server-protocol", "~> 3.14.0.2"
spec.add_runtime_dependency "rbs", "~> 0.8.0"
spec.add_runtime_dependency "rbs", "~> 0.9.0"
end
6 changes: 6 additions & 0 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,10 @@ class Address
def test_class_constructor_nested
with_checker <<-EOF do |checker|
class Steep::Names::Module end
module Steep
class Names
end
end
EOF
source = parse_ruby("module Steep; class Names::Module; end; end")

Expand Down Expand Up @@ -1120,6 +1124,8 @@ module Rails end
def test_module_constructor_nested
with_checker <<-EOS do |checker|
module Steep::Printable end
class Steep end
EOS
source = parse_ruby("class Steep; module Printable; end; end")

Expand Down
45 changes: 45 additions & 0 deletions test/validation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,51 @@ class Foo
end
end

def test_outer_namespace
with_checker <<-EOF do |checker|
class Foo::Bar
end
EOF

validator = Validator.new(checker: checker)
validator.validate

assert_operator validator, :has_error?
assert_any! validator.each_error do |error|
assert_instance_of Errors::UnknownTypeNameError, error
assert_equal parse_type("::Foo").name, error.name
end
end

with_checker <<-EOF do |checker|
type Foo::bar = Integer
EOF

validator = Validator.new(checker: checker)
validator.validate

assert_operator validator, :has_error?
assert_any! validator.each_error do |error|
assert_instance_of Errors::UnknownTypeNameError, error
assert_equal parse_type("::Foo").name, error.name
end
end

with_checker <<-EOF do |checker|
Foo::Bar: Integer
EOF

validator = Validator.new(checker: checker)
validator.validate

assert_operator validator, :has_error?
assert_any! validator.each_error do |error|
assert_instance_of Errors::UnknownTypeNameError, error
assert_equal parse_type("::Foo").name, error.name
end
end
end

def test_validate_module
skip "Not implemented yet"
end
Expand Down

0 comments on commit 4d7f122

Please sign in to comment.