mutant 0.3.0.beta2 → 0.3.0.beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.travis.yml +1 -0
 - data/lib/mutant/mutator.rb +15 -6
 - data/lib/mutant/mutator/node.rb +2 -2
 - data/lib/mutant/mutator/node/argument.rb +1 -1
 - data/lib/mutant/mutator/node/assignment.rb +1 -1
 - data/lib/mutant/mutator/node/begin.rb +16 -2
 - data/lib/mutant/mutator/util.rb +4 -3
 - data/mutant.gemspec +1 -1
 - data/spec/unit/mutant/mutator/emit_new_spec.rb +4 -3
 - data/spec/unit/mutant/mutator/emit_spec.rb +4 -3
 - data/spec/unit/mutant/mutator/node/send/mutation_spec.rb +12 -0
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 99a1dc445a2a8e2fc4485a5fc03b65366c9f00ab
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9bb4ca3b1255de13857a9c142b1d933dec0049ab
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 89768cb785f9bb73daf81720e688ae824a60b967722577c3048944f46c32b57360aa9e96ac3a48517bc889a8ee59c397248c7b90b0a401c543483e0f8f660f1a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: fc7fb6c821a962efa4542513c930adb6b89b96d4811946f62080f0ac79dc1e0361d5d07b5c569a1d6b5fa25e1fa91f9d5ff32833a0fa7fb3bb00c2fe0e43a7c7
         
     | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/lib/mutant/mutator.rb
    CHANGED
    
    | 
         @@ -12,9 +12,9 @@ module Mutant 
     | 
|
| 
       12 
12 
     | 
    
         
             
                #
         
     | 
| 
       13 
13 
     | 
    
         
             
                # @api private
         
     | 
| 
       14 
14 
     | 
    
         
             
                #
         
     | 
| 
       15 
     | 
    
         
            -
                def self.each(node, &block)
         
     | 
| 
       16 
     | 
    
         
            -
                  return to_enum(__method__, node) unless block_given?
         
     | 
| 
       17 
     | 
    
         
            -
                  Registry.lookup(node).new(node, block)
         
     | 
| 
      
 15 
     | 
    
         
            +
                def self.each(node, parent=nil, &block)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  return to_enum(__method__, node, parent) unless block_given?
         
     | 
| 
      
 17 
     | 
    
         
            +
                  Registry.lookup(node).new(node, parent, block)
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                  self
         
     | 
| 
       20 
20 
     | 
    
         
             
                end
         
     | 
| 
         @@ -52,19 +52,28 @@ module Mutant 
     | 
|
| 
       52 
52 
     | 
    
         
             
                #
         
     | 
| 
       53 
53 
     | 
    
         
             
                attr_reader :input
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
      
 55 
     | 
    
         
            +
                # Return input
         
     | 
| 
      
 56 
     | 
    
         
            +
                #
         
     | 
| 
      
 57 
     | 
    
         
            +
                # @return [Object]
         
     | 
| 
      
 58 
     | 
    
         
            +
                #
         
     | 
| 
      
 59 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 60 
     | 
    
         
            +
                #
         
     | 
| 
      
 61 
     | 
    
         
            +
                attr_reader :parent
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
       55 
63 
     | 
    
         
             
              private
         
     | 
| 
       56 
64 
     | 
    
         | 
| 
       57 
65 
     | 
    
         
             
                # Initialize object
         
     | 
| 
       58 
66 
     | 
    
         
             
                #
         
     | 
| 
       59 
67 
     | 
    
         
             
                # @param [Object] input
         
     | 
| 
      
 68 
     | 
    
         
            +
                # @param [Object] parent
         
     | 
| 
       60 
69 
     | 
    
         
             
                # @param [#call(node)] block
         
     | 
| 
       61 
70 
     | 
    
         
             
                #
         
     | 
| 
       62 
71 
     | 
    
         
             
                # @return [undefined]
         
     | 
| 
       63 
72 
     | 
    
         
             
                #
         
     | 
| 
       64 
73 
     | 
    
         
             
                # @api private
         
     | 
| 
       65 
74 
     | 
    
         
             
                #
         
     | 
| 
       66 
     | 
    
         
            -
                def initialize(input, block)
         
     | 
| 
       67 
     | 
    
         
            -
                  @input, @block =  
     | 
| 
      
 75 
     | 
    
         
            +
                def initialize(input, parent, block)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  @input, @parent, @block = input, parent, block
         
     | 
| 
       68 
77 
     | 
    
         
             
                  @seen = Set.new
         
     | 
| 
       69 
78 
     | 
    
         
             
                  guard(input)
         
     | 
| 
       70 
79 
     | 
    
         
             
                  dispatch
         
     | 
| 
         @@ -173,7 +182,7 @@ module Mutant 
     | 
|
| 
       173 
182 
     | 
    
         
             
                # @api private
         
     | 
| 
       174 
183 
     | 
    
         
             
                #
         
     | 
| 
       175 
184 
     | 
    
         
             
                def run(mutator)
         
     | 
| 
       176 
     | 
    
         
            -
                  mutator.new(input, method(:emit))
         
     | 
| 
      
 185 
     | 
    
         
            +
                  mutator.new(input, self, method(:emit))
         
     | 
| 
       177 
186 
     | 
    
         
             
                end
         
     | 
| 
       178 
187 
     | 
    
         | 
| 
       179 
188 
     | 
    
         
             
                # Shortcut to create a new unfrozen duplicate of input
         
     | 
    
        data/lib/mutant/mutator/node.rb
    CHANGED
    
    | 
         @@ -99,7 +99,7 @@ module Mutant 
     | 
|
| 
       99 
99 
     | 
    
         
             
                  # @api private
         
     | 
| 
       100 
100 
     | 
    
         
             
                  #
         
     | 
| 
       101 
101 
     | 
    
         
             
                  def emit_children_mutations
         
     | 
| 
       102 
     | 
    
         
            -
                    Mutator::Util::Array.each(children) do |children|
         
     | 
| 
      
 102 
     | 
    
         
            +
                    Mutator::Util::Array.each(children, self) do |children|
         
     | 
| 
       103 
103 
     | 
    
         
             
                      emit_self(*children)
         
     | 
| 
       104 
104 
     | 
    
         
             
                    end
         
     | 
| 
       105 
105 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -125,7 +125,7 @@ module Mutant 
     | 
|
| 
       125 
125 
     | 
    
         
             
                  def mutate_child(index, mutator = Mutator)
         
     | 
| 
       126 
126 
     | 
    
         
             
                    children = node.children
         
     | 
| 
       127 
127 
     | 
    
         
             
                    child = children[index]
         
     | 
| 
       128 
     | 
    
         
            -
                    mutator.each(child) do |mutation|
         
     | 
| 
      
 128 
     | 
    
         
            +
                    mutator.each(child, self) do |mutation|
         
     | 
| 
       129 
129 
     | 
    
         
             
                      emit_child_update(index, mutation)
         
     | 
| 
       130 
130 
     | 
    
         
             
                    end
         
     | 
| 
       131 
131 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -16,7 +16,7 @@ module Mutant 
     | 
|
| 
       16 
16 
     | 
    
         
             
                    # @api private
         
     | 
| 
       17 
17 
     | 
    
         
             
                    #
         
     | 
| 
       18 
18 
     | 
    
         
             
                    def dispatch
         
     | 
| 
       19 
     | 
    
         
            -
                      Util::Array.each(children) do |children|
         
     | 
| 
      
 19 
     | 
    
         
            +
                      Util::Array.each(children, self) do |children|
         
     | 
| 
       20 
20 
     | 
    
         
             
                        if children.length > 1
         
     | 
| 
       21 
21 
     | 
    
         
             
                          emit_self(*children)
         
     | 
| 
       22 
22 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -24,7 +24,21 @@ module Mutant 
     | 
|
| 
       24 
24 
     | 
    
         
             
                      children.each do |child|
         
     | 
| 
       25 
25 
     | 
    
         
             
                        emit(child)
         
     | 
| 
       26 
26 
     | 
    
         
             
                      end
         
     | 
| 
       27 
     | 
    
         
            -
                      emit(nil)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      emit(nil) unless parent_send?
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                    # Test if parent input is a send
         
     | 
| 
      
 31 
     | 
    
         
            +
                    #
         
     | 
| 
      
 32 
     | 
    
         
            +
                    # @return [true]
         
     | 
| 
      
 33 
     | 
    
         
            +
                    #   if parent input is a send node
         
     | 
| 
      
 34 
     | 
    
         
            +
                    #
         
     | 
| 
      
 35 
     | 
    
         
            +
                    # @return [false]
         
     | 
| 
      
 36 
     | 
    
         
            +
                    #   otherwise
         
     | 
| 
      
 37 
     | 
    
         
            +
                    #
         
     | 
| 
      
 38 
     | 
    
         
            +
                    # @api private
         
     | 
| 
      
 39 
     | 
    
         
            +
                    #
         
     | 
| 
      
 40 
     | 
    
         
            +
                    def parent_send?
         
     | 
| 
      
 41 
     | 
    
         
            +
                      parent && parent.input.type == :send
         
     | 
| 
       28 
42 
     | 
    
         
             
                    end
         
     | 
| 
       29 
43 
     | 
    
         | 
| 
       30 
44 
     | 
    
         
             
                  end # Block
         
     | 
    
        data/lib/mutant/mutator/util.rb
    CHANGED
    
    | 
         @@ -6,6 +6,7 @@ module Mutant 
     | 
|
| 
       6 
6 
     | 
    
         
             
                  # Run ulitity mutator
         
     | 
| 
       7 
7 
     | 
    
         
             
                  #
         
     | 
| 
       8 
8 
     | 
    
         
             
                  # @param [Object] object
         
     | 
| 
      
 9 
     | 
    
         
            +
                  # @param [Object] parent
         
     | 
| 
       9 
10 
     | 
    
         
             
                  #
         
     | 
| 
       10 
11 
     | 
    
         
             
                  # @return [Enumerator<Object>]
         
     | 
| 
       11 
12 
     | 
    
         
             
                  #   if no block given
         
     | 
| 
         @@ -15,10 +16,10 @@ module Mutant 
     | 
|
| 
       15 
16 
     | 
    
         
             
                  #
         
     | 
| 
       16 
17 
     | 
    
         
             
                  # @api private
         
     | 
| 
       17 
18 
     | 
    
         
             
                  #
         
     | 
| 
       18 
     | 
    
         
            -
                  def self.each(object, &block)
         
     | 
| 
       19 
     | 
    
         
            -
                    return to_enum(__method__, object) unless block_given?
         
     | 
| 
      
 19 
     | 
    
         
            +
                  def self.each(object, parent, &block)
         
     | 
| 
      
 20 
     | 
    
         
            +
                    return to_enum(__method__, object, parent) unless block_given?
         
     | 
| 
       20 
21 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                    new(object, block)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    new(object, parent, block)
         
     | 
| 
       22 
23 
     | 
    
         | 
| 
       23 
24 
     | 
    
         
             
                    self
         
     | 
| 
       24 
25 
     | 
    
         
             
                  end
         
     | 
    
        data/mutant.gemspec
    CHANGED
    
    
| 
         @@ -15,9 +15,10 @@ describe Mutant::Mutator, '#emit_new' do 
     | 
|
| 
       15 
15 
     | 
    
         
             
                end
         
     | 
| 
       16 
16 
     | 
    
         
             
              end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
              let(:object) { class_under_test.new(input, block) }
         
     | 
| 
       19 
     | 
    
         
            -
              let(:block)  { Block.new 
     | 
| 
       20 
     | 
    
         
            -
              let(:input)  { :input 
     | 
| 
      
 18 
     | 
    
         
            +
              let(:object) { class_under_test.new(input, parent, block) }
         
     | 
| 
      
 19 
     | 
    
         
            +
              let(:block)  { Block.new                                  }
         
     | 
| 
      
 20 
     | 
    
         
            +
              let(:input)  { :input                                     }
         
     | 
| 
      
 21 
     | 
    
         
            +
              let(:parent) { :parent                                    }
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
23 
     | 
    
         
             
              let(:class_under_test) do
         
     | 
| 
       23 
24 
     | 
    
         
             
                Class.new(described_class) do
         
     | 
| 
         @@ -15,9 +15,10 @@ describe Mutant::Mutator, '#emit' do 
     | 
|
| 
       15 
15 
     | 
    
         
             
                end
         
     | 
| 
       16 
16 
     | 
    
         
             
              end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
              let(:object) { class_under_test.new(input, block) }
         
     | 
| 
       19 
     | 
    
         
            -
              let(:block)  { Block.new 
     | 
| 
       20 
     | 
    
         
            -
              let(:input)  { : 
     | 
| 
      
 18 
     | 
    
         
            +
              let(:object) { class_under_test.new(input, parent, block) }
         
     | 
| 
      
 19 
     | 
    
         
            +
              let(:block)  { Block.new                                  }
         
     | 
| 
      
 20 
     | 
    
         
            +
              let(:input)  { :input                                     }
         
     | 
| 
      
 21 
     | 
    
         
            +
              let(:parent) { :parent                                    }
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
23 
     | 
    
         
             
              let(:class_under_test) do
         
     | 
| 
       23 
24 
     | 
    
         
             
                Class.new(described_class) do
         
     | 
| 
         @@ -168,6 +168,18 @@ describe Mutant::Mutator, 'send' do 
     | 
|
| 
       168 
168 
     | 
    
         
             
                end
         
     | 
| 
       169 
169 
     | 
    
         | 
| 
       170 
170 
     | 
    
         
             
                context 'binary operator methods' do
         
     | 
| 
      
 171 
     | 
    
         
            +
                  context 'nested' do
         
     | 
| 
      
 172 
     | 
    
         
            +
                    let(:source) { '(left - right) / foo' }
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
                    let(:mutations) do
         
     | 
| 
      
 175 
     | 
    
         
            +
                      mutations = []
         
     | 
| 
      
 176 
     | 
    
         
            +
                      mutations << 'foo'
         
     | 
| 
      
 177 
     | 
    
         
            +
                      mutations << 'left - right'
         
     | 
| 
      
 178 
     | 
    
         
            +
                    end
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                    it_should_behave_like 'a mutator'
         
     | 
| 
      
 181 
     | 
    
         
            +
                  end
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
       171 
183 
     | 
    
         
             
                  Mutant::BINARY_METHOD_OPERATORS.each do |operator|
         
     | 
| 
       172 
184 
     | 
    
         
             
                    context 'on literal scalar arguments' do
         
     | 
| 
       173 
185 
     | 
    
         
             
                      let(:source) { "true #{operator} false" }
         
     |