mutant 0.2.7 → 0.2.8

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.
Files changed (35) hide show
  1. data/Changelog.md +9 -1
  2. data/Gemfile.devtools +5 -12
  3. data/LICENSE +20 -0
  4. data/README.md +25 -24
  5. data/TODO +10 -2
  6. data/config/flay.yml +2 -2
  7. data/config/flog.yml +1 -1
  8. data/config/site.reek +4 -2
  9. data/lib/mutant.rb +18 -9
  10. data/lib/mutant/context/scope.rb +3 -3
  11. data/lib/mutant/differ.rb +13 -1
  12. data/lib/mutant/killer.rb +1 -0
  13. data/lib/mutant/matcher/scope_methods.rb +16 -11
  14. data/lib/mutant/mutator.rb +10 -0
  15. data/lib/mutant/mutator/node.rb +5 -18
  16. data/lib/mutant/mutator/node/actual_arguments.rb +25 -0
  17. data/lib/mutant/mutator/node/arguments.rb +0 -155
  18. data/lib/mutant/mutator/node/default_arguments.rb +24 -0
  19. data/lib/mutant/mutator/node/formal_arguments_19.rb +40 -0
  20. data/lib/mutant/mutator/node/formal_arguments_19/default_mutations.rb +32 -0
  21. data/lib/mutant/mutator/node/formal_arguments_19/pattern_argument_expansion.rb +35 -0
  22. data/lib/mutant/mutator/node/formal_arguments_19/require_defaults.rb +37 -0
  23. data/lib/mutant/mutator/node/literal.rb +14 -0
  24. data/lib/mutant/mutator/node/literal/hash.rb +1 -7
  25. data/lib/mutant/mutator/node/pattern_arguments.rb +41 -0
  26. data/lib/mutant/mutator/node/pattern_variable.rb +23 -0
  27. data/lib/mutant/mutator/node/send.rb +76 -6
  28. data/lib/mutant/mutator/util.rb +0 -71
  29. data/lib/mutant/mutator/util/array.rb +70 -0
  30. data/lib/mutant/mutator/util/symbol.rb +39 -0
  31. data/mutant.gemspec +2 -2
  32. data/spec/shared/mutator_behavior.rb +3 -2
  33. data/spec/unit/mutant/mutator/node/define/mutation_spec.rb +12 -0
  34. data/spec/unit/mutant/mutator/node/send/mutation_spec.rb +24 -17
  35. metadata +15 -3
@@ -38,77 +38,6 @@ module Mutant
38
38
  def new?(generated)
39
39
  input != generated
40
40
  end
41
-
42
- # Mutators that mutates symbol inputs
43
- class Symbol < self
44
-
45
- handle(::Symbol)
46
-
47
- private
48
-
49
- # Emit mutations
50
- #
51
- # @return [undefined]
52
- #
53
- # @api private
54
- #
55
- def dispatch
56
- emit_new { :"s#{Random.hex_string}" }
57
- end
58
-
59
- end
60
-
61
- # Mutators that mutates an array of inputs
62
- class Array < self
63
-
64
- handle(::Array)
65
-
66
- private
67
-
68
- # Emit mutations
69
- #
70
- # @return [undefined]
71
- #
72
- # @api private
73
- #
74
- def dispatch
75
- emit_element_presence
76
- emit_element_mutations
77
- emit([])
78
- end
79
-
80
- # Emit element mutations
81
- #
82
- # @return [undefined]
83
- #
84
- # @api private
85
- #
86
- def emit_element_mutations
87
- input.each_with_index do |element, index|
88
- dup = dup_input
89
-
90
- Mutator.each(element).each do |mutation|
91
- dup[index]=mutation
92
- emit(dup)
93
- end
94
- end
95
- end
96
-
97
- # Emit element presence mutations
98
- #
99
- # @return [undefined]
100
- #
101
- # @api private
102
- #
103
- def emit_element_presence
104
- input.each_index do |index|
105
- dup = dup_input
106
- dup.delete_at(index)
107
- emit(dup)
108
- end
109
- end
110
-
111
- end
112
41
  end
113
42
  end
114
43
  end
@@ -0,0 +1,70 @@
1
+ module Mutant
2
+ class Mutator
3
+ class Util
4
+
5
+ # Mutators that mutates an array of inputs
6
+ class Array < self
7
+
8
+ handle(::Array)
9
+
10
+ class Presence < Util
11
+
12
+ private
13
+
14
+ # Emit element presence mutations
15
+ #
16
+ # @return [undefined]
17
+ #
18
+ # @api private
19
+ #
20
+ def dispatch
21
+ input.each_index do |index|
22
+ dup = dup_input
23
+ dup.delete_at(index)
24
+ emit(dup)
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ class Element < Util
31
+
32
+ private
33
+
34
+ # Emit mutations
35
+ #
36
+ # @return [undefined]
37
+ #
38
+ # @api private
39
+ #
40
+ def dispatch
41
+ input.each_with_index do |element, index|
42
+ dup = dup_input
43
+
44
+ Mutator.each(element).each do |mutation|
45
+ dup[index]=mutation
46
+ emit(dup)
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ private
54
+
55
+ # Emit mutations
56
+ #
57
+ # @return [undefined]
58
+ #
59
+ # @api private
60
+ #
61
+ def dispatch
62
+ run(Element)
63
+ run(Presence)
64
+ emit([])
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,39 @@
1
+ module Mutant
2
+ class Mutator
3
+ class Util
4
+
5
+ # Mutators that mutates symbol inputs
6
+ class Symbol < self
7
+
8
+ handle(::Symbol)
9
+
10
+ private
11
+
12
+ # Emit mutations
13
+ #
14
+ # @return [undefined]
15
+ #
16
+ # @api private
17
+ #
18
+ def dispatch
19
+ emit_new { :"s#{Random.hex_string}" } unless ignore?
20
+ end
21
+
22
+ # Test if symbol is ignored
23
+ #
24
+ # @return [true]
25
+ # if symbol begins with an underscore
26
+ #
27
+ # @return [false]
28
+ # otherwise
29
+ #
30
+ # @pai private
31
+ #
32
+ def ignore?
33
+ input.to_s[0] == '_'
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'mutant'
5
- gem.version = '0.2.7'
5
+ gem.version = '0.2.8'
6
6
  gem.authors = [ 'Markus Schirp' ]
7
7
  gem.email = [ 'mbj@seonic.net' ]
8
8
  gem.description = 'Mutation testing for ruby under rubinius'
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.require_paths = [ 'lib' ]
13
13
  gem.files = `git ls-files`.split("\n")
14
14
  gem.test_files = `git ls-files -- spec`.split("\n")
15
- gem.extra_rdoc_files = %w[TODO]
15
+ gem.extra_rdoc_files = %w[TODO LICENSE]
16
16
  gem.executables = [ 'mutant' ]
17
17
 
18
18
  gem.add_runtime_dependency('to_source', '~> 0.2.5')
@@ -45,13 +45,14 @@ shared_examples_for 'a mutator' do
45
45
  end
46
46
 
47
47
  it 'generates the expected mutations' do
48
- generated = self.subject.map { |mutation| ToSource.to_source(mutation) }.to_set
48
+ generated = self.subject.map { |mutation| ToSource.to_source(mutation) }.to_set
49
49
 
50
50
  missing = (expected_mutations - generated).to_a
51
51
  unexpected = (generated - expected_mutations).to_a
52
52
 
53
53
  unless generated == expected_mutations
54
- fail "Missing mutations:\n%s\nUnexpected mutations:\n%s" % [missing.join("\n----\n"), unexpected.join("\n----\n")]
54
+ message ="Missing mutations:\n%s\nUnexpected mutations:\n%s" % [missing.join("\n----\n"), unexpected.join("\n----\n")]
55
+ fail message
55
56
  end
56
57
  end
57
58
  end
@@ -51,6 +51,18 @@ describe Mutant::Mutator, 'define' do
51
51
  it_should_behave_like 'a mutator'
52
52
  end
53
53
 
54
+ context 'with arguments beginning with an underscore' do
55
+ let(:source) { 'def foo(_unused); end' }
56
+
57
+ let(:mutations) do
58
+ mutations = []
59
+ mutations << 'def foo(_unused); Object.new; end'
60
+ mutations << 'def foo; end'
61
+ end
62
+
63
+ it_should_behave_like 'a mutator'
64
+ end
65
+
54
66
  context 'default argument' do
55
67
  let(:source) { 'def foo(a = "literal"); end' }
56
68
 
@@ -2,23 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Mutant::Mutator, 'send' do
4
4
  context 'send without arguments' do
5
- # This could not be reproduced in a test case but happens in the mutant source code?
6
- context 'block_given?' do
7
- context 'implicit self' do
8
- let(:source) { 'block_given?' }
9
-
10
- it_should_behave_like 'a noop mutator'
11
- end
12
-
13
- context 'explicit self' do
14
- let(:source) { 'self.block_given?' }
15
-
16
- it_should_behave_like 'a noop mutator'
17
- end
18
- end
19
-
20
5
  context 'with self as receiver' do
21
-
22
6
  context 'implicit' do
23
7
  let(:source) { 'foo' }
24
8
 
@@ -39,10 +23,32 @@ describe Mutant::Mutator, 'send' do
39
23
  end
40
24
 
41
25
  context 'to some object' do
42
- let(:source) { '1.foo' }
26
+ let(:source) { 'foo.bar' }
27
+
28
+ let(:mutations) do
29
+ mutations = []
30
+ mutations << 'foo'
31
+ end
32
+
33
+ it_should_behave_like 'a mutator'
34
+ end
35
+
36
+ context 'to self.class' do
37
+ let(:source) { 'self.class' }
43
38
 
44
39
  it_should_behave_like 'a noop mutator'
45
40
  end
41
+
42
+ context 'to self.class.foo' do
43
+ let(:source) { 'self.class.foo' }
44
+
45
+ let(:mutations) do
46
+ mutations = []
47
+ mutations << 'self.class'
48
+ end
49
+
50
+ it_should_behave_like 'a mutator'
51
+ end
46
52
  end
47
53
 
48
54
  context 'send with arguments' do
@@ -53,6 +59,7 @@ describe Mutant::Mutator, 'send' do
53
59
  let(:mutations) do
54
60
  mutations = []
55
61
  mutations << 'foo()'
62
+ mutations << 'nil'
56
63
  mutations << 'foo(Object.new)'
57
64
  end
58
65
 
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.7
4
+ version: 0.2.8
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-21 00:00:00.000000000 Z
12
+ date: 2012-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: to_source
@@ -163,6 +163,7 @@ executables:
163
163
  extensions: []
164
164
  extra_rdoc_files:
165
165
  - TODO
166
+ - LICENSE
166
167
  files:
167
168
  - .gitignore
168
169
  - .rspec
@@ -171,6 +172,7 @@ files:
171
172
  - Gemfile
172
173
  - Gemfile.devtools
173
174
  - Guardfile
175
+ - LICENSE
174
176
  - README.md
175
177
  - Rakefile
176
178
  - TODO
@@ -208,9 +210,15 @@ files:
208
210
  - lib/mutant/mutation/filter/whitelist.rb
209
211
  - lib/mutant/mutator.rb
210
212
  - lib/mutant/mutator/node.rb
213
+ - lib/mutant/mutator/node/actual_arguments.rb
211
214
  - lib/mutant/mutator/node/arguments.rb
212
215
  - lib/mutant/mutator/node/block.rb
216
+ - lib/mutant/mutator/node/default_arguments.rb
213
217
  - lib/mutant/mutator/node/define.rb
218
+ - lib/mutant/mutator/node/formal_arguments_19.rb
219
+ - lib/mutant/mutator/node/formal_arguments_19/default_mutations.rb
220
+ - lib/mutant/mutator/node/formal_arguments_19/pattern_argument_expansion.rb
221
+ - lib/mutant/mutator/node/formal_arguments_19/require_defaults.rb
214
222
  - lib/mutant/mutator/node/if_statement.rb
215
223
  - lib/mutant/mutator/node/iter_19.rb
216
224
  - lib/mutant/mutator/node/literal.rb
@@ -228,11 +236,15 @@ files:
228
236
  - lib/mutant/mutator/node/literal/symbol.rb
229
237
  - lib/mutant/mutator/node/local_variable_assignment.rb
230
238
  - lib/mutant/mutator/node/noop.rb
239
+ - lib/mutant/mutator/node/pattern_arguments.rb
240
+ - lib/mutant/mutator/node/pattern_variable.rb
231
241
  - lib/mutant/mutator/node/receiver_case.rb
232
242
  - lib/mutant/mutator/node/return.rb
233
243
  - lib/mutant/mutator/node/send.rb
234
244
  - lib/mutant/mutator/registry.rb
235
245
  - lib/mutant/mutator/util.rb
246
+ - lib/mutant/mutator/util/array.rb
247
+ - lib/mutant/mutator/util/symbol.rb
236
248
  - lib/mutant/random.rb
237
249
  - lib/mutant/reporter.rb
238
250
  - lib/mutant/reporter/cli.rb
@@ -351,7 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
351
363
  version: '0'
352
364
  requirements: []
353
365
  rubyforge_project:
354
- rubygems_version: 1.8.24
366
+ rubygems_version: 1.8.23
355
367
  signing_key:
356
368
  specification_version: 3
357
369
  summary: Mutation testing for ruby under rubinius