Skip to content

Commit

Permalink
Change minitest integration to allow multiple cover expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Oct 29, 2020
1 parent b45adad commit a72f511
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
17 changes: 10 additions & 7 deletions lib/mutant/integration/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ def call(reporter)
reporter.passed?
end

# Cover expression syntaxes
# Parse expressions
#
# @return [String, nil]
def expression_syntax
klass.resolve_cover_expression
# @param [ExpressionParser] parser
#
# @return [Array<Expression>]
def expressions(parser)
klass.resolve_cover_expression.map do |syntax|
parser.apply(syntax).from_right
end
end

end # TestCase

private_constant(*constants(false))
Expand Down Expand Up @@ -125,7 +128,7 @@ def all_tests_index
def construct_test(test_case)
Test.new(
id: test_case.identification,
expressions: [config.expression_parser.apply(test_case.expression_syntax).from_right]
expressions: test_case.expressions(parser)
)
end

Expand All @@ -137,7 +140,7 @@ def all_test_cases
end

def allow_runnable?(klass)
!klass.equal?(::Minitest::Runnable) && klass.resolve_cover_expression
!klass.equal?(::Minitest::Runnable) && klass.resolve_cover_expressions
end

def test_case(runnable)
Expand Down
18 changes: 8 additions & 10 deletions lib/mutant/minitest/coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,28 @@ module Coverage
#
# @api public
def cover(expression)
if defined?(@cover_expression)
fail "#{self} already declares to cover: #{@cover_expression.inspect}"
end
@cover_expressions = Set.new unless defined?(@cover_expressions)

@cover_expression = expression
@cover_expressions << expression
end

# Effective coverage expression
#
# @return [String, nil]
# @return [Set<String>]
#
# @api private
def resolve_cover_expression
return @cover_expression if defined?(@cover_expression)
def resolve_cover_expressions
return @cover_expressions if defined?(@cover_expressions)

try_superclass_cover_expression
try_superclass_cover_expressions
end

private

def try_superclass_cover_expression
def try_superclass_cover_expressions
return if superclass.equal?(::Minitest::Runnable)

superclass.resolve_cover_expression
superclass.resolve_cover_expressions
end

end # Coverage
Expand Down
1 change: 1 addition & 0 deletions test_app/test/unit/test_app/literal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class LiteralTest < Minitest::Test
cover 'TestApp::Literal*'
cover 'TestApp::Literal#string'

def test_command
object = ::TestApp::Literal.new
Expand Down

0 comments on commit a72f511

Please sign in to comment.