mutant 0.8.24 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +3 -3
  3. data/Changelog.md +14 -654
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +59 -64
  6. data/LICENSE +271 -20
  7. data/README.md +73 -140
  8. data/Rakefile +0 -21
  9. data/bin/mutant +7 -2
  10. data/config/reek.yml +2 -1
  11. data/config/rubocop.yml +5 -9
  12. data/docs/incremental.md +76 -0
  13. data/docs/known-problems.md +0 -14
  14. data/docs/mutant-minitest.md +1 -1
  15. data/docs/mutant-rspec.md +2 -24
  16. data/lib/mutant.rb +45 -53
  17. data/lib/mutant/ast/nodes.rb +0 -2
  18. data/lib/mutant/ast/types.rb +1 -117
  19. data/lib/mutant/base.rb +192 -0
  20. data/lib/mutant/bootstrap.rb +145 -0
  21. data/lib/mutant/cli.rb +68 -54
  22. data/lib/mutant/config.rb +119 -6
  23. data/lib/mutant/env.rb +94 -8
  24. data/lib/mutant/expression.rb +6 -1
  25. data/lib/mutant/expression/parser.rb +9 -31
  26. data/lib/mutant/integration.rb +64 -36
  27. data/lib/mutant/isolation.rb +16 -1
  28. data/lib/mutant/isolation/fork.rb +105 -40
  29. data/lib/mutant/license.rb +34 -0
  30. data/lib/mutant/license/subscription.rb +47 -0
  31. data/lib/mutant/license/subscription/commercial.rb +57 -0
  32. data/lib/mutant/license/subscription/opensource.rb +77 -0
  33. data/lib/mutant/loader.rb +27 -4
  34. data/lib/mutant/matcher.rb +48 -1
  35. data/lib/mutant/matcher/chain.rb +1 -1
  36. data/lib/mutant/matcher/config.rb +0 -2
  37. data/lib/mutant/matcher/filter.rb +1 -1
  38. data/lib/mutant/matcher/method.rb +11 -7
  39. data/lib/mutant/matcher/methods.rb +1 -1
  40. data/lib/mutant/matcher/namespace.rb +1 -1
  41. data/lib/mutant/matcher/null.rb +1 -1
  42. data/lib/mutant/matcher/scope.rb +1 -1
  43. data/lib/mutant/meta/example/dsl.rb +0 -8
  44. data/lib/mutant/mutation.rb +1 -2
  45. data/lib/mutant/mutator/node.rb +2 -9
  46. data/lib/mutant/mutator/node/arguments.rb +1 -1
  47. data/lib/mutant/mutator/node/class.rb +0 -8
  48. data/lib/mutant/mutator/node/define.rb +0 -12
  49. data/lib/mutant/mutator/node/generic.rb +30 -44
  50. data/lib/mutant/mutator/node/index.rb +4 -4
  51. data/lib/mutant/mutator/node/literal/regex.rb +0 -39
  52. data/lib/mutant/mutator/node/send.rb +13 -12
  53. data/lib/mutant/parallel.rb +61 -40
  54. data/lib/mutant/parallel/driver.rb +59 -0
  55. data/lib/mutant/parallel/source.rb +6 -2
  56. data/lib/mutant/parallel/worker.rb +63 -45
  57. data/lib/mutant/range.rb +15 -0
  58. data/lib/mutant/reporter/cli.rb +5 -11
  59. data/lib/mutant/reporter/cli/format.rb +3 -46
  60. data/lib/mutant/reporter/cli/printer/config.rb +5 -6
  61. data/lib/mutant/reporter/cli/printer/env.rb +40 -0
  62. data/lib/mutant/reporter/cli/printer/env_progress.rb +13 -17
  63. data/lib/mutant/reporter/cli/printer/isolation_result.rb +17 -3
  64. data/lib/mutant/reporter/cli/printer/mutation_result.rb +2 -3
  65. data/lib/mutant/reporter/cli/printer/status_progressive.rb +19 -10
  66. data/lib/mutant/repository.rb +0 -65
  67. data/lib/mutant/repository/diff.rb +104 -0
  68. data/lib/mutant/repository/diff/ranges.rb +52 -0
  69. data/lib/mutant/result.rb +16 -7
  70. data/lib/mutant/runner.rb +38 -47
  71. data/lib/mutant/runner/sink.rb +1 -1
  72. data/lib/mutant/selector/null.rb +19 -0
  73. data/lib/mutant/subject.rb +3 -1
  74. data/lib/mutant/subject/method/instance.rb +3 -1
  75. data/lib/mutant/transform.rb +511 -0
  76. data/lib/mutant/variable.rb +282 -0
  77. data/lib/mutant/version.rb +1 -1
  78. data/lib/mutant/warnings.rb +113 -0
  79. data/meta/case.rb +1 -0
  80. data/meta/class.rb +0 -9
  81. data/meta/def.rb +1 -26
  82. data/meta/regexp.rb +10 -20
  83. data/meta/send.rb +14 -46
  84. data/mutant-minitest.gemspec +1 -1
  85. data/mutant-rspec.gemspec +2 -2
  86. data/mutant.gemspec +15 -16
  87. data/mutant.yml +6 -0
  88. data/spec/integration/mutant/isolation/fork_spec.rb +22 -5
  89. data/spec/integration/mutant/minitest_spec.rb +3 -2
  90. data/spec/integration/mutant/rspec_spec.rb +4 -3
  91. data/spec/integrations.yml +16 -13
  92. data/spec/shared/base_behavior.rb +45 -0
  93. data/spec/shared/framework_integration_behavior.rb +43 -14
  94. data/spec/spec_helper.rb +21 -17
  95. data/spec/support/corpus.rb +56 -95
  96. data/spec/support/shared_context.rb +37 -14
  97. data/spec/support/xspec.rb +7 -3
  98. data/spec/unit/mutant/bootstrap_spec.rb +216 -0
  99. data/spec/unit/mutant/cli_spec.rb +173 -117
  100. data/spec/unit/mutant/config_spec.rb +126 -0
  101. data/spec/unit/mutant/either_spec.rb +247 -0
  102. data/spec/unit/mutant/env_spec.rb +162 -40
  103. data/spec/unit/mutant/expression/method_spec.rb +16 -0
  104. data/spec/unit/mutant/expression/parser_spec.rb +29 -33
  105. data/spec/unit/mutant/expression_spec.rb +5 -7
  106. data/spec/unit/mutant/integration_spec.rb +100 -9
  107. data/spec/unit/mutant/isolation/fork_spec.rb +125 -67
  108. data/spec/unit/mutant/isolation/result_spec.rb +33 -1
  109. data/spec/unit/mutant/license_spec.rb +257 -0
  110. data/spec/unit/mutant/loader_spec.rb +50 -11
  111. data/spec/unit/mutant/matcher/compiler_spec.rb +0 -78
  112. data/spec/unit/mutant/matcher/method/instance_spec.rb +55 -11
  113. data/spec/unit/mutant/matcher/method/singleton_spec.rb +12 -2
  114. data/spec/unit/mutant/matcher_spec.rb +102 -0
  115. data/spec/unit/mutant/maybe_spec.rb +60 -0
  116. data/spec/unit/mutant/meta/example/dsl_spec.rb +1 -17
  117. data/spec/unit/mutant/mutation_spec.rb +13 -6
  118. data/spec/unit/mutant/parallel/driver_spec.rb +112 -14
  119. data/spec/unit/mutant/parallel/source/array_spec.rb +25 -17
  120. data/spec/unit/mutant/parallel/worker_spec.rb +182 -44
  121. data/spec/unit/mutant/parallel_spec.rb +105 -8
  122. data/spec/unit/mutant/range_spec.rb +141 -0
  123. data/spec/unit/mutant/reporter/cli/printer/config_spec.rb +7 -21
  124. data/spec/unit/mutant/reporter/cli/printer/env_progress_spec.rb +15 -6
  125. data/spec/unit/mutant/reporter/cli/printer/env_result_spec.rb +10 -2
  126. data/spec/unit/mutant/reporter/cli/printer/isolation_result_spec.rb +12 -4
  127. data/spec/unit/mutant/reporter/cli/printer/mutation_result_spec.rb +31 -2
  128. data/spec/unit/mutant/reporter/cli/printer/status_progressive_spec.rb +4 -4
  129. data/spec/unit/mutant/reporter/cli/printer/subject_result_spec.rb +5 -0
  130. data/spec/unit/mutant/reporter/cli_spec.rb +46 -123
  131. data/spec/unit/mutant/repository/diff/ranges_spec.rb +180 -0
  132. data/spec/unit/mutant/repository/diff_spec.rb +84 -71
  133. data/spec/unit/mutant/require_highjack_spec.rb +1 -1
  134. data/spec/unit/mutant/result/env_spec.rb +39 -9
  135. data/spec/unit/mutant/result/test_spec.rb +14 -0
  136. data/spec/unit/mutant/runner_spec.rb +88 -41
  137. data/spec/unit/mutant/selector/expression_spec.rb +11 -10
  138. data/spec/unit/mutant/selector/null_spec.rb +17 -0
  139. data/spec/unit/mutant/subject/method/instance_spec.rb +44 -5
  140. data/spec/unit/mutant/subject/method/singleton_spec.rb +9 -2
  141. data/spec/unit/mutant/subject_spec.rb +9 -1
  142. data/spec/unit/mutant/transform/array_spec.rb +92 -0
  143. data/spec/unit/mutant/transform/bool_spec.rb +63 -0
  144. data/spec/unit/mutant/transform/error_spec.rb +132 -0
  145. data/spec/unit/mutant/transform/exception_spec.rb +44 -0
  146. data/spec/unit/mutant/transform/hash_spec.rb +236 -0
  147. data/spec/unit/mutant/transform/index_spec.rb +92 -0
  148. data/spec/unit/mutant/transform/named_spec.rb +49 -0
  149. data/spec/unit/mutant/transform/primitive_spec.rb +56 -0
  150. data/spec/unit/mutant/transform/sequence_spec.rb +98 -0
  151. data/spec/unit/mutant/variable_spec.rb +618 -0
  152. data/spec/unit/mutant/warnings_spec.rb +89 -0
  153. data/spec/unit/mutant/world_spec.rb +63 -0
  154. data/test_app/Gemfile.minitest +0 -2
  155. metadata +79 -113
  156. data/.gitattributes +0 -1
  157. data/.ruby-gemset +0 -1
  158. data/config/triage.yml +0 -2
  159. data/lib/mutant/actor.rb +0 -57
  160. data/lib/mutant/actor/env.rb +0 -31
  161. data/lib/mutant/actor/mailbox.rb +0 -34
  162. data/lib/mutant/actor/receiver.rb +0 -42
  163. data/lib/mutant/actor/sender.rb +0 -26
  164. data/lib/mutant/ast/meta/restarg.rb +0 -19
  165. data/lib/mutant/ast/regexp.rb +0 -42
  166. data/lib/mutant/ast/regexp/transformer.rb +0 -187
  167. data/lib/mutant/ast/regexp/transformer/direct.rb +0 -123
  168. data/lib/mutant/ast/regexp/transformer/named_group.rb +0 -59
  169. data/lib/mutant/ast/regexp/transformer/options_group.rb +0 -83
  170. data/lib/mutant/ast/regexp/transformer/quantifier.rb +0 -114
  171. data/lib/mutant/ast/regexp/transformer/recursive.rb +0 -58
  172. data/lib/mutant/ast/regexp/transformer/root.rb +0 -31
  173. data/lib/mutant/ast/regexp/transformer/text.rb +0 -60
  174. data/lib/mutant/env/bootstrap.rb +0 -160
  175. data/lib/mutant/matcher/compiler.rb +0 -60
  176. data/lib/mutant/mutator/node/regexp.rb +0 -35
  177. data/lib/mutant/mutator/node/regexp/alternation_meta.rb +0 -23
  178. data/lib/mutant/mutator/node/regexp/capture_group.rb +0 -28
  179. data/lib/mutant/mutator/node/regexp/character_type.rb +0 -32
  180. data/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb +0 -23
  181. data/lib/mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor.rb +0 -23
  182. data/lib/mutant/mutator/node/regexp/greedy_zero_or_more.rb +0 -27
  183. data/lib/mutant/parallel/master.rb +0 -181
  184. data/lib/mutant/reporter/cli/printer/status.rb +0 -53
  185. data/lib/mutant/reporter/cli/tput.rb +0 -46
  186. data/lib/mutant/warning_filter.rb +0 -61
  187. data/meta/regexp/character_types.rb +0 -23
  188. data/meta/regexp/regexp_alternation_meta.rb +0 -13
  189. data/meta/regexp/regexp_bol_anchor.rb +0 -10
  190. data/meta/regexp/regexp_bos_anchor.rb +0 -18
  191. data/meta/regexp/regexp_capture_group.rb +0 -19
  192. data/meta/regexp/regexp_eol_anchor.rb +0 -10
  193. data/meta/regexp/regexp_eos_anchor.rb +0 -8
  194. data/meta/regexp/regexp_eos_ob_eol_anchor.rb +0 -10
  195. data/meta/regexp/regexp_greedy_zero_or_more.rb +0 -12
  196. data/meta/regexp/regexp_root_expression.rb +0 -10
  197. data/meta/restarg.rb +0 -10
  198. data/spec/support/fake_actor.rb +0 -111
  199. data/spec/support/warning.rb +0 -66
  200. data/spec/unit/mutant/actor/binding_spec.rb +0 -34
  201. data/spec/unit/mutant/actor/env_spec.rb +0 -31
  202. data/spec/unit/mutant/actor/mailbox_spec.rb +0 -28
  203. data/spec/unit/mutant/actor/message_spec.rb +0 -25
  204. data/spec/unit/mutant/actor/receiver_spec.rb +0 -58
  205. data/spec/unit/mutant/actor/sender_spec.rb +0 -24
  206. data/spec/unit/mutant/ast/regexp/parse_spec.rb +0 -19
  207. data/spec/unit/mutant/ast/regexp/transformer/lookup_table/table_spec.rb +0 -21
  208. data/spec/unit/mutant/ast/regexp/transformer/lookup_table_spec.rb +0 -35
  209. data/spec/unit/mutant/ast/regexp/transformer_spec.rb +0 -21
  210. data/spec/unit/mutant/ast/regexp_spec.rb +0 -704
  211. data/spec/unit/mutant/env/bootstrap_spec.rb +0 -188
  212. data/spec/unit/mutant/matcher/compiler/subject_prefix_spec.rb +0 -26
  213. data/spec/unit/mutant/parallel/master_spec.rb +0 -338
  214. data/spec/unit/mutant/reporter/cli/printer/status_spec.rb +0 -121
  215. data/spec/unit/mutant/reporter/cli/tput_spec.rb +0 -50
  216. data/spec/unit/mutant/warning_filter_spec.rb +0 -106
  217. data/spec/unit/mutant_spec.rb +0 -17
  218. data/test_app/Gemfile.rspec3.7 +0 -7
@@ -0,0 +1,282 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutant
4
+ # Lightweight shared variables
5
+ #
6
+ # ignore :reek:TooManyMethods
7
+ class Variable
8
+ EMPTY = Class.new do
9
+ const_set(:INSPECT, 'Mutant::Variable::EMPTY')
10
+ end.new.freeze
11
+
12
+ TIMEOUT = Class.new do
13
+ const_set(:INSPECT, 'Mutant::Variable::TIMEOUT')
14
+ end.new.freeze
15
+
16
+ # Result of operation that may time out
17
+ class Result
18
+ include AbstractType, Adamantium::Flat
19
+
20
+ # Test if take resulted in a timeout
21
+ #
22
+ # @return [Boolean]
23
+ #
24
+ # @api private
25
+ def timeout?
26
+ instance_of?(Timeout)
27
+ end
28
+
29
+ abstract_method :value
30
+
31
+ # Instance returned on timeouts
32
+ class Timeout < self
33
+ include Equalizer.new
34
+
35
+ INSTANCE = new
36
+
37
+ # Construct new object
38
+ #
39
+ # @return [Timeout]
40
+ def self.new
41
+ INSTANCE
42
+ end
43
+ end # Timeout
44
+
45
+ # Instance returned without timeouts
46
+ class Value < self
47
+ include Concord::Public.new(:value)
48
+ end # Value
49
+ end # Result
50
+
51
+ private_constant(*constants(false))
52
+
53
+ # Initialize object
54
+ #
55
+ # @param [Object] value
56
+ # the initial value
57
+ #
58
+ # @return [undefined]
59
+ def initialize(condition_variable:, mutex:, value: EMPTY)
60
+ @full = condition_variable.new
61
+ @mutex = mutex.new
62
+ @value = value
63
+ end
64
+
65
+ # Take value from mvar, block on empty
66
+ #
67
+ # @return [Object]
68
+ def take
69
+ synchronize do
70
+ wait_full
71
+ perform_take
72
+ end
73
+ end
74
+
75
+ # Take value from mvar, with timeout
76
+ #
77
+ # @param [Float] Timeout
78
+ #
79
+ # @return [Result::Timeout]
80
+ # in case take resulted in a timeout
81
+ #
82
+ # @return [Result::Value]
83
+ # in case take resulted in a value
84
+ def take_timeout(timeout)
85
+ synchronize do
86
+ if wait_timeout(@full, timeout, &method(:full?))
87
+ Result::Timeout.new
88
+ else
89
+ Result::Value.new(perform_take)
90
+ end
91
+ end
92
+ end
93
+
94
+ # Read value from variable
95
+ #
96
+ # @return [Object]
97
+ # the contents of the mvar
98
+ def read
99
+ synchronize do
100
+ wait_full
101
+ @value
102
+ end
103
+ end
104
+
105
+ # Try put value into the variable, non blocking
106
+ #
107
+ # @param [Object] value
108
+ #
109
+ # @return [self]
110
+ def try_put(value)
111
+ synchronize do
112
+ perform_put(value) if empty?
113
+ end
114
+
115
+ self
116
+ end
117
+
118
+ # Execute block with value, blocking
119
+ #
120
+ # @yield [Object]
121
+ #
122
+ # @return [Object]
123
+ # the blocks return value
124
+ def with
125
+ synchronize do
126
+ wait_full
127
+ yield @value
128
+ end
129
+ end
130
+
131
+ private
132
+
133
+ # Perform the put
134
+ #
135
+ # @param [Object] value
136
+ def perform_put(value)
137
+ (@value = value).tap { @full.signal }
138
+ end
139
+
140
+ # Execute block under mutex
141
+ #
142
+ # @return [self]
143
+ def synchronize(&block)
144
+ @mutex.synchronize(&block)
145
+ end
146
+
147
+ # Wait for block predicate
148
+ #
149
+ # @param [ConditionVariable] event
150
+ #
151
+ # @return [undefined]
152
+ def wait(event)
153
+ event.wait(@mutex) until yield
154
+ end
155
+
156
+ # Wait with timeout for block predicate
157
+ #
158
+ # @param [ConditionVariable] event
159
+ #
160
+ # @return [Boolean]
161
+ # if wait was terminated due a timeout
162
+ #
163
+ # @return [undefined]
164
+ # otherwise
165
+ def wait_timeout(event, timeout)
166
+ loop do
167
+ break true if timeout <= 0
168
+ break if yield
169
+ timeout -= Timer.elapsed { event.wait(@mutex, timeout) }
170
+ end
171
+ end
172
+
173
+ # Wait till mvar is full
174
+ #
175
+ # @return [undefined]
176
+ def wait_full
177
+ wait(@full, &method(:full?))
178
+ end
179
+
180
+ # Test if state is full
181
+ #
182
+ # @return [Boolean]
183
+ def full?
184
+ !empty?
185
+ end
186
+
187
+ # Test if state is empty
188
+ #
189
+ # @return [Boolean]
190
+ def empty?
191
+ @value.equal?(EMPTY)
192
+ end
193
+
194
+ # Shared variable that can be written at most once
195
+ #
196
+ # ignore :reek:InstanceVariableAssumption
197
+ class IVar < self
198
+
199
+ # Exception raised on ivar errors
200
+ class Error < RuntimeError; end
201
+
202
+ # Put valie into the mvar, raises if already full
203
+ #
204
+ # @param [Object] value
205
+ #
206
+ # @return [self]
207
+ #
208
+ # @raise Error
209
+ # if already full
210
+ def put(value)
211
+ synchronize do
212
+ fail Error, 'is immutable' if full?
213
+ perform_put(value)
214
+ end
215
+
216
+ self
217
+ end
218
+
219
+ private
220
+
221
+ # Perform take operation
222
+ #
223
+ # @return [Object]
224
+ def perform_take
225
+ @value
226
+ end
227
+ end # IVar
228
+
229
+ # Shared variable that can be written multiple times
230
+ #
231
+ # ignore :reek:InstanceVariableAssumption
232
+ class MVar < self
233
+
234
+ # Initialize object
235
+ #
236
+ # @param [Object] value
237
+ # the initial value
238
+ #
239
+ # @return [undefined]
240
+ def initialize(condition_variable:, mutex:, value: EMPTY)
241
+ super
242
+ @empty = condition_variable.new
243
+ end
244
+
245
+ # Put value into mvar, block on full
246
+ #
247
+ # @param [Object] value
248
+ #
249
+ # @return [self]
250
+ def put(value)
251
+ synchronize do
252
+ wait(@empty, &method(:empty?))
253
+ perform_put(value)
254
+ end
255
+
256
+ self
257
+ end
258
+
259
+ # Modify mvar
260
+ #
261
+ # @return [Object]
262
+ def modify
263
+ synchronize do
264
+ wait_full
265
+ perform_put(yield(@value))
266
+ end
267
+ end
268
+
269
+ private
270
+
271
+ # Empty the mvar
272
+ #
273
+ # @return [Object]
274
+ def perform_take
275
+ @value.tap do
276
+ @value = EMPTY
277
+ @empty.signal
278
+ end
279
+ end
280
+ end # MVar
281
+ end # Variable
282
+ end # Mutant
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Mutant
4
4
  # Current mutant version
5
- VERSION = '0.8.24'
5
+ VERSION = '0.9.0'
6
6
  end # Mutant
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutant
4
+ # Class to capture warnings generated by Kernel#warn and Ruby itself.
5
+ #
6
+ # @example
7
+ # capture = Mutant::Warnings.new(Warning)
8
+ #
9
+ # # Note that this test case shows we can capture warnings generated from C
10
+ # def ruby_warning
11
+ # Class.new do
12
+ # undef :initialize
13
+ # end
14
+ # end
15
+ #
16
+ # messages = capture.call do
17
+ # ruby_warning
18
+ # end
19
+ #
20
+ # messages # => ["some_file.rb:44: warning: undefining `initialize' may cause serious problems\n"]
21
+ #
22
+ # Note this API is fundamentally impure:
23
+ #
24
+ # * Unlike almost all of classes in the mutant code base it has internal
25
+ # mutable state
26
+ # * Its therefore NOT thread safe
27
+ # * And worst: Each instance, even after its not referenced anymore by user
28
+ # code: Leaks permanent global state as instances of this class hook
29
+ # itself into the `Warning` module.
30
+ #
31
+ # So ideally only make *one* instance, and re-use it.
32
+ #
33
+ # Also note, a more canonical implementation would prepend modules and simply
34
+ # call `super` in the event the capture is disabled. This sadly does not
35
+ # work as it would inference with various bad players in the ruby ecosystem
36
+ # that do not adhere to the semantics outlined in the documentation.
37
+ #
38
+ # See: https://ruby-doc.org/core-2.6.3/Warning.html
39
+ #
40
+ # For example in case rubygems is active it adds its own hook to warnings,
41
+ # that would in case of the super implementation cause infinite recursion.
42
+ #
43
+ # Reproduction for this case is as simple as:
44
+ #
45
+ # ```
46
+ # require 'rubygems'
47
+ #
48
+ # module Warning
49
+ # def warn(*)
50
+ # super
51
+ # end
52
+ # end
53
+ # ```
54
+ #
55
+ # For that reason we do have to use the original method capture to dispatch
56
+ # in disabled state.
57
+ #
58
+ # :reek:ignore RepeatedConditional
59
+ class Warnings
60
+ # Error raised when warning capture is used recursively
61
+ class RecursiveUseError < RuntimeError; end
62
+
63
+ # Initialize object
64
+ #
65
+ # @param [Module] warning
66
+ # the module to integrate against
67
+ #
68
+ # @return [undefined]
69
+ def initialize(warning)
70
+ @disabled = true
71
+ @messages = []
72
+ @original = warning.public_method(:warn)
73
+
74
+ capture = method(:capture)
75
+ warning.module_eval do
76
+ module_function define_method(:warn, &capture)
77
+ end
78
+ end
79
+
80
+ # Run a block with warning collection enabled
81
+ #
82
+ # @return [Array<String>]
83
+ def call
84
+ assert_no_recursion
85
+ @disabled = nil
86
+ yield
87
+ IceNine.deep_freeze(@messages.dup)
88
+ ensure
89
+ @disabled = true
90
+ @messages.clear
91
+ end
92
+
93
+ private
94
+
95
+ # Hook called when capturing a warning
96
+ #
97
+ # @return [undefined]
98
+ def capture(*arguments)
99
+ if @disabled
100
+ @original.call(*arguments)
101
+ else
102
+ @messages << arguments
103
+ end
104
+ end
105
+
106
+ # Assert warnings capture does not call itself
107
+ #
108
+ # Its currently not supported nor intended to be supported.
109
+ def assert_no_recursion
110
+ fail RecursiveUseError unless @disabled
111
+ end
112
+ end # Warnings
113
+ end # Mutant
@@ -31,6 +31,7 @@ Mutant::Meta::Example.add :case do
31
31
  RUBY
32
32
  end
33
33
 
34
+ # rubocop:disable Metrics/BlockLength
34
35
  Mutant::Meta::Example.add :case do
35
36
  source <<-RUBY
36
37
  case condition
@@ -5,17 +5,8 @@ Mutant::Meta::Example.add :class do
5
5
 
6
6
  mutation 'class Foo; nil; end'
7
7
  mutation 'class Foo; self; end'
8
- mutation 'module Foo; bar; end'
9
8
  end
10
9
 
11
10
  Mutant::Meta::Example.add :class do
12
11
  source 'class Foo; end'
13
-
14
- mutation 'module Foo; end'
15
- end
16
-
17
- Mutant::Meta::Example.add :class do
18
- source 'class Foo < Baz; end'
19
-
20
- mutation 'module Foo; end'
21
12
  end
@@ -7,31 +7,6 @@ Mutant::Meta::Example.add :def do
7
7
  mutation 'def foo; super; end'
8
8
  end
9
9
 
10
- Mutant::Meta::Example.add :def do
11
- source 'def foo(a, *b); nil; end'
12
-
13
- mutation 'def foo(_a, *b); nil; end'
14
- mutation 'def foo; nil; end'
15
- mutation 'def foo(a, *b); end'
16
- mutation 'def foo(a, *b); raise; end'
17
- mutation 'def foo(a); nil; end'
18
- mutation 'def foo(*b); nil; end'
19
- mutation 'def foo(a, *b); b = []; nil; end'
20
- mutation 'def foo(a, *b); super; end'
21
- end
22
-
23
- Mutant::Meta::Example.add :def do
24
- source 'def foo(a, *); nil; end'
25
-
26
- mutation 'def foo(_a, *); nil; end'
27
- mutation 'def foo; nil; end'
28
- mutation 'def foo(a, *); end'
29
- mutation 'def foo(a, *); raise; end'
30
- mutation 'def foo(a); nil; end'
31
- mutation 'def foo(*); nil; end'
32
- mutation 'def foo(a, *); super; end'
33
- end
34
-
35
10
  Mutant::Meta::Example.add :def do
36
11
  source 'def foo; foo; rescue; end'
37
12
 
@@ -132,7 +107,7 @@ Mutant::Meta::Example.add :def do
132
107
  mutation 'def foo(a, b = nil); super; end'
133
108
  end
134
109
 
135
- Mutant::Meta::Example.add :def do
110
+ Mutant::Meta::Example.add :def, :arg do
136
111
  source 'def foo(_unused); end'
137
112
 
138
113
  mutation 'def foo(_unused); raise; end'