mutant 0.5.17 → 0.5.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +6 -0
  3. data/Rakefile +13 -0
  4. data/config/flay.yml +1 -1
  5. data/config/reek.yml +8 -1
  6. data/lib/mutant.rb +18 -3
  7. data/lib/mutant/cli.rb +6 -3
  8. data/lib/mutant/constants.rb +3 -0
  9. data/lib/mutant/expression.rb +110 -0
  10. data/lib/mutant/expression/method.rb +92 -0
  11. data/lib/mutant/expression/namespace.rb +90 -0
  12. data/lib/mutant/matcher/namespace.rb +3 -4
  13. data/lib/mutant/meta.rb +31 -0
  14. data/lib/mutant/meta/example.rb +152 -0
  15. data/lib/mutant/meta/example/dsl.rb +105 -0
  16. data/lib/mutant/mutator/node.rb +6 -6
  17. data/lib/mutant/mutator/node/arguments.rb +1 -1
  18. data/lib/mutant/mutator/node/begin.rb +1 -1
  19. data/lib/mutant/mutator/node/const.rb +1 -1
  20. data/lib/mutant/mutator/node/if.rb +6 -6
  21. data/lib/mutant/mutator/node/literal/array.rb +2 -2
  22. data/lib/mutant/mutator/node/literal/hash.rb +2 -2
  23. data/lib/mutant/mutator/node/literal/range.rb +3 -3
  24. data/lib/mutant/mutator/node/literal/regex.rb +2 -2
  25. data/lib/mutant/mutator/node/literal/symbol.rb +1 -1
  26. data/lib/mutant/mutator/node/op_asgn.rb +1 -3
  27. data/lib/mutant/mutator/node/or_asgn.rb +31 -0
  28. data/lib/mutant/mutator/node/send.rb +1 -1
  29. data/lib/mutant/mutator/node/send/attribute_assignment.rb +1 -1
  30. data/lib/mutant/reporter/cli/report/mutation.rb +11 -1
  31. data/lib/mutant/strategy.rb +1 -1
  32. data/lib/mutant/version.rb +1 -1
  33. data/meta/and.rb +12 -0
  34. data/meta/and_asgn.rb +12 -0
  35. data/meta/array.rb +30 -0
  36. data/meta/begin.rb +15 -0
  37. data/meta/binary.rb +12 -0
  38. data/meta/block.rb +55 -0
  39. data/meta/block_pass.rb +8 -0
  40. data/meta/blockarg.rb +10 -0
  41. data/meta/boolean.rb +15 -0
  42. data/meta/break.rb +11 -0
  43. data/meta/case.rb +303 -0
  44. data/meta/casgn.rb +9 -0
  45. data/meta/cbase.rb +8 -0
  46. data/meta/const.rb +9 -0
  47. data/meta/cvar.rb +7 -0
  48. data/meta/cvasgn.rb +10 -0
  49. data/meta/define.rb +118 -0
  50. data/meta/defined.rb +7 -0
  51. data/meta/dstr.rb +10 -0
  52. data/meta/dsym.rb +11 -0
  53. data/meta/ensure.rb +9 -0
  54. data/meta/fixnum.rb +19 -0
  55. data/meta/float.rb +38 -0
  56. data/meta/gvar.rb +7 -0
  57. data/meta/gvasgn.rb +10 -0
  58. data/meta/hash.rb +25 -0
  59. data/meta/if.rb +57 -0
  60. data/meta/ivasgn.rb +10 -0
  61. data/meta/kwbegin.rb +9 -0
  62. data/meta/lvar.rb +14 -0
  63. data/meta/lvasgn.rb +10 -0
  64. data/meta/masgn.rb +7 -0
  65. data/meta/match_current_line.rb +14 -0
  66. data/meta/next.rb +11 -0
  67. data/meta/nil.rb +5 -0
  68. data/meta/nthref.rb +14 -0
  69. data/meta/op_assgn.rb +15 -0
  70. data/meta/or_asgn.rb +22 -0
  71. data/meta/range.rb +41 -0
  72. data/meta/redo.rb +5 -0
  73. data/meta/regex.rb +20 -0
  74. data/meta/rescue.rb +38 -0
  75. data/meta/restarg.rb +11 -0
  76. data/meta/return.rb +15 -0
  77. data/meta/self.rb +7 -0
  78. data/meta/send.rb +240 -0
  79. data/meta/string.rb +7 -0
  80. data/meta/super.rb +26 -0
  81. data/meta/symbol.rb +8 -0
  82. data/meta/unless.rb +15 -0
  83. data/meta/while.rb +24 -0
  84. data/meta/yield.rb +10 -0
  85. data/mutant.gemspec +1 -0
  86. data/spec/integration/mutant/corpus_spec.rb +29 -25
  87. data/spec/spec_helper.rb +2 -0
  88. data/spec/support/mutation_verifier.rb +1 -0
  89. data/spec/unit/mutant/cli_new_spec.rb +6 -6
  90. data/spec/unit/mutant/expression/method_spec.rb +50 -0
  91. data/spec/unit/mutant/expression/namespace/flat_spec.rb +32 -0
  92. data/spec/unit/mutant/expression/namespace/recursive_spec.rb +37 -0
  93. data/spec/unit/mutant/matcher/namespace_spec.rb +2 -2
  94. data/spec/unit/mutant/mutation_spec.rb +1 -1
  95. data/spec/unit/mutant/mutator/node_spec.rb +14 -0
  96. metadata +123 -139
  97. data/lib/mutant/cli/classifier.rb +0 -139
  98. data/lib/mutant/cli/classifier/method.rb +0 -105
  99. data/lib/mutant/cli/classifier/namespace.rb +0 -49
  100. data/spec/unit/mutant/cli/classifier/method_spec.rb +0 -77
  101. data/spec/unit/mutant/cli/classifier/namespace/flat_spec.rb +0 -58
  102. data/spec/unit/mutant/cli/classifier/namespace/recursive_spec.rb +0 -58
  103. data/spec/unit/mutant/cli/classifier_spec.rb +0 -59
  104. data/spec/unit/mutant/mutator/node/and_asgn_spec.rb +0 -19
  105. data/spec/unit/mutant/mutator/node/begin_spec.rb +0 -32
  106. data/spec/unit/mutant/mutator/node/binary_spec.rb +0 -41
  107. data/spec/unit/mutant/mutator/node/block_pass_spec.rb +0 -15
  108. data/spec/unit/mutant/mutator/node/block_spec.rb +0 -83
  109. data/spec/unit/mutant/mutator/node/blockarg_spec.rb +0 -17
  110. data/spec/unit/mutant/mutator/node/case_spec.rb +0 -329
  111. data/spec/unit/mutant/mutator/node/cbase_spec.rb +0 -15
  112. data/spec/unit/mutant/mutator/node/conditional_loop_spec.rb +0 -58
  113. data/spec/unit/mutant/mutator/node/const_spec.rb +0 -16
  114. data/spec/unit/mutant/mutator/node/define_spec.rb +0 -171
  115. data/spec/unit/mutant/mutator/node/defined_spec.rb +0 -14
  116. data/spec/unit/mutant/mutator/node/dstr_spec.rb +0 -17
  117. data/spec/unit/mutant/mutator/node/dsym_spec.rb +0 -18
  118. data/spec/unit/mutant/mutator/node/ensure_spec.rb +0 -16
  119. data/spec/unit/mutant/mutator/node/if_spec.rb +0 -77
  120. data/spec/unit/mutant/mutator/node/kwbegin_spec.rb +0 -16
  121. data/spec/unit/mutant/mutator/node/literal/array_spec.rb +0 -47
  122. data/spec/unit/mutant/mutator/node/literal/boolean_spec.rb +0 -25
  123. data/spec/unit/mutant/mutator/node/literal/fixnum_spec.rb +0 -13
  124. data/spec/unit/mutant/mutator/node/literal/float_spec.rb +0 -53
  125. data/spec/unit/mutant/mutator/node/literal/hash_spec.rb +0 -33
  126. data/spec/unit/mutant/mutator/node/literal/nil_spec.rb +0 -10
  127. data/spec/unit/mutant/mutator/node/literal/range_spec.rb +0 -56
  128. data/spec/unit/mutant/mutator/node/literal/regex_spec.rb +0 -36
  129. data/spec/unit/mutant/mutator/node/literal/string_spec.rb +0 -15
  130. data/spec/unit/mutant/mutator/node/literal/symbol_spec.rb +0 -15
  131. data/spec/unit/mutant/mutator/node/loop_ctrl_spec.rb +0 -37
  132. data/spec/unit/mutant/mutator/node/masgn_spec.rb +0 -14
  133. data/spec/unit/mutant/mutator/node/match_current_line_spec.rb +0 -21
  134. data/spec/unit/mutant/mutator/node/named_value/access_spec.rb +0 -78
  135. data/spec/unit/mutant/mutator/node/named_value/constant_assignment_spec.rb +0 -16
  136. data/spec/unit/mutant/mutator/node/named_value/variable_assignment_spec.rb +0 -61
  137. data/spec/unit/mutant/mutator/node/nthref_spec.rb +0 -19
  138. data/spec/unit/mutant/mutator/node/op_assgn_spec.rb +0 -22
  139. data/spec/unit/mutant/mutator/node/or_asgn_spec.rb +0 -19
  140. data/spec/unit/mutant/mutator/node/redo_spec.rb +0 -10
  141. data/spec/unit/mutant/mutator/node/rescue_spec.rb +0 -63
  142. data/spec/unit/mutant/mutator/node/restarg_spec.rb +0 -18
  143. data/spec/unit/mutant/mutator/node/return_spec.rb +0 -31
  144. data/spec/unit/mutant/mutator/node/send_spec.rb +0 -382
  145. data/spec/unit/mutant/mutator/node/super_spec.rb +0 -46
  146. data/spec/unit/mutant/mutator/node/yield_spec.rb +0 -17
data/meta/casgn.rb ADDED
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source 'A = true'
5
+
6
+ mutation 'A__MUTANT__ = true'
7
+ mutation 'A = false'
8
+ mutation 'A = nil'
9
+ end
data/meta/cbase.rb ADDED
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source '::A'
5
+
6
+ mutation 'nil'
7
+ mutation 'A'
8
+ end
data/meta/const.rb ADDED
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source 'A::B::C'
5
+
6
+ mutation 'nil'
7
+ mutation 'B::C'
8
+ mutation 'C'
9
+ end
data/meta/cvar.rb ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source '@@a'
5
+
6
+ mutation 'nil'
7
+ end
data/meta/cvasgn.rb ADDED
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source '@@a = true'
5
+
6
+ mutation '@@a__mutant__ = true'
7
+ mutation '@@a = false'
8
+ mutation '@@a = nil'
9
+ mutation 'nil'
10
+ end
data/meta/define.rb ADDED
@@ -0,0 +1,118 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source 'def foo; end'
5
+
6
+ mutation 'def foo; raise; end'
7
+ end
8
+
9
+ Mutant::Meta::Example.add do
10
+ source "def foo\nfoo\nrescue\nend"
11
+
12
+ mutation 'def foo; raise; end'
13
+ mutation 'def foo; nil; rescue; end'
14
+ mutation 'def foo; end'
15
+ end
16
+
17
+ Mutant::Meta::Example.add do
18
+ source 'def foo; true; false; end'
19
+
20
+ # Mutation of each statement in block
21
+ mutation 'def foo; true; true; end'
22
+ mutation 'def foo; false; false; end'
23
+ mutation 'def foo; true; nil; end'
24
+ mutation 'def foo; nil; false; end'
25
+
26
+ # Remove statement in block
27
+ mutation 'def foo; true; end'
28
+ mutation 'def foo; false; end'
29
+
30
+ # Remove all statements
31
+ mutation 'def foo; end'
32
+
33
+ mutation 'def foo; raise; end'
34
+ end
35
+
36
+ Mutant::Meta::Example.add do
37
+ source 'def foo(a, b); end'
38
+
39
+ # Deletion of each argument
40
+ mutation 'def foo(a); end'
41
+ mutation 'def foo(b); end'
42
+
43
+ # Deletion of all arguments
44
+ mutation 'def foo; end'
45
+
46
+ # Rename each argument
47
+ mutation 'def foo(a__mutant__, b); end'
48
+ mutation 'def foo(a, b__mutant__); end'
49
+
50
+ # Mutation of body
51
+ mutation 'def foo(a, b); raise; end'
52
+ end
53
+
54
+ Mutant::Meta::Example.add do
55
+ source 'def foo(_unused); end'
56
+
57
+ mutation 'def foo(_unused); raise; end'
58
+ mutation 'def foo; end'
59
+ end
60
+
61
+ Mutant::Meta::Example.add do
62
+ source 'def foo(_unused = true); end'
63
+
64
+ mutation 'def foo(_unused = nil); end'
65
+ mutation 'def foo(_unused = false); end'
66
+ mutation 'def foo(_unused = true); raise; end'
67
+ mutation 'def foo(_unused); end'
68
+ mutation 'def foo; end'
69
+ end
70
+
71
+ Mutant::Meta::Example.add do
72
+ source 'def foo(a = true); end'
73
+
74
+ mutation 'def foo(a); end'
75
+ mutation 'def foo(); end'
76
+ mutation 'def foo(a = false); end'
77
+ mutation 'def foo(a = nil); end'
78
+ mutation 'def foo(a__mutant__ = true); end'
79
+ mutation 'def foo(a = true); raise; end'
80
+ end
81
+
82
+ Mutant::Meta::Example.add do
83
+ source 'def self.foo; true; false; end'
84
+
85
+ # Body presence mutation
86
+ mutation 'def self.foo; false; false; end'
87
+ mutation 'def self.foo; true; true; end'
88
+ mutation 'def self.foo; true; nil; end'
89
+ mutation 'def self.foo; nil; false; end'
90
+
91
+ # Body presence mutation
92
+ mutation 'def self.foo; true; end'
93
+ mutation 'def self.foo; false; end'
94
+
95
+ # Remove all statements
96
+ mutation 'def self.foo; end'
97
+
98
+ mutation 'def self.foo; raise; end'
99
+ end
100
+
101
+ Mutant::Meta::Example.add do
102
+
103
+ source 'def self.foo(a, b); end'
104
+
105
+ # Deletion of each argument
106
+ mutation 'def self.foo(a); end'
107
+ mutation 'def self.foo(b); end'
108
+
109
+ # Deletion of all arguments
110
+ mutation 'def self.foo; end'
111
+
112
+ # Rename each argument
113
+ mutation 'def self.foo(a__mutant__, b); end'
114
+ mutation 'def self.foo(a, b__mutant__); end'
115
+
116
+ # Mutation of body
117
+ mutation 'def self.foo(a, b); raise; end'
118
+ end
data/meta/defined.rb ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source 'defined?(foo)'
5
+
6
+ mutation 'defined?(nil)'
7
+ end
data/meta/dstr.rb ADDED
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source '"foo#{bar}baz"'
5
+
6
+ mutation 'nil'
7
+ mutation '"#{nil}#{bar}baz"'
8
+ mutation '"foo#{bar}#{nil}"'
9
+ mutation '"foo#{nil}baz"'
10
+ end
data/meta/dsym.rb ADDED
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+
5
+ source ':"foo#{bar}baz"'
6
+
7
+ mutation ':"#{nil}#{bar}baz"'
8
+ mutation ':"foo#{bar}#{nil}"'
9
+ mutation ':"foo#{nil}baz"'
10
+ mutation 'nil'
11
+ end
data/meta/ensure.rb ADDED
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source 'begin; rescue; ensure; true; end'
5
+
6
+ mutation 'begin; rescue; ensure; false; end'
7
+ mutation 'begin; rescue; ensure; nil; end'
8
+ mutation 'nil'
9
+ end
data/meta/fixnum.rb ADDED
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source '10'
5
+
6
+ # generic
7
+ mutation 'nil'
8
+
9
+ # edge cases
10
+ mutation '0'
11
+ mutation '1'
12
+
13
+ # negative
14
+ mutation '-10'
15
+
16
+ # scalar boundary
17
+ mutation '9'
18
+ mutation '11'
19
+ end
data/meta/float.rb ADDED
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source '10.0'
5
+
6
+ # generic
7
+ mutation 'nil'
8
+
9
+ # edge cases
10
+ mutation '0.0'
11
+ mutation '1.0'
12
+ mutation '(0.0 / 0.0)'
13
+ mutation '(1.0 / 0.0)'
14
+ mutation '(-1.0 / 0.0)'
15
+
16
+ # negative
17
+ mutation '-10.0'
18
+ end
19
+
20
+ Mutant::Meta::Example.add do
21
+ source '0.0'
22
+
23
+ mutation 'nil'
24
+ mutation '1.0'
25
+ mutation '(0.0 / 0.0)'
26
+ mutation '(1.0 / 0.0)'
27
+ mutation '(-1.0 / 0.0)'
28
+ end
29
+
30
+ Mutant::Meta::Example.add do
31
+ source '-0.0'
32
+
33
+ mutation 'nil'
34
+ mutation '1.0'
35
+ mutation '(0.0 / 0.0)'
36
+ mutation '(1.0 / 0.0)'
37
+ mutation '(-1.0 / 0.0)'
38
+ end
data/meta/gvar.rb ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source '$a'
5
+
6
+ mutation 'nil'
7
+ end
data/meta/gvasgn.rb ADDED
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source '$a = true'
5
+
6
+ mutation '$a__mutant__ = true'
7
+ mutation '$a = false'
8
+ mutation '$a = nil'
9
+ mutation 'nil'
10
+ end
data/meta/hash.rb ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source '{true => true, false => false}'
5
+
6
+ # Literal replaced with nil
7
+ mutation 'nil'
8
+
9
+ # Mutation of each key and value in hash
10
+ mutation '{ false => true , false => false }'
11
+ mutation '{ nil => true , false => false }'
12
+ mutation '{ true => false , false => false }'
13
+ mutation '{ true => nil , false => false }'
14
+ mutation '{ true => true , true => false }'
15
+ mutation '{ true => true , nil => false }'
16
+ mutation '{ true => true , false => true }'
17
+ mutation '{ true => true , false => nil }'
18
+
19
+ # Remove each key once
20
+ mutation '{ true => true }'
21
+ mutation '{ false => false }'
22
+
23
+ # Empty hash
24
+ mutation '{}'
25
+ end
data/meta/if.rb ADDED
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source 'if :condition; true; else false; end'
5
+
6
+ # mutation of condition
7
+ mutation 'if :condition__mutant__; true; else false; end'
8
+ mutation 'if !:condition; true; else false; end'
9
+ mutation 'if nil; true; else false; end'
10
+ mutation 'if true; true; else false; end'
11
+ mutation 'if false; true; else false; end'
12
+
13
+ # Deleted else branch
14
+ mutation 'if :condition; true end'
15
+
16
+ # Deleted if branch resuting in unless rendering
17
+ mutation 'unless :condition; false; end'
18
+
19
+ # Deleted if branch with promoting else branch to if branch
20
+ mutation 'if :condition; false end'
21
+
22
+ # mutation of if body
23
+ mutation 'if :condition; false; else false; end'
24
+ mutation 'if :condition; nil; else false; end'
25
+
26
+ # mutation of else body
27
+ mutation 'if :condition; true; else true; end'
28
+ mutation 'if :condition; true; else nil; end'
29
+
30
+ mutation 'nil'
31
+ end
32
+
33
+ Mutant::Meta::Example.add do
34
+ source 'if condition; true; end'
35
+
36
+ mutation 'if !condition; true; end'
37
+ mutation 'if condition; false; end'
38
+ mutation 'if condition; nil; end'
39
+ mutation 'if true; true; end'
40
+ mutation 'if false; true; end'
41
+ mutation 'if nil; true; end'
42
+ mutation 'nil'
43
+ end
44
+
45
+ Mutant::Meta::Example.add do
46
+ source 'unless :condition; true; end'
47
+
48
+ mutation 'unless !:condition; true; end'
49
+ mutation 'unless :condition__mutant__; true; end'
50
+ mutation 'unless nil; true; end'
51
+ mutation 'unless :condition; false; end'
52
+ mutation 'unless :condition; nil; end'
53
+ mutation 'unless true; true; end'
54
+ mutation 'unless false; true; end'
55
+ mutation 'if :condition; true; end'
56
+ mutation 'nil'
57
+ end
data/meta/ivasgn.rb ADDED
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source '@a = true'
5
+
6
+ mutation '@a__mutant__ = true'
7
+ mutation '@a = false'
8
+ mutation '@a = nil'
9
+ mutation 'nil'
10
+ end
data/meta/kwbegin.rb ADDED
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source 'begin; true; end'
5
+
6
+ mutation 'begin; false; end'
7
+ mutation 'begin; nil; end'
8
+ mutation 'nil'
9
+ end
data/meta/lvar.rb ADDED
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source 'a = nil; a'
5
+
6
+ mutation 'a = nil; nil'
7
+ mutation 'a = nil'
8
+ # TODO: fix invalid AST
9
+ # These ASTs are not valid and should NOT be emitted
10
+ # Mutations of lvarasgn need to be special cased to avoid this.
11
+ mutation s(:begin, s(:lvasgn, :a__mutant__, s(:nil)), s(:lvar, :a))
12
+ mutation s(:begin, s(:nil), s(:lvar, :a))
13
+ mutation s(:lvar, :a)
14
+ end
data/meta/lvasgn.rb ADDED
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source 'a = true'
5
+
6
+ mutation 'a__mutant__ = true'
7
+ mutation 'a = false'
8
+ mutation 'a = nil'
9
+ mutation 'nil'
10
+ end
data/meta/masgn.rb ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ Mutant::Meta::Example.add do
4
+ source 'a, b = c, d'
5
+
6
+ mutation 'nil'
7
+ end