Skip to content

Commit

Permalink
Add matcher config
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Dec 23, 2020
1 parent d66e549 commit 6ab43f4
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/mutant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Mutant
SCOPE_OPERATOR = '::'
end # Mutant

require 'mutant/transform'
require 'mutant/bootstrap'
require 'mutant/version'
require 'mutant/env'
Expand Down Expand Up @@ -158,7 +159,6 @@ module Mutant
require 'mutant/expression/namespace'
require 'mutant/test'
require 'mutant/timer'
require 'mutant/transform'
require 'mutant/integration'
require 'mutant/integration/null'
require 'mutant/selector'
Expand Down
16 changes: 12 additions & 4 deletions lib/mutant/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,25 @@ def merge(other)
#
# @return [Either<String,Config>]
def self.load_config_file(world)
config = DEFAULT
files = CANDIDATES.map(&world.pathname.public_method(:new)).select(&:readable?)

if files.one?
load_contents(files.first).fmap(&config.public_method(:with))
load_contents(files.first).fmap(&method(:from_attributes))
elsif files.empty?
Either::Right.new(config)
Either::Right.new(DEFAULT)
else
Either::Left.new(MORE_THAN_ONE_CONFIG_FILE % files.join(', '))
end
end

def self.from_attributes(attributes)
if attributes.key?(:subjects)
attributes[:matcher] = attributes.delete(:subjects)
end

DEFAULT.with(attributes)
end

# Expand config with defaults
#
# @return [Config]
Expand Down Expand Up @@ -165,7 +172,8 @@ def self.env
Transform::Hash::Key.new('integration', Transform::STRING),
Transform::Hash::Key.new('jobs', Transform::INTEGER),
Transform::Hash::Key.new('mutation_timeout', Transform::FLOAT),
Transform::Hash::Key.new('requires', Transform::STRING_ARRAY)
Transform::Hash::Key.new('requires', Transform::STRING_ARRAY),
Transform::Hash::Key.new('subjects', Matcher::Config::LOADER)
],
required: []
),
Expand Down
36 changes: 36 additions & 0 deletions lib/mutant/matcher/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,42 @@ class Config

DEFAULT = new(Hash[anima.attribute_names.map { |name| [name, []] }])

expression = ->(input) { Mutant::Config::DEFAULT.expression_parser.call(input) }

expression_array = Transform::Array.new(expression)

# Load from config file attributes
#
# @param [Hash{Symbol => Array<String>}]
# @return [Config]
def self.from_file_attributes(attributes)
if attributes.key?(:select)
attributes[:match_expressions] = attributes.delete(:select)
end

if attributes.key?(:ignore)
attributes[:ignore_expressions] = attributes.delete(:ignore)
end

Either::Right.new(DEFAULT.with(attributes))
end
private_class_method :from_file_attributes

LOADER =
Transform::Sequence.new(
[
Transform::Hash.new(
optional: [
Transform::Hash::Key.new('select', expression_array),
Transform::Hash::Key.new('ignore', expression_array),
],
required: []
),
Transform::Hash::Symbolize.new,
method(:from_file_attributes),
]
)

# Inspection string
#
# @return [String]
Expand Down
11 changes: 0 additions & 11 deletions mutant.sh

This file was deleted.

10 changes: 10 additions & 0 deletions mutant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ requires:
- mutant
- mutant/integration/rspec
- mutant/meta
subjects:
select:
- Mutant*
ignore:
- Mutant::CLI#add_debug_options
- Mutant::Isolation::Fork::Parent#call
- Mutant::Mutator::Node::Argument#skip?
- Mutant::Mutator::Node::ProcargZero#dispatch
- Mutant::Mutator::Node::When#mutate_conditions
- Mutant::Zombifier#call
2 changes: 1 addition & 1 deletion scripts/devloop.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
while inotifywait **/*.rb Gemfile Gemfile.shared mutant.gemspec; do
bundle exec rspec spec/unit -fd --fail-fast --order default \
&& bundle exec ./mutant.sh --since master --fail-fast -- 'Mutant*' \
&& bundle exec mutant run --since master --fail-fast --zombie -- 'Mutant*' \
&& bundle exec rubocop
done
10 changes: 10 additions & 0 deletions spec/unit/mutant/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,14 @@ def apply
end
end
end

describe '.from_file_attributes' do

let(:config) do
described_class::DEFAULT.with(
coverage_criteria: described_class::CoverageCriteria::EMPTY.with(
test_result: false
)
)
end
end

0 comments on commit 6ab43f4

Please sign in to comment.