From 6ab43f4970c0f4e26482697636e428e4c32141e8 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 14 Dec 2020 01:05:57 +0000 Subject: [PATCH] Add matcher config --- lib/mutant.rb | 2 +- lib/mutant/config.rb | 16 +++++++++++---- lib/mutant/matcher/config.rb | 36 +++++++++++++++++++++++++++++++++ mutant.sh | 11 ---------- mutant.yml | 10 +++++++++ scripts/devloop.sh | 2 +- spec/unit/mutant/config_spec.rb | 10 +++++++++ 7 files changed, 70 insertions(+), 17 deletions(-) delete mode 100755 mutant.sh diff --git a/lib/mutant.rb b/lib/mutant.rb index 3e6f656c5..c3d593143 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -40,6 +40,7 @@ module Mutant SCOPE_OPERATOR = '::' end # Mutant +require 'mutant/transform' require 'mutant/bootstrap' require 'mutant/version' require 'mutant/env' @@ -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' diff --git a/lib/mutant/config.rb b/lib/mutant/config.rb index a596a4600..b516bbd36 100644 --- a/lib/mutant/config.rb +++ b/lib/mutant/config.rb @@ -116,18 +116,25 @@ def merge(other) # # @return [Either] 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] @@ -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: [] ), diff --git a/lib/mutant/matcher/config.rb b/lib/mutant/matcher/config.rb index f3d61d3db..13cc32598 100644 --- a/lib/mutant/matcher/config.rb +++ b/lib/mutant/matcher/config.rb @@ -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}] + # @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] diff --git a/mutant.sh b/mutant.sh deleted file mode 100755 index 9d5e8472f..000000000 --- a/mutant.sh +++ /dev/null @@ -1,11 +0,0 @@ -#/usr/bin/bash -ex - -bundle exec mutant run \ - --zombie \ - --ignore-subject Mutant::CLI#add_debug_options \ - --ignore-subject Mutant::Isolation::Fork::Parent#call \ - --ignore-subject Mutant::Mutator::Node::Argument#skip? \ - --ignore-subject Mutant::Mutator::Node::ProcargZero#dispatch \ - --ignore-subject Mutant::Mutator::Node::When#mutate_conditions \ - --ignore-subject Mutant::Zombifier#call \ - $* diff --git a/mutant.yml b/mutant.yml index 540e82f47..5f9296de1 100644 --- a/mutant.yml +++ b/mutant.yml @@ -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 diff --git a/scripts/devloop.sh b/scripts/devloop.sh index 2019748fa..9b86aa3c2 100755 --- a/scripts/devloop.sh +++ b/scripts/devloop.sh @@ -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 diff --git a/spec/unit/mutant/config_spec.rb b/spec/unit/mutant/config_spec.rb index cc91080d2..fe21fd471 100644 --- a/spec/unit/mutant/config_spec.rb +++ b/spec/unit/mutant/config_spec.rb @@ -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