mutant 0.8.24 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -3
- data/Changelog.md +14 -654
- data/Gemfile +13 -0
- data/Gemfile.lock +59 -64
- data/LICENSE +271 -20
- data/README.md +73 -140
- data/Rakefile +0 -21
- data/bin/mutant +7 -2
- data/config/reek.yml +2 -1
- data/config/rubocop.yml +5 -9
- data/docs/incremental.md +76 -0
- data/docs/known-problems.md +0 -14
- data/docs/mutant-minitest.md +1 -1
- data/docs/mutant-rspec.md +2 -24
- data/lib/mutant.rb +45 -53
- data/lib/mutant/ast/nodes.rb +0 -2
- data/lib/mutant/ast/types.rb +1 -117
- data/lib/mutant/base.rb +192 -0
- data/lib/mutant/bootstrap.rb +145 -0
- data/lib/mutant/cli.rb +68 -54
- data/lib/mutant/config.rb +119 -6
- data/lib/mutant/env.rb +94 -8
- data/lib/mutant/expression.rb +6 -1
- data/lib/mutant/expression/parser.rb +9 -31
- data/lib/mutant/integration.rb +64 -36
- data/lib/mutant/isolation.rb +16 -1
- data/lib/mutant/isolation/fork.rb +105 -40
- data/lib/mutant/license.rb +34 -0
- data/lib/mutant/license/subscription.rb +47 -0
- data/lib/mutant/license/subscription/commercial.rb +57 -0
- data/lib/mutant/license/subscription/opensource.rb +77 -0
- data/lib/mutant/loader.rb +27 -4
- data/lib/mutant/matcher.rb +48 -1
- data/lib/mutant/matcher/chain.rb +1 -1
- data/lib/mutant/matcher/config.rb +0 -2
- data/lib/mutant/matcher/filter.rb +1 -1
- data/lib/mutant/matcher/method.rb +11 -7
- data/lib/mutant/matcher/methods.rb +1 -1
- data/lib/mutant/matcher/namespace.rb +1 -1
- data/lib/mutant/matcher/null.rb +1 -1
- data/lib/mutant/matcher/scope.rb +1 -1
- data/lib/mutant/meta/example/dsl.rb +0 -8
- data/lib/mutant/mutation.rb +1 -2
- data/lib/mutant/mutator/node.rb +2 -9
- data/lib/mutant/mutator/node/arguments.rb +1 -1
- data/lib/mutant/mutator/node/class.rb +0 -8
- data/lib/mutant/mutator/node/define.rb +0 -12
- data/lib/mutant/mutator/node/generic.rb +30 -44
- data/lib/mutant/mutator/node/index.rb +4 -4
- data/lib/mutant/mutator/node/literal/regex.rb +0 -39
- data/lib/mutant/mutator/node/send.rb +13 -12
- data/lib/mutant/parallel.rb +61 -40
- data/lib/mutant/parallel/driver.rb +59 -0
- data/lib/mutant/parallel/source.rb +6 -2
- data/lib/mutant/parallel/worker.rb +63 -45
- data/lib/mutant/range.rb +15 -0
- data/lib/mutant/reporter/cli.rb +5 -11
- data/lib/mutant/reporter/cli/format.rb +3 -46
- data/lib/mutant/reporter/cli/printer/config.rb +5 -6
- data/lib/mutant/reporter/cli/printer/env.rb +40 -0
- data/lib/mutant/reporter/cli/printer/env_progress.rb +13 -17
- data/lib/mutant/reporter/cli/printer/isolation_result.rb +17 -3
- data/lib/mutant/reporter/cli/printer/mutation_result.rb +2 -3
- data/lib/mutant/reporter/cli/printer/status_progressive.rb +19 -10
- data/lib/mutant/repository.rb +0 -65
- data/lib/mutant/repository/diff.rb +104 -0
- data/lib/mutant/repository/diff/ranges.rb +52 -0
- data/lib/mutant/result.rb +16 -7
- data/lib/mutant/runner.rb +38 -47
- data/lib/mutant/runner/sink.rb +1 -1
- data/lib/mutant/selector/null.rb +19 -0
- data/lib/mutant/subject.rb +3 -1
- data/lib/mutant/subject/method/instance.rb +3 -1
- data/lib/mutant/transform.rb +511 -0
- data/lib/mutant/variable.rb +282 -0
- data/lib/mutant/version.rb +1 -1
- data/lib/mutant/warnings.rb +113 -0
- data/meta/case.rb +1 -0
- data/meta/class.rb +0 -9
- data/meta/def.rb +1 -26
- data/meta/regexp.rb +10 -20
- data/meta/send.rb +14 -46
- data/mutant-minitest.gemspec +1 -1
- data/mutant-rspec.gemspec +2 -2
- data/mutant.gemspec +15 -16
- data/mutant.yml +6 -0
- data/spec/integration/mutant/isolation/fork_spec.rb +22 -5
- data/spec/integration/mutant/minitest_spec.rb +3 -2
- data/spec/integration/mutant/rspec_spec.rb +4 -3
- data/spec/integrations.yml +16 -13
- data/spec/shared/base_behavior.rb +45 -0
- data/spec/shared/framework_integration_behavior.rb +43 -14
- data/spec/spec_helper.rb +21 -17
- data/spec/support/corpus.rb +56 -95
- data/spec/support/shared_context.rb +37 -14
- data/spec/support/xspec.rb +7 -3
- data/spec/unit/mutant/bootstrap_spec.rb +216 -0
- data/spec/unit/mutant/cli_spec.rb +173 -117
- data/spec/unit/mutant/config_spec.rb +126 -0
- data/spec/unit/mutant/either_spec.rb +247 -0
- data/spec/unit/mutant/env_spec.rb +162 -40
- data/spec/unit/mutant/expression/method_spec.rb +16 -0
- data/spec/unit/mutant/expression/parser_spec.rb +29 -33
- data/spec/unit/mutant/expression_spec.rb +5 -7
- data/spec/unit/mutant/integration_spec.rb +100 -9
- data/spec/unit/mutant/isolation/fork_spec.rb +125 -67
- data/spec/unit/mutant/isolation/result_spec.rb +33 -1
- data/spec/unit/mutant/license_spec.rb +257 -0
- data/spec/unit/mutant/loader_spec.rb +50 -11
- data/spec/unit/mutant/matcher/compiler_spec.rb +0 -78
- data/spec/unit/mutant/matcher/method/instance_spec.rb +55 -11
- data/spec/unit/mutant/matcher/method/singleton_spec.rb +12 -2
- data/spec/unit/mutant/matcher_spec.rb +102 -0
- data/spec/unit/mutant/maybe_spec.rb +60 -0
- data/spec/unit/mutant/meta/example/dsl_spec.rb +1 -17
- data/spec/unit/mutant/mutation_spec.rb +13 -6
- data/spec/unit/mutant/parallel/driver_spec.rb +112 -14
- data/spec/unit/mutant/parallel/source/array_spec.rb +25 -17
- data/spec/unit/mutant/parallel/worker_spec.rb +182 -44
- data/spec/unit/mutant/parallel_spec.rb +105 -8
- data/spec/unit/mutant/range_spec.rb +141 -0
- data/spec/unit/mutant/reporter/cli/printer/config_spec.rb +7 -21
- data/spec/unit/mutant/reporter/cli/printer/env_progress_spec.rb +15 -6
- data/spec/unit/mutant/reporter/cli/printer/env_result_spec.rb +10 -2
- data/spec/unit/mutant/reporter/cli/printer/isolation_result_spec.rb +12 -4
- data/spec/unit/mutant/reporter/cli/printer/mutation_result_spec.rb +31 -2
- data/spec/unit/mutant/reporter/cli/printer/status_progressive_spec.rb +4 -4
- data/spec/unit/mutant/reporter/cli/printer/subject_result_spec.rb +5 -0
- data/spec/unit/mutant/reporter/cli_spec.rb +46 -123
- data/spec/unit/mutant/repository/diff/ranges_spec.rb +180 -0
- data/spec/unit/mutant/repository/diff_spec.rb +84 -71
- data/spec/unit/mutant/require_highjack_spec.rb +1 -1
- data/spec/unit/mutant/result/env_spec.rb +39 -9
- data/spec/unit/mutant/result/test_spec.rb +14 -0
- data/spec/unit/mutant/runner_spec.rb +88 -41
- data/spec/unit/mutant/selector/expression_spec.rb +11 -10
- data/spec/unit/mutant/selector/null_spec.rb +17 -0
- data/spec/unit/mutant/subject/method/instance_spec.rb +44 -5
- data/spec/unit/mutant/subject/method/singleton_spec.rb +9 -2
- data/spec/unit/mutant/subject_spec.rb +9 -1
- data/spec/unit/mutant/transform/array_spec.rb +92 -0
- data/spec/unit/mutant/transform/bool_spec.rb +63 -0
- data/spec/unit/mutant/transform/error_spec.rb +132 -0
- data/spec/unit/mutant/transform/exception_spec.rb +44 -0
- data/spec/unit/mutant/transform/hash_spec.rb +236 -0
- data/spec/unit/mutant/transform/index_spec.rb +92 -0
- data/spec/unit/mutant/transform/named_spec.rb +49 -0
- data/spec/unit/mutant/transform/primitive_spec.rb +56 -0
- data/spec/unit/mutant/transform/sequence_spec.rb +98 -0
- data/spec/unit/mutant/variable_spec.rb +618 -0
- data/spec/unit/mutant/warnings_spec.rb +89 -0
- data/spec/unit/mutant/world_spec.rb +63 -0
- data/test_app/Gemfile.minitest +0 -2
- metadata +79 -113
- data/.gitattributes +0 -1
- data/.ruby-gemset +0 -1
- data/config/triage.yml +0 -2
- data/lib/mutant/actor.rb +0 -57
- data/lib/mutant/actor/env.rb +0 -31
- data/lib/mutant/actor/mailbox.rb +0 -34
- data/lib/mutant/actor/receiver.rb +0 -42
- data/lib/mutant/actor/sender.rb +0 -26
- data/lib/mutant/ast/meta/restarg.rb +0 -19
- data/lib/mutant/ast/regexp.rb +0 -42
- data/lib/mutant/ast/regexp/transformer.rb +0 -187
- data/lib/mutant/ast/regexp/transformer/direct.rb +0 -123
- data/lib/mutant/ast/regexp/transformer/named_group.rb +0 -59
- data/lib/mutant/ast/regexp/transformer/options_group.rb +0 -83
- data/lib/mutant/ast/regexp/transformer/quantifier.rb +0 -114
- data/lib/mutant/ast/regexp/transformer/recursive.rb +0 -58
- data/lib/mutant/ast/regexp/transformer/root.rb +0 -31
- data/lib/mutant/ast/regexp/transformer/text.rb +0 -60
- data/lib/mutant/env/bootstrap.rb +0 -160
- data/lib/mutant/matcher/compiler.rb +0 -60
- data/lib/mutant/mutator/node/regexp.rb +0 -35
- data/lib/mutant/mutator/node/regexp/alternation_meta.rb +0 -23
- data/lib/mutant/mutator/node/regexp/capture_group.rb +0 -28
- data/lib/mutant/mutator/node/regexp/character_type.rb +0 -32
- data/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb +0 -23
- data/lib/mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor.rb +0 -23
- data/lib/mutant/mutator/node/regexp/greedy_zero_or_more.rb +0 -27
- data/lib/mutant/parallel/master.rb +0 -181
- data/lib/mutant/reporter/cli/printer/status.rb +0 -53
- data/lib/mutant/reporter/cli/tput.rb +0 -46
- data/lib/mutant/warning_filter.rb +0 -61
- data/meta/regexp/character_types.rb +0 -23
- data/meta/regexp/regexp_alternation_meta.rb +0 -13
- data/meta/regexp/regexp_bol_anchor.rb +0 -10
- data/meta/regexp/regexp_bos_anchor.rb +0 -18
- data/meta/regexp/regexp_capture_group.rb +0 -19
- data/meta/regexp/regexp_eol_anchor.rb +0 -10
- data/meta/regexp/regexp_eos_anchor.rb +0 -8
- data/meta/regexp/regexp_eos_ob_eol_anchor.rb +0 -10
- data/meta/regexp/regexp_greedy_zero_or_more.rb +0 -12
- data/meta/regexp/regexp_root_expression.rb +0 -10
- data/meta/restarg.rb +0 -10
- data/spec/support/fake_actor.rb +0 -111
- data/spec/support/warning.rb +0 -66
- data/spec/unit/mutant/actor/binding_spec.rb +0 -34
- data/spec/unit/mutant/actor/env_spec.rb +0 -31
- data/spec/unit/mutant/actor/mailbox_spec.rb +0 -28
- data/spec/unit/mutant/actor/message_spec.rb +0 -25
- data/spec/unit/mutant/actor/receiver_spec.rb +0 -58
- data/spec/unit/mutant/actor/sender_spec.rb +0 -24
- data/spec/unit/mutant/ast/regexp/parse_spec.rb +0 -19
- data/spec/unit/mutant/ast/regexp/transformer/lookup_table/table_spec.rb +0 -21
- data/spec/unit/mutant/ast/regexp/transformer/lookup_table_spec.rb +0 -35
- data/spec/unit/mutant/ast/regexp/transformer_spec.rb +0 -21
- data/spec/unit/mutant/ast/regexp_spec.rb +0 -704
- data/spec/unit/mutant/env/bootstrap_spec.rb +0 -188
- data/spec/unit/mutant/matcher/compiler/subject_prefix_spec.rb +0 -26
- data/spec/unit/mutant/parallel/master_spec.rb +0 -338
- data/spec/unit/mutant/reporter/cli/printer/status_spec.rb +0 -121
- data/spec/unit/mutant/reporter/cli/tput_spec.rb +0 -50
- data/spec/unit/mutant/warning_filter_spec.rb +0 -106
- data/spec/unit/mutant_spec.rb +0 -17
- 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
|
-
|
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 = '
|
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
|
-
|
27
|
+
amount_mutation_results,
|
28
28
|
amount_mutations,
|
29
|
-
|
30
|
-
killtime,
|
29
|
+
amount_mutations_alive,
|
31
30
|
runtime,
|
32
|
-
|
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
|
data/lib/mutant/repository.rb
CHANGED
@@ -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
|
data/lib/mutant/result.rb
CHANGED
@@ -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
|
data/lib/mutant/runner.rb
CHANGED
@@ -1,84 +1,75 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Mutant
|
4
|
-
# Runner
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# Initialize object
|
4
|
+
# Runner
|
5
|
+
module Runner
|
6
|
+
# Run against env
|
9
7
|
#
|
10
|
-
# @return [
|
11
|
-
def
|
12
|
-
|
8
|
+
# @return [Either<String, Result>]
|
9
|
+
def self.apply(env)
|
10
|
+
reporter(env).start(env)
|
13
11
|
|
14
|
-
|
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
|
-
|
31
|
-
|
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.
|
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 [
|
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
|
-
|
62
|
-
jobs:
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|