lib/mutant/cli.rb in mutant-0.5.23 vs lib/mutant/cli.rb in mutant-0.5.24
- old
+ new
@@ -2,11 +2,11 @@
module Mutant
# Comandline parser
class CLI
- include Adamantium::Flat, Equalizer.new(:config), NodeHelpers
+ include Adamantium::Flat, Equalizer.new(:config)
# Error raised when CLI argv is invalid
Error = Class.new(RuntimeError)
EXIT_FAILURE = 1
@@ -28,166 +28,29 @@
rescue Error => exception
$stderr.puts(exception.message)
EXIT_FAILURE
end
- # Builder for configuration components
- class Builder
- include NodeHelpers
-
- # Initalize object
- #
- # @return [undefined]
- #
- # @api private
- #
- def initialize
- @matchers = []
- @subject_ignores = []
- @subject_selectors = []
- end
-
- # Add a subject ignore
- #
- # @param [Matcher]
- #
- # @return [self]
- #
- # @api private
- #
- def add_subject_ignore(matcher)
- @subject_ignores << matcher
- self
- end
-
- # Add a subject selector
- #
- # @param [#call] selector
- #
- # @return [self]
- #
- # @api private
- #
- def add_subject_selector(selector)
- @subject_selectors << selector
- self
- end
-
- # Add a subject matcher
- #
- # @param [#call] selector
- #
- # @return [self]
- #
- # @api private
- #
- def add_matcher(matcher)
- @matchers << matcher
- self
- end
-
- # Return generated matcher
- #
- # @return [Mutant::Matcher]
- #
- # @api private
- #
- def matcher
- if @matchers.empty?
- raise(Error, 'No patterns given')
- end
-
- matcher = Matcher::Chain.build(@matchers)
-
- if predicate
- Matcher::Filter.new(matcher, predicate)
- else
- matcher
- end
- end
-
- private
-
- # Return subject selector
- #
- # @return [#call]
- # if selector is present
- #
- # @return [nil]
- # otherwise
- #
- # @api private
- #
- def subject_selector
- Morpher::Evaluator::Predicate::Boolean::Or.new(@subject_selectors) if @subject_selectors.any?
- end
-
- # Return predicate
- #
- # @return [#call]
- # if filter is needed
- #
- # @return [nil]
- # othrwise
- #
- # @api private
- #
- def predicate
- if subject_selector && subject_rejector
- Morpher::Evaluator::Predicate::Boolean::And.new([
- subject_selector,
- Morpher::Evaluator::Predicate::Negation.new(subject_rejector)
- ])
- elsif subject_selector
- subject_selector
- elsif subject_rejector
- Morpher::Evaluator::Predicate::Negation.new(subject_rejector)
- else
- nil
- end
- end
-
- # Return subject rejector
- #
- # @return [#call]
- # if there is a subject rejector
- #
- # @return [nil]
- # otherwise
- #
- # @api private
- #
- def subject_rejector
- rejectors = @subject_ignores.flat_map(&:to_a).map do |subject|
- Morpher.compile(s(:eql, s(:attribute, :identification), s(:static, subject.identification)))
- end
-
- Morpher::Evaluator::Predicate::Boolean::Or.new(rejectors) if rejectors.any?
- end
- end
-
# Initialize objecct
#
# @param [Array<String>]
#
# @return [undefined]
#
# @api private
#
def initialize(arguments = [])
- @builder = Builder.new
+ @builder = Matcher::Builder.new(Env::Boot.new(Reporter::CLI.new($stderr), Cache.new))
@debug = @fail_fast = @zombie = false
@expected_coverage = 100.0
- @strategy = Strategy::Null.new
- @cache = Mutant::Cache.new
+ @integration = Integration::Null.new
parse(arguments)
@config = Config.new(
- cache: @cache,
zombie: @zombie,
debug: @debug,
matcher: @builder.matcher,
- strategy: @strategy,
+ integration: @integration,
fail_fast: @fail_fast,
reporter: Reporter::CLI.new($stdout),
expected_coverage: @expected_coverage
)
end
@@ -234,23 +97,20 @@
parse_matchers(patterns)
end
# Parse matchers
#
- # @param [Enumerable<String>] patterns
+ # @param [Array<String>] patterns
#
# @return [undefined]
#
# @api private
#
def parse_matchers(patterns)
+ raise Error, 'No patterns given' if patterns.empty?
patterns.each do |pattern|
- expression = Expression.parse(pattern)
- unless expression
- raise Error, "Invalid mutant expression: #{pattern.inspect}"
- end
- @builder.add_matcher(expression.matcher(@cache))
+ @builder.add_match_expression(Expression.parse(pattern))
end
end
# Add environmental options
#
@@ -281,12 +141,12 @@
# @return [undefined]
#
# @api private
#
def use(name)
- require "mutant/#{name}"
- @strategy = Strategy.lookup(name).new
+ require "mutant/integration/#{name}"
+ @integration = Integration.lookup(name).new
rescue LoadError
$stderr.puts("Cannot load plugin: #{name.inspect}")
raise
end
@@ -317,13 +177,13 @@
#
# @api private
#
def add_filter_options(opts)
opts.on('--ignore-subject PATTERN', 'Ignore subjects that match PATTERN') do |pattern|
- @builder.add_subject_ignore(Expression.parse(pattern).matcher(@cache))
+ @builder.add_subject_ignore(Expression.parse(pattern))
end
opts.on('--code CODE', 'Scope execution to subjects with CODE') do |code|
- @builder.add_subject_selector(Morpher.compile(s(:eql, s(:attribute, :code), s(:static, code))))
+ @builder.add_subject_selector(:code, code)
end
end
# Add debug options
#