Skip to content

Commit

Permalink
Fix signature validation
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Aug 2, 2020
1 parent 8998f76 commit c3c1f9b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
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
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 c3c1f9b

Please sign in to comment.