Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Sep 20, 2015
1 parent dee3d7f commit 4bf8034
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 84 deletions.
22 changes: 13 additions & 9 deletions lib/mutant.rb
Expand Up @@ -189,22 +189,26 @@ class Config

DEFAULT = new(
debug: false,
expected_coverage: Rational(1),
fail_fast: false,
integration: Integration::Null,
matcher: Matcher::Config::DEFAULT,
includes: EMPTY_ARRAY,
integration: 'null'.freeze,
jobs: Mutant.ci? ? CI_DEFAULT_PROCESSOR_COUNT : ::Parallel.processor_count,
matcher: Matcher::Config::DEFAULT,
requires: EMPTY_ARRAY,
isolation: Mutant::Isolation::Fork,
reporter: Reporter::CLI.build($stdout),
zombie: false,
jobs: Mutant.ci? ? CI_DEFAULT_PROCESSOR_COUNT : ::Parallel.processor_count,
expected_coverage: Rational(1),
expression_parser: Expression::Parser.new([
zombie: false
)
end # Config

class Expression
class Parser
DEFAULT = Expression::Parser.new([
Expression::Method,
Expression::Methods,
Expression::Namespace::Exact,
Expression::Namespace::Recursive
])
)
end # Config
end # Parser
end # Expression
end # Mutant
7 changes: 4 additions & 3 deletions lib/mutant/cli.rb
Expand Up @@ -82,7 +82,7 @@ def parse_match_expressions(expressions)
fail Error, 'No expressions given' if expressions.empty?

expressions.each do |expression|
add_matcher(:match_expressions, config.expression_parser.(expression))
add_matcher(:match_expressions, expression)
end
end

Expand Down Expand Up @@ -119,7 +119,8 @@ def add_environment_options(opts)
#
# @api private
def setup_integration(name)
with(integration: Integration.setup(name))
Integration.setup(name)
with(integration: name)
rescue LoadError
raise Error, "Could not load integration #{name.inspect} (you may want to try installing the gem mutant-#{name})"
end
Expand Down Expand Up @@ -153,7 +154,7 @@ def add_mutation_options(opts)
# @api private
def add_filter_options(opts)
opts.on('--ignore-subject EXPRESSION', 'Ignore subjects that match EXPRESSION as prefix') do |pattern|
add_matcher(:ignore_expressions, config.expression_parser.(pattern))
add_matcher(:ignore_expressions, pattern)
end
opts.on('--since REVISION', 'Only select subjects touched since REVISION') do |revision|
add_matcher(:subject_filters, Repository::SubjectFilter.new(Repository::Diff.from_head(revision)))
Expand Down
12 changes: 5 additions & 7 deletions lib/mutant/config.rb
Expand Up @@ -6,17 +6,15 @@ module Mutant
class Config
include Adamantium::Flat, Anima.new(
:debug,
:expected_coverage,
:fail_fast,
:includes,
:integration,
:jobs,
:matcher,
:includes,
:requires,
:reporter,
:isolation,
:fail_fast,
:jobs,
:zombie,
:expected_coverage,
:expression_parser
:zombie
)

%i[fail_fast zombie debug].each do |name|
Expand Down
10 changes: 6 additions & 4 deletions lib/mutant/env.rb
Expand Up @@ -2,13 +2,15 @@ module Mutant
# Abstract base class for mutant environments
class Env
include Adamantium::Flat, Anima.new(
:config,
:actor_env,
:cache,
:subjects,
:matchable_scopes,
:config,
:integration,
:expression_parser,
:isolation,
:selector,
:subjects,
:matchable_scopes,
:mutations
)

Expand Down Expand Up @@ -59,7 +61,7 @@ def run_mutation_tests(mutation)
start = Time.now
tests = selector.call(mutation.subject)

config.isolation.call do
isolation.call do
mutation.insert
integration.call(tests)
end
Expand Down
26 changes: 16 additions & 10 deletions lib/mutant/env/bootstrap.rb
Expand Up @@ -31,6 +31,7 @@ def self.new(_config, _cache = Cache.new)
# @api private
def initialize(*)
super
@expression_parser = Expression::Parser::DEFAULT
infect
initialize_matchable_scopes
end
Expand All @@ -57,14 +58,16 @@ def warn(message)
def env
subjects = matched_subjects
Env.new(
actor_env: Actor::Env.new(Thread),
config: config,
cache: cache,
subjects: subjects,
matchable_scopes: matchable_scopes,
integration: @integration,
selector: Selector::Expression.new(@integration),
mutations: subjects.flat_map(&:mutations)
actor_env: Actor::Env.new(Thread),
cache: cache,
config: config,
expression_parser: @expression_parser,
integration: @integration,
isolation: Isolation::Fork,
matchable_scopes: matchable_scopes,
mutations: subjects.flat_map(&:mutations),
selector: Selector::Expression.new(@integration),
subjects: subjects
)
end

Expand Down Expand Up @@ -96,7 +99,10 @@ def scope_name(scope)
def infect
config.includes.each(&$LOAD_PATH.method(:<<))
config.requires.each(&method(:require))
@integration = config.integration.new(config.expression_parser).setup
@integration = Integration
.lookup(config.integration)
.new(@expression_parser)
.setup
end

# Matched subjects
Expand Down Expand Up @@ -141,7 +147,7 @@ def expression(scope)
return
end

config.expression_parser.try_parse(name)
@expression_parser.try_parse(name)
end
end # Boostrap
end # Env
Expand Down
4 changes: 2 additions & 2 deletions lib/mutant/matcher/config.rb
Expand Up @@ -14,8 +14,8 @@ class Config
ENUM_DELIMITER = ','.freeze
EMPTY_ATTRIBUTES = 'empty'.freeze
PRESENTATIONS = IceNine.deep_freeze(
match_expressions: :syntax,
ignore_expressions: :syntax,
match_expressions: :to_s,
ignore_expressions: :to_s,
subject_filters: :inspect
)
private_constant(*constants(false))
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -48,7 +48,7 @@ def parse(string)
end

def parse_expression(string)
Mutant::Config::DEFAULT.expression_parser.(string)
Mutant::Expression::Parser::DEFAULT.(string)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/unit/mutant/cli_spec.rb
Expand Up @@ -67,13 +67,13 @@

# Defaults
let(:expected_filter) { Morpher.evaluator(s(:true)) }
let(:expected_integration) { Mutant::Integration::Null }
let(:expected_integration) { 'null' }
let(:expected_reporter) { Mutant::Config::DEFAULT.reporter }
let(:expected_matcher_config) { default_matcher_config }

let(:default_matcher_config) do
Mutant::Matcher::Config::DEFAULT
.with(match_expressions: expressions.map(&method(:parse_expression)))
.with(match_expressions: expressions)
end

let(:flags) { [] }
Expand Down Expand Up @@ -249,7 +249,7 @@
let(:flags) { %w[--ignore-subject Foo::Bar] }

let(:expected_matcher_config) do
default_matcher_config.with(ignore_expressions: [parse_expression('Foo::Bar')])
default_matcher_config.with(ignore_expressions: %w[Foo::Bar])
end

it_should_behave_like 'a cli parser'
Expand Down
20 changes: 11 additions & 9 deletions spec/unit/mutant/env/boostrap_spec.rb
Expand Up @@ -9,18 +9,20 @@
)
end

let(:integration) { Mutant::Integration::Null.new(config.expression_parser) }
let(:integration) { Mutant::Integration::Null.new(Mutant::Expression::Parser::DEFAULT) }

let(:expected_env) do
Mutant::Env.new(
cache: Mutant::Cache.new,
subjects: [],
matchable_scopes: [],
mutations: [],
config: config,
selector: Mutant::Selector::Expression.new(integration),
actor_env: Mutant::Actor::Env.new(Thread),
integration: integration
actor_env: Mutant::Actor::Env.new(Thread),
cache: Mutant::Cache.new,
config: config,
expression_parser: Mutant::Expression::Parser::DEFAULT,
integration: integration,
isolation: Mutant::Isolation::Fork,
matchable_scopes: [],
mutations: [],
subjects: [],
selector: Mutant::Selector::Expression.new(integration),
)
end

Expand Down
20 changes: 11 additions & 9 deletions spec/unit/mutant/env_spec.rb
Expand Up @@ -2,21 +2,23 @@
context '#kill' do
let(:object) do
described_class.new(
config: config,
actor_env: Mutant::Actor::Env.new(Thread),
cache: Mutant::Cache.new,
selector: selector,
subjects: [],
mutations: [],
matchable_scopes: [],
integration: integration
actor_env: Mutant::Actor::Env.new(Thread),
cache: Mutant::Cache.new,
config: config,
expression_parser: Mutant::Expression::Parser::DEFAULT,
integration: integration,
isolation: isolation,
matchable_scopes: [],
mutations: [],
selector: selector,
subjects: []
)
end

let(:integration) { integration_class.new(config) }

let(:config) do
Mutant::Config::DEFAULT.with(isolation: isolation, integration: integration_class)
Mutant::Config::DEFAULT.with(integration: integration_class)
end

let(:isolation) { double('Isolation') }
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/mutant/expression/parser_spec.rb
@@ -1,5 +1,5 @@
RSpec.describe Mutant::Expression::Parser do
let(:object) { Mutant::Config::DEFAULT.expression_parser }
let(:object) { Mutant::Expression::Parser::DEFAULT }

describe '#call' do
subject { object.call(input) }
Expand Down
8 changes: 3 additions & 5 deletions spec/unit/mutant/expression_spec.rb
@@ -1,21 +1,19 @@
RSpec.describe Mutant::Expression do
let(:object) { described_class }

let(:parser) { Mutant::Config::DEFAULT.expression_parser }

describe '#prefix?' do
let(:object) { parser.call('Foo*') }
let(:object) { parse_expression('Foo*') }

subject { object.prefix?(other) }

context 'when object is a prefix of other' do
let(:other) { parser.call('Foo::Bar') }
let(:other) { parse_expression('Foo::Bar') }

it { should be(true) }
end

context 'when other is not a prefix of other' do
let(:other) { parser.call('Bar') }
let(:other) { parse_expression('Bar') }

it { should be(false) }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/mutant/integration/rspec_spec.rb
@@ -1,7 +1,7 @@
require 'mutant/integration/rspec'

RSpec.describe Mutant::Integration::Rspec do
let(:object) { described_class.new(Mutant::Config::DEFAULT.expression_parser) }
let(:object) { described_class.new(Mutant::Expression::Parser::DEFAULT) }

let(:options) { double('options') }
let(:runner) { double('runner') }
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/mutant/matcher/config_spec.rb
Expand Up @@ -9,15 +9,15 @@
end

context 'with one expression' do
let(:object) { described_class::DEFAULT.add(:match_expressions, parse_expression('Foo')) }
let(:object) { described_class::DEFAULT.add(:match_expressions, 'Foo') }
it { should eql('#<Mutant::Matcher::Config match_expressions: [Foo]>') }
end

context 'with many expressions' do
let(:object) do
described_class::DEFAULT
.add(:match_expressions, parse_expression('Foo'))
.add(:match_expressions, parse_expression('Bar'))
.add(:match_expressions, 'Foo')
.add(:match_expressions, 'Bar')
end

it { should eql('#<Mutant::Matcher::Config match_expressions: [Foo,Bar]>') }
Expand All @@ -26,8 +26,8 @@
context 'with match and ignore expression' do
let(:object) do
described_class::DEFAULT
.add(:match_expressions, parse_expression('Foo'))
.add(:ignore_expressions, parse_expression('Bar'))
.add(:match_expressions, 'Foo')
.add(:ignore_expressions, 'Bar')
end

it { should eql('#<Mutant::Matcher::Config match_expressions: [Foo] ignore_expressions: [Bar]>') }
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/mutant/reporter/cli/printer/config_spec.rb
Expand Up @@ -8,7 +8,7 @@
it_reports(<<-REPORT)
Mutant configuration:
Matcher: #<Mutant::Matcher::Config empty>
Integration: Mutant::Integration::Null
Integration: null
Expect Coverage: 100.00%
Jobs: 1
Includes: []
Expand All @@ -22,7 +22,7 @@
it_reports(<<-REPORT)
Mutant configuration:
Matcher: #<Mutant::Matcher::Config empty>
Integration: Mutant::Integration::Null
Integration: null
Expect Coverage: 10.00%
Jobs: 1
Includes: []
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/mutant/reporter/cli/printer/env_progress_spec.rb
Expand Up @@ -12,7 +12,7 @@
it_reports <<-'STR'
Mutant configuration:
Matcher: #<Mutant::Matcher::Config empty>
Integration: Mutant::Integration::Null
Integration: null
Expect Coverage: 10.00%
Jobs: 1
Includes: []
Expand All @@ -33,7 +33,7 @@
it_reports <<-'STR'
Mutant configuration:
Matcher: #<Mutant::Matcher::Config empty>
Integration: Mutant::Integration::Null
Integration: null
Expect Coverage: 10.00%
Jobs: 1
Includes: []
Expand All @@ -56,7 +56,7 @@
it_reports <<-'STR'
Mutant configuration:
Matcher: #<Mutant::Matcher::Config empty>
Integration: Mutant::Integration::Null
Integration: null
Expect Coverage: 10.00%
Jobs: 1
Includes: []
Expand Down

0 comments on commit 4bf8034

Please sign in to comment.