Skip to content

Commit

Permalink
Fix forwarded rest and kwrestarg
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Gollahon <[email protected]>
  • Loading branch information
mbj and dgollahon committed Oct 8, 2023
1 parent 77615bf commit 71b21fd
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 32 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.11.23 2023-10-08

* Fix restarg and kwrestarg invalid mutations.

# v0.11.22 2023-07-16

* Introduce mutation operators config 'light' and 'full'. Mutant will default to
Expand Down
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PATH
remote: .
specs:
mutant (0.11.22)
mutant (0.11.23)
diff-lcs (~> 1.3)
parser (~> 3.2.2)
parser (~> 3.2.2, >= 3.2.2.4)
regexp_parser (~> 2.6.1)
sorbet-runtime (~> 0.5.0)
unparser (~> 0.6.8)
unparser (~> 0.6.9)

GEM
remote: https://oss:[email protected]/
Expand Down Expand Up @@ -41,10 +41,10 @@ GEM
rspec-its (1.3.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.12.5)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rspec-support (3.12.1)
rubocop (1.56.4)
base64 (~> 0.1.1)
json (~> 2.3)
Expand All @@ -60,14 +60,14 @@ GEM
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
sorbet-runtime (0.5.10878)
sorbet-runtime (0.5.11064)
unicode-display_width (2.5.0)
unparser (0.6.8)
unparser (0.6.9)
diff-lcs (~> 1.3)
parser (>= 3.2.0)
parser (>= 3.2.2.4)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
mutant!
Expand All @@ -79,4 +79,4 @@ DEPENDENCIES
rubocop (~> 1.7)

BUNDLED WITH
2.4.1
2.4.10
8 changes: 6 additions & 2 deletions lib/mutant/mutator/node/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ def emit_argument_presence
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)
unless forward_type?(removed) || removed_block_arg?(new_arguments) || only_mlhs?(new_arguments)
emit_type(*new_arguments)
end
end
end

def forward_type?(removed)
n_forward_arg?(removed) || n_restarg?(removed) || n_kwrestarg?(removed)
end

def only_mlhs?(new_arguments)
new_arguments.one? && n_mlhs?(new_arguments.first)
end

def forward_arg?
children.last && n_forward_arg?(children.last)
children.any?(&method(:forward_type?))
end

def removed_block_arg?(new_arguments)
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/mutator/node/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def emit_argument_propagation

argument = Mutant::Util.one(arguments)

return if n_kwargs?(argument) || n_forwarded_args?(argument)
return if n_kwargs?(argument) || n_forwarded_args?(argument) || n_forwarded_restarg?(argument)

emit_propagation(argument)
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.22'
VERSION = '0.11.23'
end # Mutant
48 changes: 48 additions & 0 deletions meta/def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,40 @@
mutation 'def foo(...); super; end'
end

if RUBY_VERSION >= '3.2'
Mutant::Meta::Example.add :def do
source 'def foo(*); bar(*); end'

mutation 'def foo(*); raise; end'
mutation 'def foo(*); super; end'
mutation 'def foo(*); end'
mutation 'def foo(*); nil; end'
mutation 'def foo(*); bar; end'
end

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

mutation 'def foo(**); raise; end'
mutation 'def foo(**); super; end'
mutation 'def foo(**); end'
mutation 'def foo(**); nil; end'
mutation 'def foo(**); bar; end'
end
end

if RUBY_VERSION >= '3.1'
Mutant::Meta::Example.add :def do
source 'def foo(&); bar(&); end'

mutation 'def foo(&); raise; end'
mutation 'def foo(&); super; end'
mutation 'def foo(&); end'
mutation 'def foo(&); nil; end'
mutation 'def foo(&); bar; end'
end
end

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

Expand All @@ -213,3 +247,17 @@
mutation 'def foo(...); nil; end'
mutation 'def foo(...); end'
end

Mutant::Meta::Example.add :hash do
source 'def foo(**); { default: nil, ** }; end'

mutation 'def foo(**); end'
mutation 'def foo(**); nil; end'
mutation 'def foo(**); raise; end'
mutation 'def foo(**); super; end'
mutation 'def foo(**); { ** }; end'
mutation 'def foo(**); { default: nil }; end'
mutation 'def foo(**); { default__mutant__: nil, ** }; end'
mutation 'def foo(**); { nil => nil, ** }; end'
mutation 'def foo(**); {}; end'
end
4 changes: 2 additions & 2 deletions mutant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = '>= 2.7'

gem.add_runtime_dependency('diff-lcs', '~> 1.3')
gem.add_runtime_dependency('parser', '~> 3.2.2')
gem.add_runtime_dependency('parser', '~> 3.2.2', '>= 3.2.2.4')
gem.add_runtime_dependency('regexp_parser', '~> 2.6.1')
gem.add_runtime_dependency('sorbet-runtime', '~> 0.5.0')
gem.add_runtime_dependency('unparser', '~> 0.6.8')
gem.add_runtime_dependency('unparser', '~> 0.6.9')

gem.add_development_dependency('parallel', '~> 1.3')
gem.add_development_dependency('rspec', '~> 3.10')
Expand Down
2 changes: 2 additions & 0 deletions mutant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ matcher:
- Mutant::Mutator::Node::Arguments#emit_argument_presence
- Mutant::Mutator::Node::Arguments#removed_block_arg?
- Mutant::Mutator::Node::BlockPass#dispatch
# Mutation only alive for ruby < 3.2
- Mutant::Mutator::Node::Send#emit_argument_propagation
18 changes: 10 additions & 8 deletions test_app/Gemfile.minitest.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
PATH
remote: ..
specs:
mutant (0.11.22)
mutant (0.11.23)
diff-lcs (~> 1.3)
parser (~> 3.2.2)
parser (~> 3.2.2, >= 3.2.2.4)
regexp_parser (~> 2.6.1)
sorbet-runtime (~> 0.5.0)
unparser (~> 0.6.8)
mutant-minitest (0.11.22)
unparser (~> 0.6.9)
mutant-minitest (0.11.23)
minitest (~> 5.11)
mutant (= 0.11.22)
mutant (= 0.11.23)

GEM
remote: https://oss:[email protected]/
Expand All @@ -22,13 +22,15 @@ GEM
ast (2.4.2)
diff-lcs (1.5.0)
minitest (5.17.0)
parser (3.2.2.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
racc (1.7.1)
regexp_parser (2.6.1)
sorbet-runtime (0.5.10607)
unparser (0.6.8)
unparser (0.6.9)
diff-lcs (~> 1.3)
parser (>= 3.2.0)
parser (>= 3.2.2.4)

PLATFORMS
x86_64-linux
Expand Down
18 changes: 10 additions & 8 deletions test_app/Gemfile.rspec3.8.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
PATH
remote: ..
specs:
mutant (0.11.22)
mutant (0.11.23)
diff-lcs (~> 1.3)
parser (~> 3.2.2)
parser (~> 3.2.2, >= 3.2.2.4)
regexp_parser (~> 2.6.1)
sorbet-runtime (~> 0.5.0)
unparser (~> 0.6.8)
mutant-rspec (0.11.22)
mutant (= 0.11.22)
unparser (~> 0.6.9)
mutant-rspec (0.11.23)
mutant (= 0.11.23)
rspec-core (>= 3.8.0, < 4.0.0)

GEM
Expand All @@ -27,8 +27,10 @@ GEM
ice_nine (0.11.2)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
parser (3.2.2.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
racc (1.7.1)
regexp_parser (2.6.1)
rspec (3.8.0)
rspec-core (~> 3.8.0)
Expand All @@ -45,9 +47,9 @@ GEM
rspec-support (3.8.3)
sorbet-runtime (0.5.10607)
thread_safe (0.3.6)
unparser (0.6.8)
unparser (0.6.9)
diff-lcs (~> 1.3)
parser (>= 3.2.0)
parser (>= 3.2.2.4)

PLATFORMS
x86_64-linux
Expand Down

0 comments on commit 71b21fd

Please sign in to comment.