Fix style
This commit is contained in:
parent
ae65509258
commit
2ce02af8aa
24 changed files with 154 additions and 104 deletions
|
@ -5,4 +5,6 @@ AllCops:
|
|||
- 'Gemfile.devtools'
|
||||
- 'vendor/**/*'
|
||||
- 'tmp/**/*'
|
||||
- 'test_app/**/*'
|
||||
- 'benchmarks/**/*'
|
||||
- 'bin/mutant'
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 18
|
||||
total_score: 1191
|
||||
total_score: 1198
|
||||
|
|
|
@ -1,18 +1,5 @@
|
|||
inherit_from: ../.rubocop.yml
|
||||
|
||||
# General note about rubocop.
|
||||
# It does NOT allow to silence a specific rule violation.
|
||||
# For that reason I sometimes have to disable a whole cop where
|
||||
# I just tried to whitelist a specific occurrence.
|
||||
|
||||
|
||||
AllCops:
|
||||
Include:
|
||||
- '../**/*.rake'
|
||||
- 'Gemfile'
|
||||
- 'Gemfile.triage'
|
||||
- 'mutant.gemspec'
|
||||
|
||||
# Avoid parameter lists longer than five parameters.
|
||||
ParameterLists:
|
||||
Max: 3
|
||||
|
@ -30,53 +17,31 @@ CollectionMethods:
|
|||
find: 'detect'
|
||||
find_all: 'select'
|
||||
|
||||
# Use square brackets for literal Array objects
|
||||
PercentLiteralDelimiters:
|
||||
PreferredDelimiters:
|
||||
'%': ()
|
||||
'%i': '[]'
|
||||
'%q': ()
|
||||
'%Q': ()
|
||||
'%r': '{}'
|
||||
'%s': ()
|
||||
'%w': '[]'
|
||||
'%W': '[]'
|
||||
'%x': ()
|
||||
|
||||
MethodLength:
|
||||
CountComments: false
|
||||
Max: 17 # TODO: Bring down to 10
|
||||
|
||||
RegexpLiteral: # I do not agree %r(\A) is more readable than /\A/
|
||||
# Do not force public/protected/private keyword to be indented at the same
|
||||
# level as the def keyword. My personal preference is to outdent these keywords
|
||||
# because I think when scanning code it makes it easier to identify the
|
||||
# sections of code and visually separate them. When the keyword is at the same
|
||||
# level I think it sort of blends in with the def keywords and makes it harder
|
||||
# to scan the code and see where the sections are.
|
||||
AccessModifierIndentation:
|
||||
Enabled: false
|
||||
|
||||
Eval:
|
||||
Enabled: false # Mutant must use Kernel#eval to inject mutated source
|
||||
|
||||
# Limit line length
|
||||
LineLength:
|
||||
Max: 124 # TODO: lower to 79
|
||||
Max: 120
|
||||
|
||||
# Disable documentation checking until a class needs to be documented once
|
||||
Documentation:
|
||||
Enabled: false
|
||||
|
||||
# Do not always use &&/|| instead of and/or.
|
||||
AndOr:
|
||||
Enabled: false
|
||||
|
||||
# Do not favor modifier if/unless usage when you have a single-line body
|
||||
IfUnlessModifier:
|
||||
Enabled: false
|
||||
|
||||
# Mutant needs to define methods like def bar; end in specs
|
||||
Semicolon:
|
||||
Enabled: false
|
||||
|
||||
# Mutant needs to define multiple methods on same line in specs
|
||||
EmptyLineBetweenDefs:
|
||||
Enabled: false
|
||||
|
||||
# Mutant needs to define singleton methods like Foo.bar in specs
|
||||
ClassMethods:
|
||||
Enabled: false
|
||||
|
||||
# Allow case equality operator (in limited use within the specs)
|
||||
CaseEquality:
|
||||
Enabled: false
|
||||
|
@ -89,33 +54,63 @@ ConstantName:
|
|||
TrivialAccessors:
|
||||
Enabled: false
|
||||
|
||||
# And also have a different opinion here
|
||||
AndOr:
|
||||
# Allow empty lines around class body
|
||||
EmptyLinesAroundClassBody:
|
||||
Enabled: false
|
||||
|
||||
# I like my raise
|
||||
SignalException:
|
||||
# Allow empty lines around module body
|
||||
EmptyLinesAroundModuleBody:
|
||||
Enabled: false
|
||||
|
||||
# I need to chain optparse builder, else it is more ugly
|
||||
MultilineBlockChain:
|
||||
# Allow empty lines around block body
|
||||
EmptyLinesAroundBlockBody:
|
||||
Enabled: false
|
||||
|
||||
ClassLength:
|
||||
Max: 119
|
||||
|
||||
# I align private keywords with class body
|
||||
IndentationWidth:
|
||||
# Allow multiple line operations to not require indentation
|
||||
MultilineOperationIndentation:
|
||||
Enabled: false
|
||||
|
||||
# I like to have an empty line before closing the currently opened body
|
||||
EmptyLinesAroundBody:
|
||||
# Prefer String#% over Kernel#sprintf
|
||||
FormatString:
|
||||
Enabled: false
|
||||
|
||||
# I test this style for a while
|
||||
# Use square brackets for literal Array objects
|
||||
PercentLiteralDelimiters:
|
||||
PreferredDelimiters:
|
||||
'%': '{}'
|
||||
'%i': '[]'
|
||||
'%q': ()
|
||||
'%Q': ()
|
||||
'%r': '{}'
|
||||
'%s': ()
|
||||
'%w': '[]'
|
||||
'%W': '[]'
|
||||
'%x': ()
|
||||
|
||||
# Align if/else blocks with the variable assignment
|
||||
EndAlignment:
|
||||
AlignWith: variable
|
||||
|
||||
# Do not always align parameters when it is easier to read
|
||||
AlignParameters:
|
||||
Exclude:
|
||||
- spec/**/*_spec.rb
|
||||
|
||||
# Prefer #kind_of? over #is_a?
|
||||
ClassCheck:
|
||||
EnforcedStyle: kind_of?
|
||||
|
||||
# Do not prefer double quotes to be used when %q or %Q is more appropriate
|
||||
UnneededPercentQ:
|
||||
Enabled: false
|
||||
|
||||
# Allow a maximum ABC score
|
||||
Metrics/AbcSize:
|
||||
Max: 18.00
|
||||
|
||||
# Do not prefer lambda.call(...) over lambda.(...)
|
||||
LambdaCall:
|
||||
Enabled: false
|
||||
|
||||
# I like my style more
|
||||
AccessModifierIndentation:
|
||||
Enabled: false
|
||||
Style/RegexpLiteral:
|
||||
MaxSlashes: 0
|
||||
|
|
|
@ -74,6 +74,8 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# rubocop:disable MethodLength
|
||||
#
|
||||
def self.singleton_subclass_instance(name, superclass, &block)
|
||||
klass = Class.new(superclass) do
|
||||
def inspect
|
||||
|
|
|
@ -15,7 +15,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def self.walk(node, stack, &block)
|
||||
raise ArgumentError, 'block expected' unless block_given?
|
||||
fail ArgumentError, 'block expected' unless block_given?
|
||||
|
||||
block.call(node, stack)
|
||||
node.children.grep(Parser::AST::Node).each do |child|
|
||||
|
|
|
@ -74,7 +74,7 @@ module Mutant
|
|||
|
||||
parse_match_expressions(opts.parse!(arguments))
|
||||
rescue OptionParser::ParseError => error
|
||||
fail(Error, error.message, error.backtrace)
|
||||
raise(Error, error.message, error.backtrace)
|
||||
end
|
||||
|
||||
# Parse matchers
|
||||
|
@ -101,6 +101,8 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# rubocop:disable MethodLength
|
||||
#
|
||||
def add_environment_options(opts)
|
||||
opts.separator('Environment:')
|
||||
opts.on('--zombie', 'Run mutant zombified') do
|
||||
|
@ -129,7 +131,7 @@ module Mutant
|
|||
require "mutant/integration/#{name}"
|
||||
update(integration: Integration.lookup(name))
|
||||
rescue LoadError
|
||||
fail Error, "Could not load integration #{name.inspect} (you may want to try installing the gem mutant-#{name})"
|
||||
raise Error, "Could not load integration #{name.inspect} (you may want to try installing the gem mutant-#{name})"
|
||||
end
|
||||
|
||||
# Add options
|
||||
|
@ -146,7 +148,8 @@ module Mutant
|
|||
|
||||
opts.on('--score COVERAGE', 'Fail unless COVERAGE is not reached exactly') do |coverage|
|
||||
update(expected_coverage: Float(coverage))
|
||||
end.on('--use STRATEGY', 'Use STRATEGY for killing mutations', &method(:setup_integration))
|
||||
end
|
||||
opts.on('--use STRATEGY', 'Use STRATEGY for killing mutations', &method(:setup_integration))
|
||||
end
|
||||
|
||||
# Add filter options
|
||||
|
@ -177,12 +180,15 @@ module Mutant
|
|||
def add_debug_options(opts)
|
||||
opts.on('--fail-fast', 'Fail fast') do
|
||||
update(fail_fast: true)
|
||||
end.on('--version', 'Print mutants version') do
|
||||
end
|
||||
opts.on('--version', 'Print mutants version') do
|
||||
puts("mutant-#{Mutant::VERSION}")
|
||||
Kernel.exit(EXIT_SUCCESS)
|
||||
end.on('-d', '--debug', 'Enable debugging output') do
|
||||
end
|
||||
opts.on('-d', '--debug', 'Enable debugging output') do
|
||||
update(debug: true)
|
||||
end.on_tail('-h', '--help', 'Show this message') do
|
||||
end
|
||||
opts.on_tail('-h', '--help', 'Show this message') do
|
||||
puts(opts.to_s)
|
||||
Kernel.exit(EXIT_SUCCESS)
|
||||
end
|
||||
|
|
|
@ -125,7 +125,7 @@ module Mutant
|
|||
def expression(scope)
|
||||
name = scope_name(scope) or return
|
||||
|
||||
unless name.is_a?(String)
|
||||
unless name.instance_of?(String)
|
||||
warn("#{scope.class}#name from: #{scope.inspect} returned #{name.inspect}. #{SEMANTICS_MESSAGE}")
|
||||
return
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ module Mutant
|
|||
def self.call(&block)
|
||||
block.call
|
||||
rescue => exception
|
||||
fail Error, exception
|
||||
raise Error, exception
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -37,6 +37,8 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# rubocop:disable MethodLength
|
||||
#
|
||||
def self.call(&block)
|
||||
reader, writer = IO.pipe.map(&:binmode)
|
||||
|
||||
|
@ -52,7 +54,7 @@ module Mutant
|
|||
writer.close
|
||||
Marshal.load(reader.read)
|
||||
rescue => exception
|
||||
fail Error, exception
|
||||
raise Error, exception
|
||||
ensure
|
||||
Process.waitpid(pid) if pid
|
||||
end
|
||||
|
|
|
@ -12,6 +12,10 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# One off the very few valid uses of eval
|
||||
#
|
||||
# rubocop:disable Lint/Eval
|
||||
#
|
||||
def call
|
||||
eval(
|
||||
source,
|
||||
|
|
|
@ -42,6 +42,8 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# rubocop:disable MethodLength
|
||||
#
|
||||
def predicate
|
||||
if subject_selector && subject_rejector
|
||||
Morpher::Evaluator::Predicate::Boolean::And.new([
|
||||
|
|
|
@ -16,6 +16,8 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# rubocop:disable MethodLength
|
||||
#
|
||||
def kill(isolation, integration)
|
||||
start = Time.now
|
||||
tests = subject.tests
|
||||
|
|
|
@ -19,7 +19,7 @@ module Mutant
|
|||
emit_singletons unless parent_node && n_const?(parent_node)
|
||||
emit_type(nil, *children.drop(1))
|
||||
children.each_with_index do |child, index|
|
||||
mutate_child(index) if child.is_a?(Parser::AST::Node)
|
||||
mutate_child(index) if child.instance_of?(Parser::AST::Node)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ module Mutant
|
|||
#
|
||||
def dispatch
|
||||
children.each_with_index do |child, index|
|
||||
mutate_child(index) if child.is_a?(Parser::AST::Node)
|
||||
mutate_child(index) if child.instance_of?(Parser::AST::Node)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# rubocop:disable MethodLength
|
||||
#
|
||||
def run
|
||||
config.jobs.times do
|
||||
@workers += 1
|
||||
|
|
|
@ -14,13 +14,11 @@ module Mutant
|
|||
#
|
||||
def self.build(output)
|
||||
tty = output.respond_to?(:tty?) && output.tty?
|
||||
format =
|
||||
if !Mutant.ci? && tty && Tput::INSTANCE.available
|
||||
Format::Framed.new(tty: tty, tput: Tput::INSTANCE)
|
||||
else
|
||||
Format::Progressive.new(tty: tty)
|
||||
end
|
||||
|
||||
format = if !Mutant.ci? && tty && Tput::INSTANCE.available
|
||||
Format::Framed.new(tty: tty, tput: Tput::INSTANCE)
|
||||
else
|
||||
Format::Progressive.new(tty: tty)
|
||||
end
|
||||
new(output, format)
|
||||
end
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def active_subject_results
|
||||
active_mutation_jobs = active_jobs.select { |job| job.payload.is_a?(Mutant::Mutation) }
|
||||
active_mutation_jobs = active_jobs.select { |job| job.payload.kind_of?(Mutant::Mutation) }
|
||||
active_subjects = active_mutation_jobs.map(&:payload).flat_map(&:subject).to_set
|
||||
|
||||
payload.subject_results.select do |subject_result|
|
||||
|
@ -197,6 +197,8 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# rubocop:disable AbcSize
|
||||
#
|
||||
def run
|
||||
info 'Mutant configuration:'
|
||||
info 'Matcher: %s', object.matcher_config.inspect
|
||||
|
@ -231,6 +233,8 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# rubocop:disable MethodLength
|
||||
#
|
||||
def run
|
||||
visit(Config, env.config)
|
||||
info 'Subjects: %s', amount_subjects
|
||||
|
@ -480,7 +484,8 @@ module Mutant
|
|||
|
||||
delegate :mutation, :test_result
|
||||
|
||||
DIFF_ERROR_MESSAGE = 'BUG: Mutation NOT resulted in exactly one diff hunk. Please report a reproduction!'.freeze
|
||||
DIFF_ERROR_MESSAGE =
|
||||
'BUG: Mutation NOT resulted in exactly one diff hunk. Please report a reproduction!'.freeze
|
||||
|
||||
MAP = {
|
||||
Mutant::Mutation::Evil => :evil_details,
|
||||
|
|
|
@ -10,6 +10,10 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# Probably one of the only valid uses of eval.
|
||||
#
|
||||
# rubocop:disable Lint/Eval
|
||||
#
|
||||
def zombify(namespace)
|
||||
$stderr.puts("Zombifying #{path}")
|
||||
eval(
|
||||
|
@ -33,15 +37,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def self.find(logical_name)
|
||||
file_name =
|
||||
case ::File.extname(logical_name)
|
||||
when '.so'
|
||||
return
|
||||
when '.rb'
|
||||
logical_name
|
||||
else
|
||||
"#{logical_name}.rb"
|
||||
end
|
||||
file_name = expand_file_name(logical_name)
|
||||
|
||||
$LOAD_PATH.each do |path|
|
||||
path = Pathname.new(path).join(file_name)
|
||||
|
@ -52,6 +48,29 @@ module Mutant
|
|||
nil
|
||||
end
|
||||
|
||||
# Return expanded file name
|
||||
#
|
||||
# @param [String] logical_name
|
||||
#
|
||||
# @return [nil]
|
||||
# if no expansion is possible
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def self.expand_file_name(logical_name)
|
||||
case ::File.extname(logical_name)
|
||||
when '.so'
|
||||
return
|
||||
when '.rb'
|
||||
logical_name
|
||||
else
|
||||
"#{logical_name}.rb"
|
||||
end
|
||||
end
|
||||
private_class_method :expand_file_name
|
||||
|
||||
private
|
||||
|
||||
# Return node
|
||||
|
|
|
@ -47,6 +47,8 @@ module Corpus
|
|||
# otherwise
|
||||
#
|
||||
# rubocop:disable MethodLength
|
||||
# rubocop:disable AbcSize
|
||||
#
|
||||
def verify_mutation_generation
|
||||
checkout
|
||||
start = Time.now
|
||||
|
|
|
@ -12,7 +12,7 @@ module FakeActor
|
|||
|
||||
def verify(other)
|
||||
unless eql?(other)
|
||||
raise "Got:\n#{other.inspect}\nExpected:\n#{inspect}"
|
||||
fail "Got:\n#{other.inspect}\nExpected:\n#{inspect}"
|
||||
end
|
||||
block.call(other.message) if block
|
||||
end
|
||||
|
@ -31,16 +31,16 @@ module FakeActor
|
|||
end
|
||||
|
||||
def sending(expectation)
|
||||
raise "Unexpected send: #{expectation.inspect}" if messages.empty?
|
||||
fail "Unexpected send: #{expectation.inspect}" if messages.empty?
|
||||
expected = messages.shift
|
||||
expected.verify(expectation)
|
||||
self
|
||||
end
|
||||
|
||||
def receiving(name)
|
||||
raise "No message to read for #{name.inspect}" if messages.empty?
|
||||
fail "No message to read for #{name.inspect}" if messages.empty?
|
||||
expected = messages.shift
|
||||
raise "Unexpected message #{expected.inspect} for #{name.inspect}" unless expected.name.eql?(name)
|
||||
fail "Unexpected message #{expected.inspect} for #{name.inspect}" unless expected.name.eql?(name)
|
||||
expected.message
|
||||
end
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ private
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# rubocop:disable AbcSize
|
||||
#
|
||||
def mutation_report
|
||||
message = ['Original-AST:', original_node.inspect, 'Original-Source:', Unparser.unparse(original_node)]
|
||||
if missing.any?
|
||||
|
|
|
@ -8,12 +8,13 @@ module SharedContext
|
|||
def messages(&block)
|
||||
let(:message_sequence) do
|
||||
FakeActor::MessageSequence.new.tap do |sequence|
|
||||
sequence.instance_eval(&block)
|
||||
sequence.instance_eval(&block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:disable MethodLength
|
||||
# rubocop:disable AbcSize
|
||||
def setup_shared_context
|
||||
let(:env) { double('env', config: config, subjects: [subject_a], mutations: mutations) }
|
||||
let(:job_a) { Mutant::Parallel::Job.new(index: 0, payload: mutation_a) }
|
||||
|
|
|
@ -8,11 +8,13 @@ RSpec.describe Mutant::Env do
|
|||
it 'warns via reporter' do
|
||||
klass = Class.new do
|
||||
def self.name
|
||||
raise
|
||||
fail
|
||||
end
|
||||
end
|
||||
|
||||
expected_warnings = ["Class#name from: #{klass} raised an error: RuntimeError. #{Mutant::Env::SEMANTICS_MESSAGE}"]
|
||||
expected_warnings = [
|
||||
"Class#name from: #{klass} raised an error: RuntimeError. #{Mutant::Env::SEMANTICS_MESSAGE}"
|
||||
]
|
||||
|
||||
expect { subject }.to change { config.reporter.warn_calls }.from([]).to(expected_warnings)
|
||||
|
||||
|
|
|
@ -51,7 +51,10 @@ RSpec.describe Mutant::Expression do
|
|||
let(:input) { 'foo bar' }
|
||||
|
||||
it 'raises an exception' do
|
||||
expect { subject }.to raise_error(Mutant::Expression::InvalidExpressionError, 'Expression: "foo bar" is not valid')
|
||||
expect { subject }.to raise_error(
|
||||
Mutant::Expression::InvalidExpressionError,
|
||||
'Expression: "foo bar" is not valid'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ RSpec.describe Mutant::WarningFilter do
|
|||
it 'executes block with warning filter enabled' do
|
||||
found = false
|
||||
object.use do
|
||||
found = $stderr.is_a?(described_class)
|
||||
found = $stderr.instance_of?(described_class)
|
||||
end
|
||||
expect(found).to be(true)
|
||||
end
|
||||
|
@ -71,6 +71,7 @@ RSpec.describe Mutant::WarningFilter do
|
|||
|
||||
it 'returns warnings generated within block' do
|
||||
warnings = object.use do
|
||||
# rubocop:disable Lint/Eval
|
||||
eval(<<-RUBY)
|
||||
Class.new do
|
||||
def foo
|
||||
|
|
Loading…
Reference in a new issue