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

Fix forward argument mutations #1317

Merged
merged 5 commits into from
Apr 10, 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
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Base steps
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Check Whitespace
run: git diff --check -- HEAD~1
ruby-spec:
Expand All @@ -23,7 +23,7 @@ jobs:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -39,7 +39,7 @@ jobs:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ruby/setup-ruby@v1
Expand All @@ -57,7 +57,7 @@ jobs:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -77,7 +77,7 @@ jobs:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -93,7 +93,7 @@ jobs:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -109,7 +109,7 @@ jobs:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -125,7 +125,7 @@ jobs:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand Down
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.11.6 2022-04-10

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

Fix forward arg mutations.

# v0.11.5 2022-04-03

* [#1314](https://github.com/mbj/mutant/pull/1314)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
mutant (0.11.5)
mutant (0.11.6)
diff-lcs (~> 1.3)
parser (~> 3.1.0)
regexp_parser (~> 2.0, >= 2.0.3)
Expand Down
5 changes: 0 additions & 5 deletions foo.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/mutant/mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Mutation
include Concord::Public.new(:subject, :node)

CODE_DELIMITER = "\0"
CODE_RANGE = (0..4).freeze
CODE_RANGE = (..4).freeze

# Mutation identification code
#
Expand Down
24 changes: 17 additions & 7 deletions lib/mutant/mutator/node/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,27 @@ def dispatch
end

def emit_argument_presence
emit_type unless removed_block_arg?(EMPTY_ARRAY)
emit_type unless removed_block_arg?(EMPTY_ARRAY) || forward_arg?

Util::Array::Presence.call(children).each do |children|
unless removed_block_arg?(children) || (children.one? && n_mlhs?(children.first))
emit_type(*children)
children.each_with_index do |removed, index|
new_arguments = children.dup
new_arguments.delete_at(index)
unless n_forward_arg?(removed) || removed_block_arg?(new_arguments) || only_mlhs?(new_arguments)
emit_type(*new_arguments)
end
end
end

def removed_block_arg?(children)
anonymous_block_arg? && children.none?(&ANONYMOUS_BLOCKARG_PRED)
def only_mlhs?(new_arguments)
new_arguments.one? && n_mlhs?(new_arguments.first)
end

def forward_arg?
children.last && n_forward_arg?(children.last)
end

def removed_block_arg?(new_arguments)
anonymous_block_arg? && new_arguments.none?(&ANONYMOUS_BLOCKARG_PRED)
end

def anonymous_block_arg?
Expand All @@ -47,7 +57,7 @@ def emit_argument_mutations
end

def invalid_argument_replacement?(mutant, index)
n_arg?(mutant) && children[0...index].any?(&method(:n_optarg?))
n_arg?(mutant) && children[...index].any?(&method(:n_optarg?))
end

def emit_mlhs_expansion
Expand Down
4 changes: 3 additions & 1 deletion lib/mutant/mutator/node/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ def emit_argument_propagation

argument = Mutant::Util.one(arguments)

emit_propagation(argument) unless n_kwargs?(argument)
return if n_kwargs?(argument) || n_forwarded_args?(argument)

emit_propagation(argument)
end

def mutate_receiver
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/mutator/node/send/attribute_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Send
# Mutator for attribute assignments
class AttributeAssignment < self

ATTRIBUTE_RANGE = (0..-2).freeze
ATTRIBUTE_RANGE = (..-2).freeze

private_constant(*constants(false))

Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/mutator/node/when.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def dispatch

def mutate_conditions
conditions = children.length - 1
children[0..-2].each_index do |index|
children[..-2].each_index do |index|
delete_child(index) if conditions > 1
mutate_child(index)
end
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.5'
VERSION = '0.11.6'
end # Mutant
27 changes: 26 additions & 1 deletion meta/def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@
end

Mutant::Meta::Example.add :def do

source 'def self.foo(a, b); end'

# Deletion of each argument
Expand All @@ -188,3 +187,29 @@
mutation 'def self.foo(a, b); raise; end'
mutation 'def self.foo(a, b); super; end'
end

Mutant::Meta::Example.add :def do
source 'def foo(...); end'

mutation 'def foo(...); raise; end'
mutation 'def foo(...); super; end'
end

Mutant::Meta::Example.add :def do
source 'def foo(a, ...); end'

mutation 'def foo(_a, ...); end'
mutation 'def foo(a, ...); raise; end'
mutation 'def foo(a, ...); super; end'
mutation 'def foo(...); end'
end

Mutant::Meta::Example.add :def, :send do
source 'def foo(...); bar(...) end'

mutation 'def foo(...); bar; end'
mutation 'def foo(...); raise; end'
mutation 'def foo(...); super; end'
mutation 'def foo(...); nil; end'
mutation 'def foo(...); end'
end
2 changes: 1 addition & 1 deletion spec/support/xspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def self.assert_not_empty(event_list)
private_class_method :assert_not_empty

def self.assert_total(event_list)
return unless event_list[0..-2].map(&:first).any?(&TERMINATE_EVENTS.public_method(:include?))
return unless event_list[..-2].map(&:first).any?(&TERMINATE_EVENTS.public_method(:include?))

fail "Reaction not total: #{event_list}"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/mutant/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def self.main_body

let(:expected_events) do
[
*super()[0..-2],
*super()[..-2],
[
:stderr,
:puts,
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/mutant/expression/namespace/recursive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@
context 'on constants' do
let(:other) { parse_expression('TestApp::Literal::Deep') }

it { should be(input[0..-2].length) }
it { should be(input[..-2].length) }
end

context 'on singleton method' do
let(:other) { parse_expression('TestApp::Literal.foo') }

it { should be(input[0..-2].length) }
it { should be(input[..-2].length) }
end

context 'on instance method' do
let(:other) { parse_expression('TestApp::Literal#foo') }

it { should be(input[0..-2].length) }
it { should be(input[..-2].length) }
end
end
end
Expand Down