Sync devtools and fix rubocop warnings

This commit is contained in:
Markus Schirp 2014-06-08 13:01:26 +00:00
parent ac07bfdb0d
commit 8d31d52a93
16 changed files with 76 additions and 105 deletions

View file

@ -1,9 +1,9 @@
# encoding: utf-8
group :development do
gem 'rake', '~> 10.3.1'
gem 'rspec', '~> 2.99.0.beta2'
gem 'rspec-core', '~> 2.99.0.beta2'
gem 'rake', '~> 10.3.2'
gem 'rspec', '~> 2.99.0'
gem 'rspec-core', '~> 2.99.0'
gem 'yard', '~> 0.8.7.4'
platform :rbx do
@ -11,30 +11,34 @@ group :development do
end
end
group :yard do
gem 'kramdown', '~> 1.3.3'
end
group :guard do
gem 'guard', '~> 2.6.0'
gem 'guard', '~> 2.6.1'
gem 'guard-bundler', '~> 2.0.0'
gem 'guard-rspec', '~> 4.2.8'
gem 'guard-rspec', '~> 4.2.9'
gem 'guard-rubocop', '~> 1.1.0'
# file system change event handling
gem 'listen', '~> 2.7.3'
gem 'listen', '~> 2.7.7'
gem 'rb-fchange', '~> 0.0.6', require: false
gem 'rb-fsevent', '~> 0.9.4', require: false
gem 'rb-inotify', '~> 0.9.4', require: false
gem 'rb-inotify', '~> 0.9.5', require: false
# notification handling
gem 'libnotify', '~> 0.8.2', require: false
gem 'libnotify', '~> 0.8.3', require: false
gem 'rb-notifu', '~> 0.0.4', require: false
gem 'terminal-notifier-guard', '~> 1.5.3', require: false
end
group :metrics do
gem 'coveralls', '~> 0.7.0'
gem 'flay', '~> 2.4.0'
gem 'flog', '~> 4.2.0'
gem 'flay', '~> 2.5.0'
gem 'flog', '~> 4.2.1'
gem 'reek', '~> 1.3.7'
gem 'rubocop', '~> 0.21.0'
gem 'rubocop', '~> 0.23.0'
gem 'simplecov', '~> 0.7.1'
gem 'yardstick', '~> 0.9.9'

View file

@ -120,9 +120,7 @@ module Mutant
# @api private
#
def subject_selector
if @subject_selectors.any?
Morpher::Evaluator::Predicate::Boolean::Or.new(@subject_selectors)
end
Morpher::Evaluator::Predicate::Boolean::Or.new(@subject_selectors) if @subject_selectors.any?
end
# Return predicate
@ -153,6 +151,10 @@ module Mutant
# Return subject rejector
#
# @return [#call]
# if there is a subject rejector
#
# @return [nil]
# otherwise
#
# @api private
#
@ -161,9 +163,7 @@ module Mutant
Morpher.compile(s(:eql, s(:attribute, :identification), s(:static, subject.identification)))
end
if rejectors.any?
Morpher::Evaluator::Predicate::Boolean::Or.new(rejectors)
end
Morpher::Evaluator::Predicate::Boolean::Or.new(rejectors) if rejectors.any?
end
end

View file

@ -16,10 +16,9 @@ module Mutant
# @api private
#
def diff
if diffs.length.equal?(1)
::Diff::LCS::Hunk.new(old, new, diffs.first, max_length, 0)
.diff(:unified) << "\n"
end
return unless diffs.length.equal?(1)
::Diff::LCS::Hunk.new(old, new, diffs.first, max_length, 0)
.diff(:unified) << "\n"
end
memoize :diff

View file

@ -99,9 +99,8 @@ module Mutant
def self.expressions(input)
REGISTRY.each_with_object([]) do |(regexp, klass), expressions|
match = regexp.match(input)
if match
expressions << klass.new(match)
end
next unless match
expressions << klass.new(match)
end
end
private_class_method :expressions

View file

@ -95,9 +95,7 @@ Fix your lib to support normal ruby semantics!
MESSAGE
return
end
if pattern =~ name
yield scope
end
yield scope if pattern =~ name
end
end # Namespace

View file

@ -91,9 +91,10 @@ module Mutant
# @api private
#
def missing_report
if missing.any?
['Missing mutations:', missing.map(&method(:format_mutation)).join("\n-----\n")]
end
[
'Missing mutations:',
missing.map(&method(:format_mutation)).join("\n-----\n")
] if missing.any?
end
# Return unexpected report
@ -103,12 +104,10 @@ module Mutant
# @api private
#
def unexpected_report
if unexpected.any?
[
'Unexpected mutations:',
unexpected.map(&method(:format_mutation)).join("\n-----\n")
]
end
[
'Unexpected mutations:',
unexpected.map(&method(:format_mutation)).join("\n-----\n")
] if unexpected.any?
end
# Format mutation

View file

@ -119,34 +119,6 @@ module Mutant
emit!(object)
end
# Maximum amount of tries to generate a new object
MAX_TRIES = 3
# Call block until it generates a mutation
#
# @yield
# Execute block until object is generated where new?(object) returns true
#
# @return [self]
#
# @raise [RuntimeError]
# raises RuntimeError when no new node can be generated after MAX_TRIES.
#
# @api private
#
def emit_new
MAX_TRIES.times do
object = yield
if new?(object)
emit!(object)
return
end
end
raise "New AST could not be generated after #{MAX_TRIES} attempts"
end
# Call block with node
#
# @param [Parser::AST::Node] node

View file

@ -122,9 +122,8 @@ module Mutant
block ||= ->(_node) { true }
child = children.at(index)
mutator.each(child, self) do |mutation|
if block.call(mutation)
emit_child_update(index, mutation)
end
next unless block.call(mutation)
emit_child_update(index, mutation)
end
end

View file

@ -44,9 +44,8 @@ module Mutant
def emit_argument_mutations
children.each_with_index do |child, index|
Mutator.each(child) do |mutant|
unless invalid_argument_replacement?(mutant, index)
emit_child_update(index, mutant)
end
next if invalid_argument_replacement?(mutant, index)
emit_child_update(index, mutant)
end
end
end

View file

@ -50,10 +50,9 @@ module Mutant
def emit_else_mutations
else_branch = children.last
else_index = children.length - 1
if else_branch
mutate_child(else_index)
emit_child_update(else_index, nil)
end
return unless else_branch
mutate_child(else_index)
emit_child_update(else_index, nil)
end
end # Case

View file

@ -48,10 +48,9 @@ module Mutant
#
def mutate_if_branch
emit_type(condition, else_branch, nil) if else_branch
if if_branch
emit_if_branch_mutations
emit_type(condition, if_branch, nil)
end
return unless if_branch
emit_if_branch_mutations
emit_type(condition, if_branch, nil)
end
# Emit else branch mutations
@ -61,10 +60,9 @@ module Mutant
# @api private
#
def mutate_else_branch
if else_branch
emit_else_branch_mutations
emit_type(condition, nil, else_branch)
end
return unless else_branch
emit_else_branch_mutations
emit_type(condition, nil, else_branch)
end
end # If

View file

@ -21,9 +21,8 @@ module Mutant
emit_singletons
emit_type
mutate_body
if children.one?
emit(children.first)
end
return unless children.one?
emit(children.first)
end
# Mutate body

View file

@ -20,10 +20,9 @@ module Mutant
#
def dispatch
emit_singletons
if value
emit(value)
emit_value_mutations
end
return unless value
emit(value)
emit_value_mutations
end
end # Return

View file

@ -183,12 +183,20 @@ module Mutant
# @api private
#
def emit_implicit_self
if receiver.type == :self &&
!KEYWORDS.include?(selector) &&
!attribute_assignment? &&
!OP_ASSIGN.include?(parent_type)
emit_receiver(nil)
end
emit_receiver(nil) if allow_implicit_self?
end
# Test if implicit self is allowed
#
# @return [Boolean]
#
# @api private
#
def allow_implicit_self?
receiver.type == :self &&
!KEYWORDS.include?(selector) &&
!attribute_assignment? &&
!OP_ASSIGN.include?(parent_type)
end
# Test for assignment

View file

@ -220,5 +220,3 @@ Mutant::Meta::Example.add do
end
RUBY
end

View file

@ -30,12 +30,14 @@ describe 'Mutant on ruby corpus' do
def verify
checkout
start = Time.now
total = Parallel.map(Pathname.glob(repo_path.join('**/*.rb')).sort_by(&:size).reverse, finish: method(:progress)) do |path|
paths = Pathname.glob(repo_path.join('**/*.rb')).sort_by(&:size).reverse
total = Parallel.map(paths, finish: method(:progress)) do |path|
count = 0
node =
begin
Parser::CurrentRuby.parse(path.read)
rescue EncodingError, ArgumentError
:foo # make rubocop happy
end
unless node.nil?
Mutant::Mutator::Node.each(node) do
@ -95,7 +97,7 @@ describe 'Mutant on ruby corpus' do
#
def progress(path, _index, count)
MUTEX.synchronize do
puts 'Mutations - %4i - %s' % [count, path]
puts format('Mutations - %4i - %s', count, path)
end
end
@ -106,12 +108,11 @@ describe 'Mutant on ruby corpus' do
# @api private
#
def system(arguments)
unless Kernel.system(*arguments)
if block_given?
yield
else
raise 'System command failed!'
end
return if Kernel.system(*arguments)
if block_given?
yield
else
raise 'System command failed!'
end
end