Cleanup CLI implementation a bit.
This commit is contained in:
parent
ad82b0fc4f
commit
1b0ed70ba4
5 changed files with 24 additions and 30 deletions
|
@ -89,7 +89,7 @@ MultilineBlockChain:
|
|||
Enabled: false
|
||||
|
||||
ClassLength:
|
||||
Max: 105
|
||||
Max: 109
|
||||
|
||||
# I align private keywords with class body
|
||||
IndentationWidth:
|
||||
|
|
|
@ -43,6 +43,7 @@ module Mutant
|
|||
def initialize(arguments = [])
|
||||
@filters, @matchers = [], []
|
||||
@debug = @fail_fast = @zombie = false
|
||||
@strategy = Strategy::Null.new
|
||||
@cache = Mutant::Cache.new
|
||||
parse(arguments)
|
||||
config # trigger lazyness now
|
||||
|
@ -61,7 +62,7 @@ module Mutant
|
|||
debug: @debug,
|
||||
matcher: matcher,
|
||||
subject_predicate: @subject_predicate.output,
|
||||
strategy: @strategy || Strategy::Null.new,
|
||||
strategy: @strategy,
|
||||
fail_fast: @fail_fast,
|
||||
reporter: reporter
|
||||
)
|
||||
|
@ -189,19 +190,21 @@ module Mutant
|
|||
end
|
||||
end
|
||||
|
||||
# Add runner
|
||||
# Use plugin
|
||||
#
|
||||
# @param [String] runner_name
|
||||
# FIXME: For now all plugins are strategies. Later they could be anything that allows "late integration".
|
||||
#
|
||||
# @param [String] name
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def set_strategy(name)
|
||||
def use(name)
|
||||
require "mutant/#{name}"
|
||||
@strategy = Strategy.lookup(name).new
|
||||
rescue LoadError
|
||||
$stderr.puts("Cannot load strategy: #{name.inspect}")
|
||||
$stderr.puts("Cannot load plugin: #{name.inspect}")
|
||||
raise
|
||||
end
|
||||
|
||||
|
@ -217,11 +220,9 @@ module Mutant
|
|||
opts.separator ''
|
||||
opts.separator 'Options:'
|
||||
|
||||
opts.on('--via STRATEGY', 'Use STRATEGY for killing mutations') do |runner|
|
||||
set_strategy(runner)
|
||||
end
|
||||
|
||||
opts.on('--version', 'Print mutants version') do |name|
|
||||
opts.on('--use STRATEGY', 'Use STRATEGY for killing mutations') do |runner|
|
||||
use(runner)
|
||||
end.on('--version', 'Print mutants version') do |name|
|
||||
puts("mutant-#{Mutant::VERSION}")
|
||||
Kernel.exit(0)
|
||||
end.on('--code FILTER', 'Adds a code filter') do |filter|
|
||||
|
|
|
@ -4,7 +4,7 @@ module Mutant
|
|||
|
||||
# Abstract base class for killing strategies
|
||||
class Strategy
|
||||
include AbstractType, Adamantium::Flat
|
||||
include AbstractType, Adamantium::Flat, Equalizer.new
|
||||
|
||||
REGISTRY = {}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ describe Mutant, 'rspec integration' do
|
|||
end
|
||||
end
|
||||
|
||||
let(:base_cmd) { 'bundle exec mutant -I lib --require test_app --via rspec' }
|
||||
let(:base_cmd) { 'bundle exec mutant -I lib --require test_app --use rspec' }
|
||||
|
||||
specify 'it allows to kill mutations' do
|
||||
Kernel.system("#{base_cmd} ::TestApp::Literal#string").should be(true)
|
||||
|
|
|
@ -28,7 +28,7 @@ describe Mutant::CLI, '.new' do
|
|||
|
||||
# Defaults
|
||||
let(:expected_filter) { Mutant::Predicate::TAUTOLOGY }
|
||||
let(:expected_strategy) { Mutant::Rspec::Strategy.new }
|
||||
let(:expected_strategy) { Mutant::Strategy::Null.new }
|
||||
let(:expected_reporter) { Mutant::Reporter::CLI.new($stdout) }
|
||||
|
||||
let(:ns) { Mutant::Matcher }
|
||||
|
@ -54,13 +54,6 @@ describe Mutant::CLI, '.new' do
|
|||
it_should_behave_like 'an invalid cli run'
|
||||
end
|
||||
|
||||
context 'with many strategy flags' do
|
||||
let(:arguments) { %w(--rspec --rspec TestApp) }
|
||||
let(:expected_matcher) { Mutant::Matcher::Scope.new(cache, TestApp) }
|
||||
|
||||
it_should_behave_like 'a cli parser'
|
||||
end
|
||||
|
||||
context 'without arguments' do
|
||||
let(:arguments) { [] }
|
||||
|
||||
|
@ -70,22 +63,22 @@ describe Mutant::CLI, '.new' do
|
|||
end
|
||||
|
||||
context 'with code filter and missing argument' do
|
||||
let(:arguments) { %w(--rspec --code) }
|
||||
let(:arguments) { %w(--code) }
|
||||
let(:expected_message) { 'missing argument: --code' }
|
||||
|
||||
it_should_behave_like 'an invalid cli run'
|
||||
end
|
||||
|
||||
context 'with explicit method matcher' do
|
||||
let(:arguments) { %w(--rspec TestApp::Literal#float) }
|
||||
let(:arguments) { %w(TestApp::Literal#float) }
|
||||
let(:expected_matcher) { ns::Method::Instance.new(cache, TestApp::Literal, TestApp::Literal.instance_method(:float)) }
|
||||
|
||||
it_should_behave_like 'a cli parser'
|
||||
end
|
||||
|
||||
context 'with debug flag' do
|
||||
let(:matcher) { '::TestApp*' }
|
||||
let(:arguments) { %W(--debug --rspec #{matcher}) }
|
||||
let(:matcher) { '::TestApp*' }
|
||||
let(:arguments) { %W(--debug #{matcher}) }
|
||||
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
|
||||
|
||||
it_should_behave_like 'a cli parser'
|
||||
|
@ -96,8 +89,8 @@ describe Mutant::CLI, '.new' do
|
|||
end
|
||||
|
||||
context 'with zombie flag' do
|
||||
let(:matcher) { '::TestApp*' }
|
||||
let(:arguments) { %W(--zombie --rspec #{matcher}) }
|
||||
let(:matcher) { '::TestApp*' }
|
||||
let(:arguments) { %W(--zombie #{matcher}) }
|
||||
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
|
||||
|
||||
it_should_behave_like 'a cli parser'
|
||||
|
@ -108,8 +101,8 @@ describe Mutant::CLI, '.new' do
|
|||
end
|
||||
|
||||
context 'with namespace matcher' do
|
||||
let(:matcher) { '::TestApp*' }
|
||||
let(:arguments) { %W(--rspec #{matcher}) }
|
||||
let(:matcher) { '::TestApp*' }
|
||||
let(:arguments) { %W(#{matcher}) }
|
||||
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
|
||||
|
||||
it_should_behave_like 'a cli parser'
|
||||
|
@ -117,7 +110,7 @@ describe Mutant::CLI, '.new' do
|
|||
|
||||
context 'with code filter' do
|
||||
let(:matcher) { 'TestApp::Literal#float' }
|
||||
let(:arguments) { %W(--rspec --code faa --code bbb #{matcher}) }
|
||||
let(:arguments) { %W(--code faa --code bbb #{matcher}) }
|
||||
|
||||
let(:filters) do
|
||||
[
|
||||
|
|
Loading…
Add table
Reference in a new issue