Skip to content

Commit

Permalink
Improve type coverage (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous authored Oct 22, 2022
1 parent 1289c95 commit eac17e3
Show file tree
Hide file tree
Showing 28 changed files with 74 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## Head

- Improve type coverage.

## 0.8.1

- Improve type-checking.
Expand Down
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require "rdoc/task"
task default: %i[lint test]

desc "Run lint"
task lint: %i[rubocop rbs:setup typecheck:run rdoc]
task lint: %i[rubocop rbs:setup typecheck:run typecheck:stats rdoc]

RuboCop::RakeTask.new

Expand All @@ -30,6 +30,11 @@ namespace :typecheck do
task :save do
sh "steep check --save-expectations"
end

desc "Show type coverage stats"
task :stats do
sh "steep stats --format=table"
end
end

namespace :rbs do
Expand Down
2 changes: 1 addition & 1 deletion lib/easytest/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Case
alias skipped? skipped
alias only? only

def initialize(name:, skipped: false, only: false, &block)
def initialize(name:, skipped: false, only: false, block: nil)
@name = name
@file = (caller_locations(3, 1)&.first&.absolute_path or raise)
@block = block
Expand Down
1 change: 1 addition & 0 deletions lib/easytest/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def initialize(argv)
end

def parse_options
# @type var options: Hash[Symbol, bool]
options = {}

parser = OptionParser.new do |p|
Expand Down
10 changes: 5 additions & 5 deletions lib/easytest/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ module DSL
refine Kernel do
def test(name, &block)
Utils.raise_if_no_test_name(name, method: "test")
Easytest.add_case Case.new(name: name, &block)
Easytest.add_case Case.new(name: name, block: block)
end

def before(&block)
Easytest.add_hook Hook.new(type: :before, &block)
Easytest.add_hook Hook.new(type: :before, block: block)
end

def after(&block)
Easytest.add_hook Hook.new(type: :after, &block)
Easytest.add_hook Hook.new(type: :after, block: block)
end

def skip(name, &block)
Utils.raise_if_no_test_name(name, method: "skip")
Easytest.add_case Case.new(name: name, skipped: true, &block)
Easytest.add_case Case.new(name: name, skipped: true, block: block)
end

def only(name, &block)
Utils.raise_if_no_test_name(name, method: "only")
Easytest.add_case Case.new(name: name, only: true, &block)
Easytest.add_case Case.new(name: name, only: true, block: block)
end

def expect(actual = nil, &block)
Expand Down
2 changes: 1 addition & 1 deletion lib/easytest/hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Hook
attr_reader :type
attr_reader :block

def initialize(type:, &block)
def initialize(type:, block:)
raise ArgumentError, "" unless [:before, :after].include?(type)

@file = (caller_locations(3, 1)&.first&.absolute_path or raise)
Expand Down
2 changes: 1 addition & 1 deletion lib/easytest/matcher/contain_exactly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Easytest
module Matcher
class ContainExactly < Base
def match?
(actual.to_a - expected).empty?
(Array(actual) - Array(expected)).empty?
end

def message
Expand Down
15 changes: 9 additions & 6 deletions lib/easytest/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@ def run
before_hooks = hooks.filter(&:before?)
after_hooks = hooks.filter(&:after?)

# @type var reports: Array[[Symbol, String]]
reports = []

cases_per_file.each do |c|
if include_only_case && !c.only?
c.skip!
end

begin
before_hooks.each { |hook| hook.run(c) }
result, report = c.run
ensure
after_hooks.each { |hook| hook.run(c) }
end
result, report =
begin
before_hooks.each { |hook| hook.run(c) }
c.run
ensure
after_hooks.each { |hook| hook.run(c) }
end

case result
when :passed
Expand Down Expand Up @@ -133,6 +135,7 @@ def elapsed_time
end

def summary
# @type var list: Array[String]
list = []

if failed_count > 0
Expand Down
2 changes: 1 addition & 1 deletion sig-private/easytest/case.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Easytest

alias only? only

def initialize: (name: String, ?skipped: bool, ?only: bool) ?{ () -> void } -> void
def initialize: (name: String, ?skipped: bool, ?only: bool, ?block: (^() -> void)?) -> void

def skip!: () -> void

Expand Down
2 changes: 1 addition & 1 deletion sig-private/easytest/hook.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Easytest

attr_reader block: ^(Case) -> void

def initialize: (type: Symbol) { (Case) -> void } -> void
def initialize: (type: Symbol, block: ^(Case) -> void) -> void

def run: (Case test_case) -> void

Expand Down
8 changes: 4 additions & 4 deletions sig-private/easytest/matcher/base.rbs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module Easytest
module Matcher
class Base
attr_reader actual: untyped
class Base[A, E]
attr_reader actual: A

attr_reader expected: untyped
attr_reader expected: E

attr_reader negate: bool

alias negate? negate

def initialize: (actual: untyped, expected: untyped, ?negate: bool) -> void
def initialize: (actual: A, expected: E, ?negate: bool) -> void

def match?: () -> bool

Expand Down
2 changes: 1 addition & 1 deletion sig-private/easytest/matcher/be.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Easytest
module Matcher
class Be < Base
class Be < Base[Object, Object]
end
end
end
2 changes: 1 addition & 1 deletion sig-private/easytest/matcher/be_a.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Easytest
module Matcher
class BeA < Base
class BeA < Base[Object, Module]
end
end
end
12 changes: 11 additions & 1 deletion sig-private/easytest/matcher/contain_exactly.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
module Easytest
module Matcher
class ContainExactly < Base
interface _ToA
def to_a: () -> Array[untyped]
end

interface _ToAry
def to_ary: () -> Array[untyped]
end

type array_like = _ToA | _ToAry

class ContainExactly < Base[array_like, array_like]
end
end
end
6 changes: 5 additions & 1 deletion sig-private/easytest/matcher/empty.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Easytest
module Matcher
class Empty < Base
interface _Empty
def empty?: () -> bool
end

class Empty < Base[_Empty, untyped]
end
end
end
2 changes: 1 addition & 1 deletion sig-private/easytest/matcher/equal.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Easytest
module Matcher
class Equal < Base
class Equal < Base[Object, untyped]
end
end
end
2 changes: 1 addition & 1 deletion sig-private/easytest/matcher/false.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Easytest
module Matcher
class False < Base
class False < Base[bool, untyped]
end
end
end
2 changes: 1 addition & 1 deletion sig-private/easytest/matcher/have_attributes.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Easytest
module Matcher
class HaveAttributes < Base
class HaveAttributes < Base[Object, Hash[Symbol, untyped]]
end
end
end
6 changes: 5 additions & 1 deletion sig-private/easytest/matcher/include.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Easytest
module Matcher
class Include < Base
interface _Include
def include?: (untyped) -> bool
end

class Include < Base[_Include, untyped]
end
end
end
2 changes: 1 addition & 1 deletion sig-private/easytest/matcher/instance_of.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Easytest
module Matcher
class InstanceOf < Base
class InstanceOf < Base[Object, Module]
end
end
end
2 changes: 1 addition & 1 deletion sig-private/easytest/matcher/kind_of.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Easytest
module Matcher
class KindOf < Base
class KindOf < Base[Object, Module]
end
end
end
6 changes: 5 additions & 1 deletion sig-private/easytest/matcher/match.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Easytest
module Matcher
class Match < Base
interface _Match
def match?: (untyped) -> bool
end

class Match < Base[_Match, untyped]
end
end
end
2 changes: 1 addition & 1 deletion sig-private/easytest/matcher/nil.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Easytest
module Matcher
class Nil < Base
class Nil < Base[Object, untyped]
end
end
end
4 changes: 2 additions & 2 deletions sig-private/easytest/matcher/raise.rbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Easytest
module Matcher
class Raise < Base
class Raise < Base[Proc, untyped]
@raised_error: Exception

attr_reader with_message: (String | Regexp)?

def initialize: (actual: untyped, expected: untyped, negate: bool, with_message: (String | Regexp)?) -> void
def initialize: (actual: Proc, expected: untyped, negate: bool, with_message: (String | Regexp)?) -> void

private

Expand Down
4 changes: 2 additions & 2 deletions sig-private/easytest/matcher/raise_nothing.rbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Easytest
module Matcher
class RaiseNothing < Base
class RaiseNothing < Base[Proc, untyped]
@raised_error: Exception

def initialize: (actual: untyped) -> void
def initialize: (actual: Proc) -> void
end
end
end
2 changes: 1 addition & 1 deletion sig-private/easytest/matcher/satisfy.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Easytest
module Matcher
class Satisfy < Base
class Satisfy < Base[untyped, Proc]
end
end
end
2 changes: 1 addition & 1 deletion sig-private/easytest/matcher/true.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Easytest
module Matcher
class True < Base
class True < Base[bool, untyped]
end
end
end
10 changes: 0 additions & 10 deletions steep_expectations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@
::Object <: ::String
::BasicObject <: ::String
code: Ruby::ArgumentTypeMismatch
- range:
start:
line: 6
character: 31
end:
line: 6
character: 34
severity: ERROR
message: The method cannot be called without a block
code: Ruby::RequiredBlockMissing
- range:
start:
line: 6
Expand Down

0 comments on commit eac17e3

Please sign in to comment.