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
@@ -5,11 +5,15 @@ module Mutant
5
5
  class CLI
6
6
  class Printer
7
7
  # Reporter for mutation results
8
- #
9
- # :reek:TooManyConstants
10
8
  class IsolationResult < self
11
9
  CHILD_ERROR_MESSAGE = <<~'MESSAGE'
12
- Killfork exited nonzero. Its result (if any) was ignored:
10
+ Killfork exited nonzero. Its result (if any) was ignored.
11
+ Process status:
12
+ %s
13
+ MESSAGE
14
+
15
+ LOG_MESSAGES = <<~'MESSAGE'
16
+ Log messages (combined stderr and stdout):
13
17
  %s
14
18
  MESSAGE
15
19
 
@@ -57,6 +61,7 @@ module Mutant
57
61
  # @return [undefined]
58
62
  def run
59
63
  __send__(MAP.fetch(object.class))
64
+ print_log_messages
60
65
  end
61
66
 
62
67
  private
@@ -68,6 +73,15 @@ module Mutant
68
73
  visit(TestResult, object.value)
69
74
  end
70
75
 
76
+ # Print log messages
77
+ #
78
+ # @return [undefined]
79
+ def print_log_messages
80
+ log = object.log
81
+
82
+ puts(LOG_MESSAGES % log) unless log.empty?
83
+ end
84
+
71
85
  # Visit child error isolation result
72
86
  #
73
87
  # @return [undefined]
@@ -5,8 +5,6 @@ module Mutant
5
5
  class CLI
6
6
  class Printer
7
7
  # Reporter for mutation results
8
- #
9
- # :reek:TooManyConstants
10
8
  class MutationResult < self
11
9
 
12
10
  delegate :mutation, :isolation_result
@@ -67,7 +65,8 @@ module Mutant
67
65
  def print_details
68
66
  __send__(MAP.fetch(mutation.class))
69
67
 
70
- visit_isolation_result unless isolation_result.success?
68
+ puts(FOOTER)
69
+ visit_isolation_result
71
70
  end
72
71
 
73
72
  # Evil mutation details
@@ -6,16 +6,16 @@ module Mutant
6
6
  class Printer
7
7
  # Reporter for progressive output format on scheduler Status objects
8
8
  class StatusProgressive < self
9
- FORMAT = '(%02d/%02d) %3d%% - killtime: %0.02fs runtime: %0.02fs overhead: %0.02fs'
9
+ FORMAT = 'progress: %02d/%02d alive: %d runtime: %0.02fs killtime: %0.02fs mutations/s: %0.02f'
10
10
 
11
11
  delegate(
12
- :coverage,
13
- :runtime,
14
- :amount_mutations_killed,
15
- :amount_mutations,
16
12
  :amount_mutation_results,
13
+ :amount_mutations,
14
+ :amount_mutations_alive,
15
+ :amount_mutations_killed,
17
16
  :killtime,
18
- :overhead
17
+ :overhead,
18
+ :runtime
19
19
  )
20
20
 
21
21
  # Run printer
@@ -24,12 +24,12 @@ module Mutant
24
24
  def run
25
25
  status(
26
26
  FORMAT,
27
- amount_mutations_killed,
27
+ amount_mutation_results,
28
28
  amount_mutations,
29
- coverage * 100,
30
- killtime,
29
+ amount_mutations_alive,
31
30
  runtime,
32
- overhead
31
+ killtime,
32
+ mutations_per_second
33
33
  )
34
34
  end
35
35
 
@@ -41,6 +41,15 @@ module Mutant
41
41
  def object
42
42
  super().payload
43
43
  end
44
+
45
+ # Mutations processed per second
46
+ #
47
+ # @return [Float]
48
+ #
49
+ # @api private
50
+ def mutations_per_second
51
+ amount_mutation_results / runtime
52
+ end
44
53
  end # StatusProgressive
45
54
  end # Printer
46
55
  end # CLI
@@ -2,9 +2,6 @@
2
2
 
3
3
  module Mutant
4
4
  module Repository
5
- # Error raised on repository interaction problems
6
- RepositoryError = Class.new(RuntimeError)
7
-
8
5
  # Subject filter based on repository diff
9
6
  class SubjectFilter
10
7
  include Adamantium, Concord.new(:diff)
@@ -19,67 +16,5 @@ module Mutant
19
16
  end
20
17
 
21
18
  end # SubjectFilter
22
-
23
- # Diff between two objects in repository
24
- class Diff
25
- include Adamantium, Anima.new(:config, :from, :to)
26
-
27
- HEAD = 'HEAD'
28
-
29
- # Test if diff changes file at line range
30
- #
31
- # @param [Pathname] path
32
- # @param [Range<Integer>] line_range
33
- #
34
- # @return [Boolean]
35
- #
36
- # @raise [RepositoryError]
37
- # when git command failed
38
- def touches?(path, line_range)
39
- return false unless within_working_directory?(path) && tracks?(path)
40
-
41
- command = %W[
42
- git log
43
- #{from}...#{to}
44
- --ignore-all-space
45
- -L #{line_range.begin},#{line_range.end}:#{path}
46
- ]
47
-
48
- stdout, status = config.open3.capture2(*command, binmode: true)
49
-
50
- fail RepositoryError, "Command #{command} failed!" unless status.success?
51
-
52
- !stdout.empty?
53
- end
54
-
55
- private
56
-
57
- # Test if path is tracked in repository
58
- #
59
- # FIXME: Cache results, to avoid spending time on producing redundant results.
60
- #
61
- # @param [Pathname] path
62
- #
63
- # @return [Boolean]
64
- def tracks?(path)
65
- command = %W[git ls-files --error-unmatch -- #{path}]
66
- config.kernel.system(
67
- *command,
68
- out: File::NULL,
69
- err: File::NULL
70
- )
71
- end
72
-
73
- # Test if the path is within the current working directory
74
- #
75
- # @param [Pathname] path
76
- #
77
- # @return [TrueClass, nil]
78
- def within_working_directory?(path)
79
- working_directory = config.pathname.pwd
80
- path.ascend { |parent| return true if working_directory.eql?(parent) }
81
- end
82
-
83
- end # Diff
84
19
  end # Repository
85
20
  end # Mutant
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutant
4
+ module Repository
5
+ # Diff index between HEAD and a tree reference
6
+ class Diff
7
+ include Adamantium, Anima.new(:world, :to)
8
+
9
+ FORMAT = /\A:\d{6} \d{6} [a-f\d]{40} [a-f\d]{40} [ACDMRTUX]\t(.*)\n\z/.freeze
10
+
11
+ private_constant(*constants(false))
12
+
13
+ class Error < RuntimeError; end
14
+
15
+ # Test if diff changes file at line range
16
+ #
17
+ # @param [Pathname] path
18
+ # @param [Range<Integer>] line_range
19
+ #
20
+ # @return [Boolean]
21
+ #
22
+ # @raise [RepositoryError]
23
+ # when git command failed
24
+ def touches?(path, line_range)
25
+ touched_paths
26
+ .fetch(path) { return false }
27
+ .touches?(line_range)
28
+ end
29
+
30
+ private
31
+
32
+ # Touched paths
33
+ #
34
+ # @return [Hash{Pathname => Path}]
35
+ #
36
+ # rubocop:disable Metrics/MethodLength
37
+ def touched_paths
38
+ pathname = world.pathname
39
+ work_dir = pathname.pwd
40
+
41
+ world
42
+ .capture_stdout(%W[git diff-index #{to}])
43
+ .from_right
44
+ .lines
45
+ .map do |line|
46
+ path = parse_line(work_dir, line)
47
+ [path.path, path]
48
+ end
49
+ .to_h
50
+ end
51
+ memoize :touched_paths
52
+
53
+ # Parse path
54
+ #
55
+ # @param [Pathname] work_dir
56
+ # @param [String] line
57
+ #
58
+ # @return [Path]
59
+ def parse_line(work_dir, line)
60
+ match = FORMAT.match(line) or fail Error, "Invalid git diff-index line: #{line}"
61
+
62
+ Path.new(
63
+ path: work_dir.join(match.captures.first),
64
+ to: to,
65
+ world: world
66
+ )
67
+ end
68
+
69
+ # Path touched by a diff
70
+ class Path
71
+ include Adamantium, Anima.new(:world, :to, :path)
72
+
73
+ DECIMAL = /(?:0|[1-9]\d*)/.freeze
74
+ REGEXP = /\A@@ -(#{DECIMAL})(?:,(#{DECIMAL}))? \+(#{DECIMAL})(?:,(#{DECIMAL}))? @@/.freeze
75
+
76
+ private_constant(*constants(false))
77
+
78
+ # Test if diff path touches a line range
79
+ #
80
+ # @param [Range<Integer>] range
81
+ #
82
+ # @return [Boolean]
83
+ def touches?(line_range)
84
+ diff_ranges.any? do |range|
85
+ Range.overlap?(range, line_range)
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ # Ranges of hunks in the diff
92
+ #
93
+ # @return [Array<Range<Integer>>]
94
+ def diff_ranges
95
+ world
96
+ .capture_stdout(%W[git diff --unified=0 #{to} -- #{path}])
97
+ .fmap(&Ranges.method(:parse))
98
+ .from_right
99
+ end
100
+ memoize :diff_ranges
101
+ end # Path
102
+ end # Diff
103
+ end # Repository
104
+ end # Mutant
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutant
4
+ module Repository
5
+ class Diff
6
+ module Ranges
7
+ DECIMAL = /(?:0|[1-9]\d*)/.freeze
8
+ REGEXP = /\A@@ -(#{DECIMAL})(?:,(#{DECIMAL}))? \+(#{DECIMAL})(?:,(#{DECIMAL}))? @@/.freeze
9
+
10
+ private_constant(*constants(false))
11
+
12
+ # Parse a unified diff into ranges
13
+ #
14
+ # @param [String]
15
+ #
16
+ # @return [Set<Range<Integer>>]
17
+ def self.parse(diff)
18
+ diff.lines.flat_map(&method(:parse_ranges)).to_set
19
+ end
20
+
21
+ # Parse ranges from line
22
+ #
23
+ # @param [String] line
24
+ #
25
+ # @return [Array<Range<Integer>>]
26
+ def self.parse_ranges(line)
27
+ match = REGEXP.match(line) or return EMPTY_ARRAY
28
+
29
+ match
30
+ .captures
31
+ .each_slice(2)
32
+ .map { |start, offset| mk_range(start, offset) }
33
+ .reject { |range| range.end < range.begin }
34
+ end
35
+ private_class_method :parse_ranges
36
+
37
+ # Construct a range from start point and offset
38
+ #
39
+ # @param [String] start
40
+ # @param [String, nil] offset
41
+ #
42
+ # @return [Range<Integer>]
43
+ def self.mk_range(start, offset)
44
+ start = Integer(start)
45
+
46
+ ::Range.new(start, start + (offset ? Integer(offset).pred : 0))
47
+ end
48
+ private_class_method :mk_range
49
+ end # Ranges
50
+ end # Diff
51
+ end # Repository
52
+ end # Ranges
@@ -101,13 +101,6 @@ module Mutant
101
101
  env.mutations.length
102
102
  end
103
103
 
104
- # Amount of subjects
105
- #
106
- # @return [Integer]
107
- def amount_subjects
108
- env.subjects.length
109
- end
110
-
111
104
  # Test if processing needs to stop
112
105
  #
113
106
  # @return [Boolean]
@@ -126,6 +119,22 @@ module Mutant
126
119
  :runtime,
127
120
  :tests
128
121
  )
122
+
123
+ class VoidValue < self
124
+ include Singleton
125
+
126
+ # Initialize object
127
+ #
128
+ # @return [undefined]
129
+ def initialize
130
+ super(
131
+ output: '',
132
+ passed: false,
133
+ runtime: 0.0,
134
+ tests: []
135
+ )
136
+ end
137
+ end # VoidValue
129
138
  end # Test
130
139
 
131
140
  # Subject result
@@ -1,84 +1,75 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mutant
4
- # Runner baseclass
5
- class Runner
6
- include Adamantium::Flat, Concord.new(:env), Procto.call(:result)
7
-
8
- # Initialize object
4
+ # Runner
5
+ module Runner
6
+ # Run against env
9
7
  #
10
- # @return [undefined]
11
- def initialize(*)
12
- super
8
+ # @return [Either<String, Result>]
9
+ def self.apply(env)
10
+ reporter(env).start(env)
13
11
 
14
- reporter.start(env)
15
-
16
- run_mutation_analysis
12
+ Either::Right.new(run_mutation_analysis(env))
17
13
  end
18
14
 
19
- # Final result
20
- #
21
- # @return [Result::Env]
22
- attr_reader :result
23
-
24
- private
25
-
26
15
  # Run mutation analysis
27
16
  #
28
17
  # @return [undefined]
29
- def run_mutation_analysis
30
- @result = run_driver(Parallel.async(mutation_test_config))
31
- reporter.report(result)
18
+ def self.run_mutation_analysis(env)
19
+ reporter = reporter(env)
20
+
21
+ run_driver(
22
+ reporter,
23
+ Parallel.async(mutation_test_config(env))
24
+ ).tap do |result|
25
+ reporter.report(result)
26
+ end
32
27
  end
28
+ private_class_method :run_mutation_analysis
33
29
 
34
30
  # Run driver
35
31
  #
32
+ # @param [Reporter] reporter
36
33
  # @param [Driver] driver
37
34
  #
38
35
  # @return [Object]
39
36
  # the last returned status payload
40
- def run_driver(driver)
41
- status = nil
42
- sleep = env.config.kernel.method(:sleep)
43
-
37
+ def self.run_driver(reporter, driver)
44
38
  loop do
45
- status = driver.status
39
+ status = driver.wait_timeout(reporter.delay)
40
+ break status.payload if status.done?
46
41
  reporter.progress(status)
47
- break if status.done
48
- sleep.call(reporter.delay)
49
42
  end
50
-
51
- driver.stop
52
-
53
- status.payload
54
43
  end
44
+ private_class_method :run_driver
55
45
 
56
46
  # Configuration for parallel execution engine
57
47
  #
58
- # @return [Parallel::Config]
59
- def mutation_test_config
48
+ # @return [Parallell::Config]
49
+ def self.mutation_test_config(env)
50
+ world = env.world
51
+
60
52
  Parallel::Config.new(
61
- env: env.actor_env,
62
- jobs: config.jobs,
63
- processor: env.method(:kill),
64
- sink: Sink.new(env),
65
- source: Parallel::Source::Array.new(env.mutations)
53
+ condition_variable: world.condition_variable,
54
+ jobs: env.config.jobs,
55
+ mutex: world.mutex,
56
+ processor: env.method(:kill),
57
+ sink: Sink.new(env),
58
+ source: Parallel::Source::Array.new(env.mutations),
59
+ thread: world.thread
66
60
  )
67
61
  end
62
+ private_class_method :mutation_test_config
68
63
 
69
64
  # Reporter to use
70
65
  #
66
+ # @param [Env] env
67
+ #
71
68
  # @return [Reporter]
72
- def reporter
69
+ def self.reporter(env)
73
70
  env.config.reporter
74
71
  end
75
-
76
- # Config for this mutant execution
77
- #
78
- # @return [Config]
79
- def config
80
- env.config
81
- end
72
+ private_class_method :reporter
82
73
 
83
74
  end # Runner
84
75
  end # Mutant