Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Mangles method call using a hash literal and a block #13

Open
agrimm opened this Issue · 1 comment

2 participants

@agrimm

Using a hash literal and a block causes heckle to erroneously get rid of the hash literal:

In the following example, the original code has a hash literal {} passed to each_with_object, but not in the mutated code.

This is running on Ruby 1.9.3 patchlevel 0 on Ubuntu.

I haven't evaluated this on Ruby 2.0 yet, because it can't be installed on 2.0. #12

require "test/unit"

class Target
  def target_method
    arr = []
    arr.each_with_object({}) do |item, result|
      result[item] = item
    end
  end
end

class TestTarget < Test::Unit::TestCase
  def test_method
    Target.new.target_method
  end
end


ruby1.9.1 -S heckle Target target_method --test replication.rb --verbose
{:force=>false, :nodes=>[:call, :cvasgn, :dasgn, :dasgn_curr, :false, :gasgn, :iasgn, :if, :iter, :lasgn, :lit, :str, :true, :until, :while], :debug=>true, :focus=>false, :timeout=>5, :test_pattern=>"replication.rb"}
**********************************************************************
***  Target#target_method loaded with 4 possible mutations
**********************************************************************

4 mutations remaining...
Replacing Target#target_method with:

--- original
+++ mutation
 def target_method
-  arr = []
+  arr = nil
   arr.each_with_object { |item, result| result[item] = item }
 end

Run options: --seed 43468

# Running tests:

E

Finished tests in 0.000949s, 1053.5332 tests/s, 0.0000 assertions/s.

  1) Error:
test_method(TestTarget):
NoMethodError: undefined method `each_with_object' for nil:NilClass
    (h1_target_method):3:in `target_method'
    /home/agrimm/code/sandbox/heckle_error_20130405/replication.rb:14:in `test_method'

1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
Tests failed -- this is good
3 mutations remaining...
Replacing Target#target_method with:

--- original
+++ mutation
 def target_method
   arr = []
-  arr.each_with_object { |item, result| result[item] = item }
+  arr.each_with_object { |_heckle_dummy, result| result[item] = item }
 end

Run options: --seed 8961

# Running tests:

E

Finished tests in 0.000674s, 1483.0942 tests/s, 0.0000 assertions/s.

  1) Error:
test_method(TestTarget):
ArgumentError: wrong number of arguments(0 for 1)
    (h3_target_method):3:in `each_with_object'
    (h3_target_method):3:in `target_method'
    /home/agrimm/code/sandbox/heckle_error_20130405/replication.rb:14:in `test_method'

1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
Tests failed -- this is good
2 mutations remaining...
@phiggins
Owner

Good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.