mutant 0.2.8 → 0.2.9

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.
data/Changelog.md CHANGED
@@ -1,3 +1,10 @@
1
+ # v0.2.9 2013-01-02
2
+
3
+ * [feature] Mutate instance and global variable assignments
4
+ * [feature] Mutate super calls
5
+
6
+ [Compare v0.2.8..v0.2.9](https://github.com/mbj/mutant/compare/v0.2.8...v0.2.9)
7
+
1
8
  # v0.2.8 2012-12-29
2
9
 
3
10
  * [feature] Do not mutate argument or local variable names beginning with an underscore
data/TODO CHANGED
@@ -13,6 +13,9 @@ Mutations:
13
13
  * Add mutations for dynamic regexp symbol and string literals
14
14
  * Mutate "def foo; bar; end" to "def foo; self; end"?
15
15
  * Emit negative and positive mutations
16
+ * Mutate Block catch "def foo(&block)" and block pass "foo(&block)"
17
+ * Mutate super arguments just like send arguments
18
+ * Add timeout to terminate infinite loops
16
19
 
17
20
  Example of a negative mutation:
18
21
  Mutations on local variables and arguments prefixed with an underscore would be emitted as
data/lib/mutant.rb CHANGED
@@ -68,6 +68,7 @@ require 'mutant/mutator/util'
68
68
  require 'mutant/mutator/util/array'
69
69
  require 'mutant/mutator/util/symbol'
70
70
  require 'mutant/mutator/node'
71
+ require 'mutant/mutator/node/noop'
71
72
  require 'mutant/mutator/node/literal'
72
73
  require 'mutant/mutator/node/literal/boolean'
73
74
  require 'mutant/mutator/node/literal/range'
@@ -81,8 +82,10 @@ require 'mutant/mutator/node/literal/hash'
81
82
  require 'mutant/mutator/node/literal/regex'
82
83
  require 'mutant/mutator/node/literal/nil'
83
84
  require 'mutant/mutator/node/block'
84
- require 'mutant/mutator/node/noop'
85
+ require 'mutant/mutator/node/while'
86
+ require 'mutant/mutator/node/super'
85
87
  require 'mutant/mutator/node/send'
88
+ require 'mutant/mutator/node/assignment'
86
89
  require 'mutant/mutator/node/define'
87
90
  require 'mutant/mutator/node/formal_arguments_19'
88
91
  require 'mutant/mutator/node/formal_arguments_19/default_mutations'
@@ -93,7 +96,6 @@ require 'mutant/mutator/node/pattern_arguments'
93
96
  require 'mutant/mutator/node/pattern_variable'
94
97
  require 'mutant/mutator/node/default_arguments'
95
98
  require 'mutant/mutator/node/return'
96
- require 'mutant/mutator/node/local_variable_assignment'
97
99
  require 'mutant/mutator/node/iter_19'
98
100
  require 'mutant/mutator/node/if_statement'
99
101
  require 'mutant/mutator/node/receiver_case'
@@ -0,0 +1,48 @@
1
+ module Mutant
2
+ class Mutator
3
+ class Node
4
+ class Assignment < self
5
+
6
+ private
7
+
8
+ class Variable < self
9
+
10
+ # Emit mutants
11
+ #
12
+ # @return [undefined]
13
+ #
14
+ # @api private
15
+ #
16
+ def dispatch
17
+ emit_attribute_mutations(:name) do |mutation|
18
+ mutation.name = "#{self.class::PREFIX}#{mutation.name}".to_sym
19
+ end
20
+ emit_attribute_mutations(:value)
21
+ end
22
+
23
+ class Local < self
24
+ PREFIX = ''.freeze
25
+ handle(Rubinius::AST::LocalVariableAssignment)
26
+ end
27
+
28
+ class Instance < self
29
+ PREFIX = '@'.freeze
30
+ handle(Rubinius::AST::InstanceVariableAssignment)
31
+ end
32
+
33
+ class Class < self
34
+ PREFIX = '@@'.freeze
35
+ handle(Rubinius::AST::ClassVariableAssignment)
36
+ end
37
+
38
+ class Global < self
39
+ PREFIX = '$'.freeze
40
+ handle(Rubinius::AST::GlobalVariableAssignment)
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -7,13 +7,12 @@ module Mutant
7
7
  # Literal references to self do not need to be mutated?
8
8
  handle(Rubinius::AST::Self)
9
9
 
10
-
11
10
  # Currently unhandled node classes. Feel free to contribute your mutator!
12
- handle(Rubinius::AST::While)
13
11
  handle(Rubinius::AST::ElementAssignment)
14
12
  handle(Rubinius::AST::AttributeAssignment)
15
13
  handle(Rubinius::AST::Not)
16
14
  handle(Rubinius::AST::And)
15
+ handle(Rubinius::AST::Or)
17
16
  handle(Rubinius::AST::Defined)
18
17
  handle(Rubinius::AST::Super)
19
18
  handle(Rubinius::AST::Next)
@@ -22,25 +21,24 @@ module Mutant
22
21
  handle(Rubinius::AST::ZSuper)
23
22
  handle(Rubinius::AST::MultipleAssignment)
24
23
  handle(Rubinius::AST::ScopedConstant)
25
- handle(Rubinius::AST::LocalVariableAssignment)
26
24
  handle(Rubinius::AST::LocalVariableAccess)
27
- handle(Rubinius::AST::InstanceVariableAssignment)
28
25
  handle(Rubinius::AST::InstanceVariableAccess)
29
- handle(Rubinius::AST::GlobalVariableAssignment)
30
26
  handle(Rubinius::AST::GlobalVariableAccess)
27
+ handle(Rubinius::AST::ClassVariableAccess)
31
28
  handle(Rubinius::AST::ToplevelConstant)
32
29
  handle(Rubinius::AST::Ensure)
33
30
  handle(Rubinius::AST::Rescue)
34
31
  handle(Rubinius::AST::DynamicString)
35
32
  handle(Rubinius::AST::DynamicSymbol)
36
- handle(Rubinius::AST::File)
37
33
  handle(Rubinius::AST::DynamicRegex)
34
+ handle(Rubinius::AST::File)
38
35
  handle(Rubinius::AST::OpAssignOr19)
39
36
  handle(Rubinius::AST::BlockPass19)
40
37
  handle(Rubinius::AST::OpAssign1)
41
- handle(Rubinius::AST::Or)
42
38
  handle(Rubinius::AST::ConstantAccess)
43
39
  handle(Rubinius::AST::Yield)
40
+ handle(Rubinius::AST::Begin)
41
+ handle(Rubinius::AST::Rescue)
44
42
 
45
43
  private
46
44
 
@@ -0,0 +1,53 @@
1
+ module Mutant
2
+ class Mutator
3
+ class Node
4
+
5
+ class ZSuper < self
6
+
7
+ handle(Rubinius::AST::ZSuper)
8
+
9
+ # Emit mutations
10
+ #
11
+ # @return [undefined]
12
+ #
13
+ # @api private
14
+ #
15
+ def dispatch
16
+ emit_node(Rubinius::AST::Super, new(Rubinius::AST::ActualArguments))
17
+ end
18
+
19
+ end
20
+
21
+ class Super < self
22
+ handle(Rubinius::AST::Super)
23
+
24
+ private
25
+
26
+ # Emit mutations
27
+ #
28
+ # @return [undefined]
29
+ #
30
+ # @api private
31
+ #
32
+ def dispatch
33
+ emit_node(Rubinius::AST::ZSuper)
34
+ emit_without_block
35
+ emit_attribute_mutations(:block) if node.block
36
+ emit_attribute_mutations(:arguments)
37
+ end
38
+
39
+ # Emit without block mutation
40
+ #
41
+ # @return [undefined]
42
+ #
43
+ # @api private
44
+ #
45
+ def emit_without_block
46
+ dup = dup_node
47
+ dup.block = nil
48
+ emit(dup)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ module Mutant
2
+ class Mutator
3
+ class Node
4
+ class While < self
5
+
6
+ handle(Rubinius::AST::While)
7
+
8
+ private
9
+
10
+ # Emit mutations
11
+ #
12
+ # @return [undefined]
13
+ #
14
+ # @api private
15
+ #
16
+ def dispatch
17
+ emit_attribute_mutations(:condition)
18
+ emit_attribute_mutations(:body)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
data/mutant.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'mutant'
5
- gem.version = '0.2.8'
5
+ gem.version = '0.2.9'
6
6
  gem.authors = [ 'Markus Schirp' ]
7
7
  gem.email = [ 'mbj@seonic.net' ]
8
8
  gem.description = 'Mutation testing for ruby under rubinius'
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.extra_rdoc_files = %w[TODO LICENSE]
16
16
  gem.executables = [ 'mutant' ]
17
17
 
18
- gem.add_runtime_dependency('to_source', '~> 0.2.5')
18
+ gem.add_runtime_dependency('to_source', '~> 0.2.7')
19
19
  gem.add_runtime_dependency('ice_nine', '~> 0.6.0')
20
20
  gem.add_runtime_dependency('descendants_tracker', '~> 0.0.1')
21
21
  gem.add_runtime_dependency('backports', '~> 2.6')
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mutant::Mutator::Node::Assignment, 'mutations' do
4
+
5
+ before do
6
+ Mutant::Random.stub(:hex_string => :random)
7
+ end
8
+
9
+ context 'global variable' do
10
+ let(:source) { '$a = true' }
11
+
12
+ let(:mutations) do
13
+ mutations = []
14
+
15
+ mutations << '$srandom = true'
16
+ mutations << '$a = false'
17
+ mutations << '$a = nil'
18
+ end
19
+
20
+ it_should_behave_like 'a mutator'
21
+ end
22
+
23
+ context 'class variable' do
24
+ let(:source) { '@@a = true' }
25
+
26
+ let(:mutations) do
27
+ mutations = []
28
+
29
+ mutations << '@@srandom = true'
30
+ mutations << '@@a = false'
31
+ mutations << '@@a = nil'
32
+ end
33
+
34
+ it_should_behave_like 'a mutator'
35
+ end
36
+
37
+ context 'instance variable' do
38
+ let(:source) { '@a = true' }
39
+
40
+ let(:mutations) do
41
+ mutations = []
42
+
43
+ mutations << '@srandom = true'
44
+ mutations << '@a = false'
45
+ mutations << '@a = nil'
46
+ end
47
+
48
+ it_should_behave_like 'a mutator'
49
+ end
50
+
51
+ context 'local variable' do
52
+ let(:source) { 'a = true' }
53
+
54
+ let(:mutations) do
55
+ mutations = []
56
+
57
+ mutations << 'srandom = true'
58
+ mutations << 'a = false'
59
+ mutations << 'a = nil'
60
+ end
61
+
62
+ it_should_behave_like 'a mutator'
63
+ end
64
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mutant::Mutator, 'super' do
4
+
5
+ context 'with no arguments' do
6
+ let(:source) { 'super' }
7
+
8
+ let(:mutations) do
9
+ mutations = []
10
+ mutations << 'super()'
11
+ end
12
+
13
+ it_should_behave_like 'a mutator'
14
+ end
15
+
16
+ context 'with explicit empty arguments' do
17
+ let(:source) { 'super()' }
18
+
19
+ let(:mutations) do
20
+ mutations = []
21
+ mutations << 'super'
22
+ end
23
+
24
+ it_should_behave_like 'a mutator'
25
+ end
26
+
27
+ context 'with explicit empty arguments and block' do
28
+ let(:source) { 'super() { foo; bar }' }
29
+
30
+ let(:mutations) do
31
+ mutations = []
32
+ mutations << 'super() { foo }'
33
+ mutations << 'super() { bar }'
34
+ mutations << 'super() { }'
35
+ mutations << 'super()'
36
+ mutations << 'super'
37
+ end
38
+
39
+ it_should_behave_like 'a mutator'
40
+ end
41
+
42
+ context 'super with arguments' do
43
+ let(:source) { 'super(foo, bar)' }
44
+
45
+ let(:mutations) do
46
+ mutations = []
47
+ mutations << 'super'
48
+ mutations << 'super()'
49
+ mutations << 'super(foo)'
50
+ mutations << 'super(bar)'
51
+ end
52
+
53
+ it_should_behave_like 'a mutator'
54
+ end
55
+
56
+ context 'super with arguments and block' do
57
+ let(:source) { 'super(foo, bar) { foo; bar }' }
58
+
59
+ let(:mutations) do
60
+ mutations = []
61
+ mutations << 'super(foo, bar) { foo; }'
62
+ mutations << 'super(foo, bar) { bar; }'
63
+ mutations << 'super(foo, bar) { nil }'
64
+ mutations << 'super(foo, bar)'
65
+ mutations << 'super'
66
+ mutations << 'super(foo) { foo; bar }'
67
+ mutations << 'super(bar) { foo; bar }'
68
+ mutations << 'super() { foo; bar }'
69
+ end
70
+
71
+ it_should_behave_like 'a mutator'
72
+ end
73
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mutant::Mutator::Node::While do
4
+
5
+ context 'with more than one statement' do
6
+ let(:source) { "while true; foo; bar; end" }
7
+
8
+ let(:mutations) do
9
+ mutations = []
10
+ mutations << 'while true; bar; end'
11
+ mutations << 'while true; foo; end'
12
+ mutations << 'while true; nil; end'
13
+ mutations << 'while false; foo; bar; end'
14
+ mutations << 'while nil; foo; bar; end'
15
+ end
16
+
17
+ it_should_behave_like 'a mutator'
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mutant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-30 00:00:00.000000000 Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: to_source
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.2.5
21
+ version: 0.2.7
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.2.5
29
+ version: 0.2.7
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: ice_nine
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -212,6 +212,7 @@ files:
212
212
  - lib/mutant/mutator/node.rb
213
213
  - lib/mutant/mutator/node/actual_arguments.rb
214
214
  - lib/mutant/mutator/node/arguments.rb
215
+ - lib/mutant/mutator/node/assignment.rb
215
216
  - lib/mutant/mutator/node/block.rb
216
217
  - lib/mutant/mutator/node/default_arguments.rb
217
218
  - lib/mutant/mutator/node/define.rb
@@ -234,13 +235,14 @@ files:
234
235
  - lib/mutant/mutator/node/literal/regex.rb
235
236
  - lib/mutant/mutator/node/literal/string.rb
236
237
  - lib/mutant/mutator/node/literal/symbol.rb
237
- - lib/mutant/mutator/node/local_variable_assignment.rb
238
238
  - lib/mutant/mutator/node/noop.rb
239
239
  - lib/mutant/mutator/node/pattern_arguments.rb
240
240
  - lib/mutant/mutator/node/pattern_variable.rb
241
241
  - lib/mutant/mutator/node/receiver_case.rb
242
242
  - lib/mutant/mutator/node/return.rb
243
243
  - lib/mutant/mutator/node/send.rb
244
+ - lib/mutant/mutator/node/super.rb
245
+ - lib/mutant/mutator/node/while.rb
244
246
  - lib/mutant/mutator/registry.rb
245
247
  - lib/mutant/mutator/util.rb
246
248
  - lib/mutant/mutator/util/array.rb
@@ -296,6 +298,7 @@ files:
296
298
  - spec/unit/mutant/mutator/each_spec.rb
297
299
  - spec/unit/mutant/mutator/emit_new_spec.rb
298
300
  - spec/unit/mutant/mutator/emit_spec.rb
301
+ - spec/unit/mutant/mutator/node/assignment/mutation_spec.rb
299
302
  - spec/unit/mutant/mutator/node/block/mutation_spec.rb
300
303
  - spec/unit/mutant/mutator/node/define/mutation_spec.rb
301
304
  - spec/unit/mutant/mutator/node/if_statement/mutation_spec.rb
@@ -313,6 +316,8 @@ files:
313
316
  - spec/unit/mutant/mutator/node/receiver_case/mutation_spec.rb
314
317
  - spec/unit/mutant/mutator/node/return/mutation_spec.rb
315
318
  - spec/unit/mutant/mutator/node/send/mutation_spec.rb
319
+ - spec/unit/mutant/mutator/node/super/mutation_spec.rb
320
+ - spec/unit/mutant/mutator/node/while/mutation_spec.rb
316
321
  - spec/unit/mutant/mutator/self_spec.rb
317
322
  - spec/unit/mutant/strategy/rspec/example_lookup/spec_file_spec.rb
318
323
  - spec/unit/mutant/subject/class_methods/new_spec.rb
@@ -407,6 +412,7 @@ test_files:
407
412
  - spec/unit/mutant/mutator/each_spec.rb
408
413
  - spec/unit/mutant/mutator/emit_new_spec.rb
409
414
  - spec/unit/mutant/mutator/emit_spec.rb
415
+ - spec/unit/mutant/mutator/node/assignment/mutation_spec.rb
410
416
  - spec/unit/mutant/mutator/node/block/mutation_spec.rb
411
417
  - spec/unit/mutant/mutator/node/define/mutation_spec.rb
412
418
  - spec/unit/mutant/mutator/node/if_statement/mutation_spec.rb
@@ -424,6 +430,8 @@ test_files:
424
430
  - spec/unit/mutant/mutator/node/receiver_case/mutation_spec.rb
425
431
  - spec/unit/mutant/mutator/node/return/mutation_spec.rb
426
432
  - spec/unit/mutant/mutator/node/send/mutation_spec.rb
433
+ - spec/unit/mutant/mutator/node/super/mutation_spec.rb
434
+ - spec/unit/mutant/mutator/node/while/mutation_spec.rb
427
435
  - spec/unit/mutant/mutator/self_spec.rb
428
436
  - spec/unit/mutant/strategy/rspec/example_lookup/spec_file_spec.rb
429
437
  - spec/unit/mutant/subject/class_methods/new_spec.rb
@@ -1,25 +0,0 @@
1
- module Mutant
2
- class Mutator
3
- class Node
4
- class LocalVariableAssignment < self
5
-
6
- handle(Rubinius::AST::LocalVariableAssignment)
7
-
8
- private
9
-
10
- # Emit mutants
11
- #
12
- # @return [undefined]
13
- #
14
- # @api private
15
- #
16
- def dispatch
17
- emit_attribute_mutations(:name)
18
- emit_attribute_mutations(:value)
19
- end
20
-
21
- end
22
- end
23
- end
24
- end
25
-