From 5f24cb886d30b9410d8dba4babdd61914cb55c52 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 22 Nov 2020 04:20:37 +0000 Subject: [PATCH] Change Config inheritance to preserve order --- lib/mutant/cli/command/run.rb | 4 ++-- lib/mutant/config.rb | 4 ++-- spec/unit/mutant/cli_spec.rb | 32 +++++++++++++++++++++++++------- spec/unit/mutant/config_spec.rb | 2 +- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/mutant/cli/command/run.rb b/lib/mutant/cli/command/run.rb index 2c12ad112..7d262b980 100644 --- a/lib/mutant/cli/command/run.rb +++ b/lib/mutant/cli/command/run.rb @@ -35,7 +35,7 @@ def zombie? def initialize(attributes) super(attributes) - @config = Config::DEFAULT + @config = Config.env end def execute @@ -49,7 +49,7 @@ def execute end def expand(file_config) - @config = Config.env.merge(file_config).merge(@config) + @config = @config.merge(file_config) end def soft_fail(result) diff --git a/lib/mutant/config.rb b/lib/mutant/config.rb index 2791bf155..16cc2afae 100644 --- a/lib/mutant/config.rb +++ b/lib/mutant/config.rb @@ -61,12 +61,12 @@ class Config def merge(other) other.with( fail_fast: fail_fast || other.fail_fast, - includes: includes + other.includes, + includes: other.includes + includes, jobs: other.jobs || jobs, integration: other.integration || integration, mutation_timeout: other.mutation_timeout || mutation_timeout, matcher: matcher.merge(other.matcher), - requires: requires + other.requires, + requires: other.requires + requires, zombie: zombie || other.zombie ) end diff --git a/spec/unit/mutant/cli_spec.rb b/spec/unit/mutant/cli_spec.rb index 40d6c5e5f..0f457686a 100644 --- a/spec/unit/mutant/cli_spec.rb +++ b/spec/unit/mutant/cli_spec.rb @@ -382,15 +382,14 @@ def self.make let(:env_result) { instance_double(Mutant::Result::Env, success?: true) } let(:expected_events) { [license_validation_event] } let(:expected_exit) { true } - let(:file_config) { Mutant::Config::DEFAULT } let(:file_config_result) { MPrelude::Either::Right.new(file_config) } let(:license_result) { MPrelude::Either::Right.new(subscription) } let(:runner_result) { MPrelude::Either::Right.new(env_result) } let(:file_config) do Mutant::Config::DEFAULT.with( - includes: %w[lib], - requires: %w[foo] + includes: %w[include-file], + requires: %w[require-file] ) end @@ -557,15 +556,34 @@ def self.make end context 'with --include option' do - let(:arguments) { super() + %w[--include lob --include lub] } - let(:bootstrap_config) { super().with(includes: %w[lib lob lub]) } + let(:arguments) do + super() + %w[ + --include include-cli-a + --include include-cli-b + ] + end + + let(:bootstrap_config) do + super().with( + includes: %w[ + include-file + include-cli-a + include-cli-b + ] + ) + end include_examples 'CLI run' end context 'with --require option' do - let(:arguments) { super() + %w[--require bar] } - let(:bootstrap_config) { super().with(requires: %w[foo bar]) } + let(:arguments) { super() + %w[--require require-cli] } + + let(:bootstrap_config) do + super().with( + requires: %w[require-file require-cli] + ) + end include_examples 'CLI run' end diff --git a/spec/unit/mutant/config_spec.rb b/spec/unit/mutant/config_spec.rb index 9a197e3da..e3f92d9ec 100644 --- a/spec/unit/mutant/config_spec.rb +++ b/spec/unit/mutant/config_spec.rb @@ -29,7 +29,7 @@ def expect_value(value) let(:original_value) { %w[bar] } it 'adds other and orignial' do - expect_value(original_value + other_value) + expect_value(other_value + original_value) end end