Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Mutant::Config::DEFAULT to be well formed at all times #1353

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.11.14 2022-09-05

* [#1353](https://github.com/mbj/mutant/pull/1353)

Fix to provide a well formed `Mutant::Config::DEFAULT` constant at all times.
Primarily useful for custom 3rd party integrations that use mutants API directly.

# v0.11.14 2022-07-31

* [#1348](https://github.com/mbj/mutant/pull/1348)
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
mutant (0.11.14)
mutant (0.11.15)
diff-lcs (~> 1.3)
parser (~> 3.1.0)
regexp_parser (~> 2.3, >= 2.3.1)
Expand Down Expand Up @@ -52,7 +52,7 @@ GEM
rubocop-ast (1.16.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
sorbet-runtime (0.5.10206)
sorbet-runtime (0.5.10400)
unicode-display_width (2.1.0)
unparser (0.6.5)
diff-lcs (~> 1.3)
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ module Mutant
# Reopen class to initialize constant to avoid dep circle
class Config
DEFAULT = new(
coverage_criteria: Config::CoverageCriteria::EMPTY,
coverage_criteria: Config::CoverageCriteria::DEFAULT,
expression_parser: Expression::Parser.new([
Expression::Descendants,
Expression::Method,
Expand Down
6 changes: 4 additions & 2 deletions lib/mutant/cli/command/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Environment < self

def initialize(attributes)
super(attributes)
@config = Config::DEFAULT
@config = Config::DEFAULT.with(
coverage_criteria: Config::CoverageCriteria::EMPTY
)
end

def bootstrap
Expand All @@ -37,7 +39,7 @@ def expand(file_config)
)
end

@config = Config.env.merge(file_config).merge(@config).expand_defaults
@config = Config.env.merge(file_config).merge(@config)
end

def parse_remaining_arguments(arguments)
Expand Down
10 changes: 0 additions & 10 deletions lib/mutant/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ def self.load_config_file(env)
end
end

# Expand config with defaults
#
# @return [Config]
def expand_defaults
with(
coverage_criteria: CoverageCriteria::DEFAULT.merge(coverage_criteria),
jobs: jobs || 1
)
end

def self.load_contents(env, path)
Transform::Named
.new(
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module Mutant
# Current mutant version
VERSION = '0.11.14'
VERSION = '0.11.15'
end # Mutant
4 changes: 1 addition & 3 deletions spec/support/shared_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ def setup_shared_context
end

let(:config) do
Mutant::Config::DEFAULT.with(
reporter: Mutant::Reporter::Null.new
).expand_defaults
Mutant::Config::DEFAULT.with(reporter: Mutant::Reporter::Null.new)
end

let(:subject_a_context) do
Expand Down
13 changes: 9 additions & 4 deletions spec/unit/mutant/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
let(:events) { [] }
let(:expected_zombie) { false }
let(:kernel) { class_double(Kernel) }
let(:load_config_file_config) { Mutant::Config::DEFAULT }
let(:stderr) { instance_double(IO, :stderr, tty?: false) }
let(:stdout) { instance_double(IO, :stdout, tty?: false) }
let(:timer) { instance_double(Mutant::Timer) }
Expand All @@ -21,6 +20,12 @@
)
end

let(:load_config_file_config) do
Mutant::Config::DEFAULT.with(
coverage_criteria: Mutant::Config::CoverageCriteria::EMPTY
)
end

def apply
described_class.parse(
arguments: Marshal.load(Marshal.dump(arguments)),
Expand Down Expand Up @@ -548,7 +553,7 @@ def self.main_body

shared_context 'environment' do
let(:arguments) { %w[run] }
let(:bootstrap_config) { env_config.merge(file_config).expand_defaults }
let(:bootstrap_config) { env_config.merge(file_config) }
let(:bootstrap_result) { right(env) }
let(:env_result) { instance_double(Mutant::Result::Env, success?: true) }
let(:expected_exit) { true }
Expand Down Expand Up @@ -1154,7 +1159,7 @@ def self.main_body
let(:file_config) { Mutant::Config::DEFAULT }

context 'without coverage criteria in env or file' do
let(:bootstrap_config) { Mutant::Config::DEFAULT.expand_defaults }
let(:bootstrap_config) { Mutant::Config::DEFAULT }

include_examples 'CLI run'
end
Expand All @@ -1168,7 +1173,7 @@ def self.main_body
)
end

let(:bootstrap_config) { file_config.expand_defaults }
let(:bootstrap_config) { file_config }

include_examples 'CLI run'
end
Expand Down
34 changes: 0 additions & 34 deletions spec/unit/mutant/config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
# frozen_string_literal: true

RSpec.describe Mutant::Config do
describe '#expand_defaults' do
let(:config) do
described_class::DEFAULT.with(
coverage_criteria: described_class::CoverageCriteria::EMPTY.with(
test_result: false
)
)
end

def apply
config.expand_defaults
end

context 'on empty jobs' do
it 'expands empty jobs' do
expect(apply.jobs).to eql(1)
end
end

context 'on present jobs' do
let(:config) { super().with(jobs: 2) }

it 'doesn not expand jobs' do
expect(apply.jobs).to eql(2)
end
end

it 'expands merges coverage criteria with defaults' do
expect(apply.coverage_criteria).to eql(
described_class::CoverageCriteria::DEFAULT.with(test_result: false)
)
end
end

describe '#merge' do
def apply
original.merge(other)
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/mutant/reporter/cli/printer/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
it_reports(<<~'REPORT')
Matcher: #<Mutant::Matcher::Config empty>
Integration: null
Jobs: 1
Jobs: auto
Includes: []
Requires: []
REPORT
Expand All @@ -38,7 +38,7 @@
it_reports(<<~'REPORT')
Matcher: #<Mutant::Matcher::Config empty>
Integration: foo
Jobs: 1
Jobs: auto
Includes: []
Requires: []
REPORT
Expand All @@ -52,7 +52,7 @@
it_reports(<<~'REPORT')
Matcher: #<Mutant::Matcher::Config empty>
Integration: null
Jobs: 1
Jobs: auto
Includes: []
Requires: []
MutationTimeout: 2.1
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/mutant/reporter/cli/printer/env_progress_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Mutant environment:
Matcher: #<Mutant::Matcher::Config empty>
Integration: null
Jobs: 1
Jobs: auto
Includes: []
Requires: []
Subjects: 1
Expand All @@ -38,7 +38,7 @@
Mutant environment:
Matcher: #<Mutant::Matcher::Config empty>
Integration: null
Jobs: 1
Jobs: auto
Includes: []
Requires: []
Subjects: 1
Expand All @@ -65,7 +65,7 @@
Mutant environment:
Matcher: #<Mutant::Matcher::Config empty>
Integration: null
Jobs: 1
Jobs: auto
Includes: []
Requires: []
Subjects: 1
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/mutant/reporter/cli/printer/env_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Mutant environment:
Matcher: #<Mutant::Matcher::Config empty>
Integration: null
Jobs: 1
Jobs: auto
Includes: []
Requires: []
Subjects: 1
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/mutant/reporter/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def self.it_reports(expected_content)
Mutant environment:
Matcher: #<Mutant::Matcher::Config empty>
Integration: null
Jobs: 1
Jobs: auto
Includes: []
Requires: []
Subjects: 1
Expand All @@ -84,7 +84,7 @@ def self.it_reports(expected_content)
Mutant environment:
Matcher: #<Mutant::Matcher::Config empty>
Integration: null
Jobs: 1
Jobs: auto
Includes: []
Requires: []
Subjects: 1
Expand Down