evilution 1.5.1 → 1.6.0
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.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +30 -0
- data/CHANGELOG.md +49 -0
- data/README.md +285 -45
- data/docs/architecture.md +110 -12
- data/docs/ast_pattern_syntax.md +35 -7
- data/docs/combined_runs_spike.md +407 -0
- data/docs/integrations.md +1 -1
- data/docs/isolation.md +63 -2
- data/docs/migration-from-mutant.md +16 -11
- data/docs/mutant_schemata_spike.md +387 -0
- data/docs/operator_yield_study.md +576 -0
- data/docs/probe_first_spike.md +264 -0
- data/lib/evilution/ast/ancestor_lookup.rb +36 -0
- data/lib/evilution/ast/callback_declaration.rb +36 -3
- data/lib/evilution/ast/class_body.rb +62 -16
- data/lib/evilution/ast/def_region.rb +130 -0
- data/lib/evilution/ast/local_declaration.rb +37 -0
- data/lib/evilution/ast/parent_index.rb +50 -0
- data/lib/evilution/ast/parse_cache.rb +27 -0
- data/lib/evilution/ast/parser.rb +8 -3
- data/lib/evilution/ast/pattern/filter.rb +53 -12
- data/lib/evilution/ast/skip_filter.rb +83 -0
- data/lib/evilution/ast/skip_sites/debug_output.rb +67 -0
- data/lib/evilution/ast/skip_sites/error_messages.rb +74 -0
- data/lib/evilution/ast/skip_sites/logging.rb +93 -0
- data/lib/evilution/ast/skip_sites/message.rb +44 -0
- data/lib/evilution/ast/skip_sites/nodes.rb +105 -0
- data/lib/evilution/ast/skip_sites/presets.rb +31 -0
- data/lib/evilution/ast/skip_sites/purity.rb +69 -0
- data/lib/evilution/ast/skip_sites/requires.rb +40 -0
- data/lib/evilution/ast/skip_sites.rb +9 -0
- data/lib/evilution/ast/source_surgeon.rb +20 -2
- data/lib/evilution/ast/syntax_check.rb +10 -8
- data/lib/evilution/baseline/report.rb +11 -2
- data/lib/evilution/baseline.rb +31 -6
- data/lib/evilution/cache/keys.rb +140 -0
- data/lib/evilution/cache/run_fingerprint.rb +51 -0
- data/lib/evilution/cache/skeleton.rb +57 -0
- data/lib/evilution/cache/spec_digest.rb +39 -0
- data/lib/evilution/cache.rb +143 -50
- data/lib/evilution/class_tree.rb +38 -0
- data/lib/evilution/cli/command.rb +12 -4
- data/lib/evilution/cli/commands/run.rb +12 -3
- data/lib/evilution/cli/commands/subjects.rb +5 -2
- data/lib/evilution/cli/parser/options_builder.rb +67 -3
- data/lib/evilution/cli/printers/environment.rb +34 -4
- data/lib/evilution/cli/printers/session_detail.rb +20 -3
- data/lib/evilution/compare/categorizer.rb +2 -1
- data/lib/evilution/compare/normalizer.rb +3 -2
- data/lib/evilution/config/sources.rb +3 -0
- data/lib/evilution/config/validators/base.rb +9 -0
- data/lib/evilution/config/validators/since.rb +22 -0
- data/lib/evilution/config/validators/skip_sites.rb +24 -0
- data/lib/evilution/config/validators/timeout_ceiling.rb +10 -0
- data/lib/evilution/config/validators/timeout_factor.rb +10 -0
- data/lib/evilution/config/validators/timeout_floor.rb +10 -0
- data/lib/evilution/config.rb +122 -6
- data/lib/evilution/coverage/load_tracker.rb +50 -0
- data/lib/evilution/coverage/map.rb +42 -5
- data/lib/evilution/coverage/map_builder.rb +123 -22
- data/lib/evilution/coverage/map_store.rb +15 -5
- data/lib/evilution/coverage/recorder.rb +42 -3
- data/lib/evilution/coverage_example_filter.rb +35 -0
- data/lib/evilution/equivalent/heuristic/comment_marking.rb +14 -1
- data/lib/evilution/example_filter.rb +20 -0
- data/lib/evilution/git/changed_lines.rb +103 -0
- data/lib/evilution/git/since_scope.rb +77 -0
- data/lib/evilution/git/unified_diff.rb +68 -0
- data/lib/evilution/infra_crash.rb +26 -0
- data/lib/evilution/integration/base.rb +97 -6
- data/lib/evilution/integration/crash_detector.rb +46 -6
- data/lib/evilution/integration/known_failures.rb +4 -0
- data/lib/evilution/integration/loading/body_call_neutralizer.rb +49 -11
- data/lib/evilution/integration/loading/callback_equivalence.rb +62 -0
- data/lib/evilution/integration/loading/callback_redeclaration.rb +151 -36
- data/lib/evilution/integration/loading/concern_redeclaration.rb +16 -12
- data/lib/evilution/integration/loading/concern_registry.rb +87 -0
- data/lib/evilution/integration/loading/concern_state_cleaner.rb +19 -8
- data/lib/evilution/integration/loading/created_modules.rb +56 -0
- data/lib/evilution/integration/loading/frozen_namespaces.rb +80 -0
- data/lib/evilution/integration/loading/mutation_applier.rb +42 -11
- data/lib/evilution/integration/loading/neutralization.rb +41 -0
- data/lib/evilution/integration/loading/redefinition_recovery.rb +5 -3
- data/lib/evilution/integration/loading/superseded_modules.rb +22 -19
- data/lib/evilution/integration/minitest/stop_hook.rb +57 -0
- data/lib/evilution/integration/minitest.rb +22 -2
- data/lib/evilution/integration/minitest_crash_detector.rb +19 -0
- data/lib/evilution/integration/rspec/baseline_runner.rb +3 -2
- data/lib/evilution/integration/rspec/crash_detector_lifecycle.rb +6 -1
- data/lib/evilution/integration/rspec/example_filter_applier.rb +16 -0
- data/lib/evilution/integration/rspec/example_ids.rb +23 -0
- data/lib/evilution/integration/rspec/example_order.rb +86 -0
- data/lib/evilution/integration/rspec/killer_first.rb +72 -0
- data/lib/evilution/integration/rspec/result_builder.rb +7 -0
- data/lib/evilution/integration/rspec/state_guard/example_group_descendants.rb +44 -0
- data/lib/evilution/integration/rspec/state_guard.rb +2 -2
- data/lib/evilution/integration/rspec/target_resolver.rb +42 -0
- data/lib/evilution/integration/rspec/test_file_resolver.rb +4 -2
- data/lib/evilution/integration/rspec.rb +98 -47
- data/lib/evilution/integration/stop_policy.rb +49 -0
- data/lib/evilution/integration/test_unit/dispatcher.rb +20 -1
- data/lib/evilution/integration/test_unit/subject_class_registry.rb +6 -1
- data/lib/evilution/integration/test_unit.rb +28 -2
- data/lib/evilution/isolation/fork.rb +58 -13
- data/lib/evilution/isolation/in_process.rb +12 -1
- data/lib/evilution/line_set.rb +72 -0
- data/lib/evilution/mcp/info_tool/actions/environment.rb +12 -16
- data/lib/evilution/mcp/info_tool/actions/subjects.rb +3 -5
- data/lib/evilution/mcp/info_tool/status_glossary.rb +15 -2
- data/lib/evilution/mcp/info_tool.rb +24 -17
- data/lib/evilution/mcp/mutate_tool/config_builder.rb +13 -1
- data/lib/evilution/mcp/mutate_tool/option_parser.rb +2 -2
- data/lib/evilution/mcp/mutate_tool/progress_streamer.rb +1 -1
- data/lib/evilution/mcp/mutate_tool/report_trimmer.rb +28 -5
- data/lib/evilution/mcp/mutate_tool/survived_enricher.rb +12 -7
- data/lib/evilution/mcp/mutate_tool.rb +32 -7
- data/lib/evilution/mcp/session_tool.rb +1 -2
- data/lib/evilution/mcp.rb +4 -0
- data/lib/evilution/mutation/line_diff.rb +111 -0
- data/lib/evilution/mutation.rb +17 -13
- data/lib/evilution/mutator/base.rb +121 -98
- data/lib/evilution/mutator/constant_value_subjects.rb +29 -1
- data/lib/evilution/mutator/line_range_filter.rb +27 -0
- data/lib/evilution/mutator/load_sources.rb +88 -0
- data/lib/evilution/mutator/operator/alias_removal.rb +2 -5
- data/lib/evilution/mutator/operator/argument_method_call_replacement.rb +3 -0
- data/lib/evilution/mutator/operator/attr_accessor_swap.rb +2 -5
- data/lib/evilution/mutator/operator/constant_namespace_strip.rb +3 -3
- data/lib/evilution/mutator/operator/freeze_removal.rb +29 -11
- data/lib/evilution/mutator/operator/method_call_removal.rb +3 -1
- data/lib/evilution/mutator/operator/mixin_removal.rb +2 -5
- data/lib/evilution/mutator/operator/superclass_removal.rb +2 -5
- data/lib/evilution/mutator/operator/symbol_literal.rb +1 -1
- data/lib/evilution/mutator/operator/visibility_removal.rb +2 -5
- data/lib/evilution/mutator/registry.rb +11 -5
- data/lib/evilution/mutator/restore_source_cache.rb +41 -0
- data/lib/evilution/parallel/pool.rb +11 -4
- data/lib/evilution/parallel/work_queue/dispatcher/result_stream.rb +40 -0
- data/lib/evilution/parallel/work_queue/dispatcher.rb +20 -7
- data/lib/evilution/parallel/work_queue/worker/loop.rb +7 -2
- data/lib/evilution/parallel/work_queue/worker.rb +10 -3
- data/lib/evilution/parallel/work_queue/worker_stat.rb +7 -0
- data/lib/evilution/parallel/work_queue.rb +69 -12
- data/lib/evilution/parallel_db_warning.rb +39 -12
- data/lib/evilution/process_supervisor.rb +22 -2
- data/lib/evilution/reporter/cli/item_formatters/coverage_gap.rb +13 -2
- data/lib/evilution/reporter/cli/item_formatters/subject_score.rb +5 -1
- data/lib/evilution/reporter/cli/line_formatters/mutations.rb +9 -2
- data/lib/evilution/reporter/cli/line_formatters/result_line.rb +9 -1
- data/lib/evilution/reporter/cli/line_formatters/skipped_sites.rb +14 -0
- data/lib/evilution/reporter/cli/line_formatters/uncovered_code.rb +17 -0
- data/lib/evilution/reporter/cli/metrics_block.rb +4 -0
- data/lib/evilution/reporter/cli/trailer.rb +4 -4
- data/lib/evilution/reporter/cli.rb +9 -2
- data/lib/evilution/reporter/html/assets/style.css +8 -0
- data/lib/evilution/reporter/html/sections/file_section.rb +9 -0
- data/lib/evilution/reporter/html/sections/uncovered_details.rb +27 -0
- data/lib/evilution/reporter/html/templates/file_section.html.erb +2 -1
- data/lib/evilution/reporter/html/templates/summary_cards.html.erb +3 -0
- data/lib/evilution/reporter/html/templates/uncovered_details.html.erb +11 -0
- data/lib/evilution/reporter/json/mutation_detail.rb +77 -0
- data/lib/evilution/reporter/json/subjects.rb +1 -0
- data/lib/evilution/reporter/json/timings.rb +42 -0
- data/lib/evilution/reporter/json.rb +13 -50
- data/lib/evilution/result/coverage_gap.rb +5 -0
- data/lib/evilution/result/mutation_result.rb +55 -3
- data/lib/evilution/result/mutation_timings.rb +54 -0
- data/lib/evilution/result/run_timings.rb +20 -0
- data/lib/evilution/result/subject_score.rb +8 -1
- data/lib/evilution/result/subject_scorer.rb +5 -3
- data/lib/evilution/result/summary.rb +49 -12
- data/lib/evilution/runner/baseline_runner.rb +47 -5
- data/lib/evilution/runner/diagnostics.rb +0 -13
- data/lib/evilution/runner/isolation_resolver.rb +16 -4
- data/lib/evilution/runner/mutation_executor/isolated_run.rb +34 -0
- data/lib/evilution/runner/mutation_executor/kill_history.rb +66 -0
- data/lib/evilution/runner/mutation_executor/mutation_runner.rb +31 -12
- data/lib/evilution/runner/mutation_executor/neutralizer/baseline_failed.rb +1 -0
- data/lib/evilution/runner/mutation_executor/neutralizer/infra_error.rb +6 -20
- data/lib/evilution/runner/mutation_executor/probe_first.rb +99 -0
- data/lib/evilution/runner/mutation_executor/probe_first_run.rb +59 -0
- data/lib/evilution/runner/mutation_executor/result_cache.rb +45 -14
- data/lib/evilution/runner/mutation_executor/result_notifier.rb +1 -1
- data/lib/evilution/runner/mutation_executor/result_packer.rb +54 -24
- data/lib/evilution/runner/mutation_executor/runless_verdict.rb +39 -0
- data/lib/evilution/runner/mutation_executor/strategy/parallel/hinted_items.rb +27 -0
- data/lib/evilution/runner/mutation_executor/strategy/parallel/ordered_delivery.rb +97 -0
- data/lib/evilution/runner/mutation_executor/strategy/parallel.rb +102 -83
- data/lib/evilution/runner/mutation_executor/timed_run.rb +33 -0
- data/lib/evilution/runner/mutation_executor/timeout_policy/adaptive.rb +67 -0
- data/lib/evilution/runner/mutation_executor/timeout_policy/base.rb +35 -0
- data/lib/evilution/runner/mutation_executor/timeout_policy/fixed.rb +17 -0
- data/lib/evilution/runner/mutation_executor/timeout_policy.rb +56 -0
- data/lib/evilution/runner/mutation_executor.rb +75 -10
- data/lib/evilution/runner/mutation_planner.rb +29 -21
- data/lib/evilution/runner/phase_clock.rb +22 -0
- data/lib/evilution/runner/report_publisher.rb +1 -1
- data/lib/evilution/runner/subject_pipeline.rb +18 -8
- data/lib/evilution/runner.rb +87 -26
- data/lib/evilution/session/diff.rb +9 -2
- data/lib/evilution/session/store.rb +17 -2
- data/lib/evilution/source_ast_cache.rb +10 -0
- data/lib/evilution/spec_ast_cache.rb +15 -0
- data/lib/evilution/spec_resolver/constant_references.rb +66 -0
- data/lib/evilution/spec_resolver/project_files.rb +50 -0
- data/lib/evilution/spec_resolver/sibling_spec_ranker.rb +111 -0
- data/lib/evilution/spec_resolver/spec_pattern.rb +19 -0
- data/lib/evilution/spec_resolver.rb +76 -65
- data/lib/evilution/spec_selector.rb +17 -13
- data/lib/evilution/subject.rb +7 -2
- data/lib/evilution/version.rb +1 -1
- data/lib/evilution/worker_database/copies.rb +73 -0
- data/lib/evilution/worker_database/schema.rb +39 -0
- data/lib/evilution/worker_database/sqlite_copy.rb +65 -0
- data/lib/evilution/worker_database.rb +214 -0
- data/schema/evilution.config.schema.json +74 -2
- metadata +84 -13
- data/lib/evilution/integration/rspec/state_guard/object_space_example_groups.rb +0 -42
- data/scripts/benchmark_density +0 -262
- data/scripts/benchmark_density.yml +0 -19
- data/scripts/canary_manifest.yml +0 -47
- data/scripts/compare_mutations +0 -421
- data/scripts/compare_mutations.yml +0 -24
- data/scripts/compare_targeting +0 -279
- data/scripts/compare_targeting.example.yml +0 -24
- data/scripts/mutant_json_adapter +0 -227
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../loading"
|
|
4
|
+
|
|
5
|
+
# The modules extended with ActiveSupport::Concern, for ConcernStateCleaner to
|
|
6
|
+
# look through before every evaluation of a mutated or restored file.
|
|
7
|
+
#
|
|
8
|
+
# Finding them by walking ObjectSpace on every evaluation visited every object
|
|
9
|
+
# in the process. Here the heap is walked once, the first time the registry is
|
|
10
|
+
# asked, for the concerns that already exist; the ones defined afterwards are
|
|
11
|
+
# recorded as they extend themselves, through a hook on the concern module's
|
|
12
|
+
# own `extended`. The registry is shared by the process, so a run that asks
|
|
13
|
+
# once in the parent (see ConcernStateCleaner#warm) leaves every forked
|
|
14
|
+
# mutation process a filled copy and no walk to make.
|
|
15
|
+
#
|
|
16
|
+
# The hook is one module for every registry, prepended at most once: a
|
|
17
|
+
# prepended module cannot be taken off, so one per registry would stay on the
|
|
18
|
+
# concern module for the life of the process, each run by every `extend`.
|
|
19
|
+
#
|
|
20
|
+
# Only modules that extend themselves with the concern module are recorded
|
|
21
|
+
# after the walk. A module extended with another module that includes it, or
|
|
22
|
+
# a `clone` of a concern, answers `concern === mod` without passing through
|
|
23
|
+
# `extended`, and is not listed. Neither can be given an `included` block of
|
|
24
|
+
# its own by a file that loads: the first is never set up to be included
|
|
25
|
+
# (ActiveSupport leaves its dependencies unset), and the second already holds
|
|
26
|
+
# the block of the concern it was cloned from.
|
|
27
|
+
#
|
|
28
|
+
# A module that is no longer referenced is not kept alive by being listed:
|
|
29
|
+
# a mutation that re-creates a concern leaves the old module to the garbage
|
|
30
|
+
# collector.
|
|
31
|
+
#
|
|
32
|
+
# No message is sent to the modules walked or recorded. ObjectSpace yields
|
|
33
|
+
# modules that answer messages in their own way, such as ActiveSupport's
|
|
34
|
+
# DeprecatedConstantProxy, which turns any of them into a deprecation that a
|
|
35
|
+
# project may have set to raise. `concern === mod` is answered by the concern
|
|
36
|
+
# module, and the record is keyed by identity.
|
|
37
|
+
class Evilution::Integration::Loading::ConcernRegistry
|
|
38
|
+
# The registries that have tracked a concern module; weakly held, so that
|
|
39
|
+
# one dropped by its owner is not kept alive by the hook.
|
|
40
|
+
@tracking = ObjectSpace::WeakMap.new
|
|
41
|
+
|
|
42
|
+
def self.default
|
|
43
|
+
@default ||= new
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Called by the hook in a concern module's `extended`.
|
|
47
|
+
def self.extended_with(concern, base)
|
|
48
|
+
@tracking.each_key { |registry| registry.record(concern, base) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.track(registry, concern)
|
|
52
|
+
@tracking[registry] = true
|
|
53
|
+
# Prepending a module the singleton class already has is a no-op.
|
|
54
|
+
concern.singleton_class.prepend(Hook)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
module Hook
|
|
58
|
+
def extended(base)
|
|
59
|
+
Evilution::Integration::Loading::ConcernRegistry.extended_with(self, base)
|
|
60
|
+
super
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# The modules extended with `concern`, the ActiveSupport::Concern module of
|
|
65
|
+
# the process. A different module than the one asked about last (a project
|
|
66
|
+
# whose ActiveSupport was loaded again) starts the record over.
|
|
67
|
+
def concerns(concern)
|
|
68
|
+
track(concern) unless concern.equal?(@concern)
|
|
69
|
+
@modules.keys
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Called for every registry when a module extends itself with `concern`,
|
|
73
|
+
# whichever concern module the registry tracks. Nothing is recorded before
|
|
74
|
+
# the first #concerns: the walk made then finds what was extended until it.
|
|
75
|
+
def record(concern, base)
|
|
76
|
+
@modules[base] = true if concern.equal?(@concern)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
private
|
|
80
|
+
|
|
81
|
+
def track(concern)
|
|
82
|
+
@concern = concern
|
|
83
|
+
@modules = ObjectSpace::WeakMap.new
|
|
84
|
+
self.class.track(self, concern)
|
|
85
|
+
ObjectSpace.each_object(Module) { |mod| @modules[mod] = true if concern === mod } # rubocop:disable Style/CaseEquality
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../loading"
|
|
4
4
|
require_relative "../../load_path/subpath_resolver"
|
|
5
|
+
require_relative "concern_registry"
|
|
5
6
|
|
|
6
7
|
# Re-evaluating an `ActiveSupport::Concern` module raises
|
|
7
8
|
# "MultipleIncludedBlocks" because AS::Concern records the block source
|
|
8
9
|
# location on the first include/prepend call. Before a re-eval we clear the
|
|
9
10
|
# `@_included_block` / `@_prepended_block` ivar on modules whose block came
|
|
10
11
|
# from the file we're about to re-eval.
|
|
12
|
+
#
|
|
13
|
+
# The concern modules come from a ConcernRegistry, which walks the heap once
|
|
14
|
+
# for the process rather than once per evaluation.
|
|
11
15
|
class Evilution::Integration::Loading::ConcernStateCleaner
|
|
12
16
|
IVARS = %i[@_included_block @_prepended_block].freeze
|
|
13
17
|
|
|
14
|
-
#
|
|
15
|
-
# message honestly. ActiveSupport::Deprecation::DeprecatedConstantProxy
|
|
18
|
+
# The registry's first lookup walks every Module in the VM, including ones
|
|
19
|
+
# that answer no message honestly. ActiveSupport::Deprecation::DeprecatedConstantProxy
|
|
16
20
|
# subclasses Module and undefines all of its instance methods, so asking it
|
|
17
21
|
# anything lands in its method_missing and emits the deprecation; where the
|
|
18
22
|
# deprecator's behaviour is :raise (grape's spec_helper sets that), the
|
|
@@ -31,8 +35,19 @@ class Evilution::Integration::Loading::ConcernStateCleaner
|
|
|
31
35
|
REMOVE_IVAR = Object.instance_method(:remove_instance_variable)
|
|
32
36
|
private_constant :IVAR_DEFINED, :IVAR_GET, :REMOVE_IVAR
|
|
33
37
|
|
|
34
|
-
def initialize(subpath_resolver: Evilution::LoadPath::SubpathResolver.new
|
|
38
|
+
def initialize(subpath_resolver: Evilution::LoadPath::SubpathResolver.new,
|
|
39
|
+
registry: Evilution::Integration::Loading::ConcernRegistry.default)
|
|
35
40
|
@subpath_resolver = subpath_resolver
|
|
41
|
+
@registry = registry
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Fills the registry ahead of the first evaluation. Called in the parent of
|
|
45
|
+
# a run, so that a forked mutation process inherits it filled.
|
|
46
|
+
def warm
|
|
47
|
+
return unless defined?(ActiveSupport::Concern)
|
|
48
|
+
|
|
49
|
+
@registry.concerns(ActiveSupport::Concern)
|
|
50
|
+
nil
|
|
36
51
|
end
|
|
37
52
|
|
|
38
53
|
def call(file_path)
|
|
@@ -44,11 +59,7 @@ class Evilution::Integration::Loading::ConcernStateCleaner
|
|
|
44
59
|
absolute = File.expand_path(file_path, Evilution.project_base_dir)
|
|
45
60
|
subpath = @subpath_resolver.call(absolute)
|
|
46
61
|
|
|
47
|
-
|
|
48
|
-
next unless ActiveSupport::Concern === mod # rubocop:disable Style/CaseEquality
|
|
49
|
-
|
|
50
|
-
clear_concern_ivars(mod, absolute, subpath)
|
|
51
|
-
end
|
|
62
|
+
@registry.concerns(ActiveSupport::Concern).each { |mod| clear_concern_ivars(mod, absolute, subpath) }
|
|
52
63
|
end
|
|
53
64
|
|
|
54
65
|
private
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../loading"
|
|
4
|
+
|
|
5
|
+
# Sees the modules created while a block runs, as they are created.
|
|
6
|
+
#
|
|
7
|
+
# SupersededModules needs the modules an evaluation of a file created. Taking
|
|
8
|
+
# them as the difference between two walks of ObjectSpace, before and after,
|
|
9
|
+
# visited every object in the process twice per evaluation, and an in-process
|
|
10
|
+
# run evaluates every file twice per mutation (the mutation, then the
|
|
11
|
+
# restore). Here Module#initialize is hooked instead, once for the process,
|
|
12
|
+
# when the first block is run: `Module.new` passes through it, with or
|
|
13
|
+
# without a body. A copy made by `dup` or `clone` never runs initialize, so
|
|
14
|
+
# Module#initialize_copy is hooked as well. Nothing is recorded while no
|
|
15
|
+
# block runs.
|
|
16
|
+
#
|
|
17
|
+
# Every module whose initialize runs is added, whatever its class, and
|
|
18
|
+
# whether or not its body raised; telling them apart is the caller's
|
|
19
|
+
# business. A module created in another thread while the block runs is added
|
|
20
|
+
# too, as the walk would have found it.
|
|
21
|
+
module Evilution::Integration::Loading::CreatedModules
|
|
22
|
+
@lists = [].freeze
|
|
23
|
+
|
|
24
|
+
# Runs the block, adding to `list` each module created while it runs;
|
|
25
|
+
# returns the block's value.
|
|
26
|
+
def self.into(list)
|
|
27
|
+
# Prepending a module Module already has is a no-op.
|
|
28
|
+
::Module.prepend(Hook)
|
|
29
|
+
@lists = [*@lists, list].freeze
|
|
30
|
+
yield
|
|
31
|
+
ensure
|
|
32
|
+
@lists = @lists.reject { |open| open.equal?(list) }.freeze
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.record(mod)
|
|
36
|
+
@lists.each { |list| list << mod }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
module Hook
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
# Recorded before the body runs, so that a module whose body raises is
|
|
43
|
+
# recorded all the same.
|
|
44
|
+
def initialize(*, **, &)
|
|
45
|
+
Evilution::Integration::Loading::CreatedModules.record(self)
|
|
46
|
+
super
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# A copy holds the methods of its original, written in the original's
|
|
50
|
+
# file, and is a module of its own to empty like any other.
|
|
51
|
+
def initialize_copy(original)
|
|
52
|
+
Evilution::Integration::Loading::CreatedModules.record(self)
|
|
53
|
+
super
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../loading"
|
|
4
|
+
|
|
5
|
+
# The classes and modules a file declares, as they stood before a mutant of the
|
|
6
|
+
# file was applied, and a way past a mutant that froze one of them.
|
|
7
|
+
#
|
|
8
|
+
# A mutant can freeze a class its own file declares: `List.freeze` in place of
|
|
9
|
+
# `List.new([].freeze).freeze`. The rest of the class body then raises
|
|
10
|
+
# FrozenError, and so does the original evaluated after it to tell whether the
|
|
11
|
+
# mutant broke the load, since it reopens the class the mutant froze. Ruby
|
|
12
|
+
# cannot thaw an object, so the frozen class is set aside for that check
|
|
13
|
+
# alone: its constant is removed and the original defines the class afresh,
|
|
14
|
+
# then the frozen class is put back. The fresh class has only what this file
|
|
15
|
+
# defines, and nothing else refers to it: other files may reopen the class or
|
|
16
|
+
# include the module, and those still hold the frozen one. Keeping the fresh
|
|
17
|
+
# class would judge the mutants after this one against a class the rest of the
|
|
18
|
+
# program does not use. Put back, the class stays frozen in this process, and
|
|
19
|
+
# those mutants cannot be judged here at all; a forked mutant process never
|
|
20
|
+
# sees the freeze.
|
|
21
|
+
#
|
|
22
|
+
# Only a class or module the file declares is set aside, and only one that was
|
|
23
|
+
# not frozen before the mutant was applied: a file that freezes its own class
|
|
24
|
+
# as it loads cannot be evaluated again, mutated or not, and that failure
|
|
25
|
+
# stands.
|
|
26
|
+
class Evilution::Integration::Loading::FrozenNamespaces
|
|
27
|
+
# Of the given names, those a mutant may yet freeze: the ones that are not a
|
|
28
|
+
# frozen class or module now.
|
|
29
|
+
def self.taken(names)
|
|
30
|
+
new(names.reject { |name| frozen_namespace?(name) })
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.frozen_namespace?(name)
|
|
34
|
+
Object.const_defined?(name, false) && Object.const_get(name).frozen?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def initialize(unfrozen)
|
|
38
|
+
@unfrozen = unfrozen
|
|
39
|
+
freeze
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
NONE = new([])
|
|
43
|
+
|
|
44
|
+
# Runs the block. When it raises FrozenError on a class the mutant froze,
|
|
45
|
+
# runs the block once more with that class's constant removed, then puts the
|
|
46
|
+
# frozen class back.
|
|
47
|
+
def recover(&)
|
|
48
|
+
yield
|
|
49
|
+
rescue FrozenError => e
|
|
50
|
+
name = frozen_since_taken(e)
|
|
51
|
+
raise unless name
|
|
52
|
+
|
|
53
|
+
put_aside(name, &)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# A FrozenError raised by hand need not name what is frozen: asking it for
|
|
59
|
+
# its receiver then raises ArgumentError.
|
|
60
|
+
def frozen_since_taken(error)
|
|
61
|
+
receiver = error.receiver
|
|
62
|
+
@unfrozen.find { |name| Object.const_defined?(name, false) && Object.const_get(name).equal?(receiver) }
|
|
63
|
+
rescue ArgumentError
|
|
64
|
+
nil
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Whatever the block defined under the name is dropped: removing it first
|
|
68
|
+
# spares the warning about a constant set twice.
|
|
69
|
+
def put_aside(name)
|
|
70
|
+
parent_name, _, local_name = name.rpartition("::")
|
|
71
|
+
parent = parent_name.empty? ? Object : Object.const_get(parent_name)
|
|
72
|
+
frozen = parent.send(:remove_const, local_name)
|
|
73
|
+
begin
|
|
74
|
+
yield
|
|
75
|
+
ensure
|
|
76
|
+
parent.send(:remove_const, local_name) if parent.const_defined?(local_name, false)
|
|
77
|
+
parent.const_set(local_name, frozen)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -6,6 +6,7 @@ require_relative "constant_pinner"
|
|
|
6
6
|
require_relative "concern_state_cleaner"
|
|
7
7
|
require_relative "source_evaluator"
|
|
8
8
|
require_relative "redefinition_recovery"
|
|
9
|
+
require_relative "frozen_namespaces"
|
|
9
10
|
require_relative "../../diagnostic"
|
|
10
11
|
|
|
11
12
|
# Composes the load-time pipeline that applies a mutation's new source to the
|
|
@@ -27,7 +28,12 @@ require_relative "../../diagnostic"
|
|
|
27
28
|
# as one that crashes a test is. When the original fails too, or there is none
|
|
28
29
|
# to compare with, the failure says nothing about the mutant and stays an
|
|
29
30
|
# error. A syntax error is never the mutant's doing in that sense: it means
|
|
30
|
-
# the mutation was not valid Ruby to begin with.
|
|
31
|
+
# the mutation was not valid Ruby to begin with. A mutant that froze a class
|
|
32
|
+
# its file declares would make the original fail as well, on the class it
|
|
33
|
+
# froze; for that check alone the frozen class is set aside and the original
|
|
34
|
+
# defines the class afresh (FrozenNamespaces), then the frozen class is put
|
|
35
|
+
# back. The fresh class has only what this file defines, so the check tells
|
|
36
|
+
# whether this file's original loads, not whether the whole class works.
|
|
31
37
|
class Evilution::Integration::Loading::MutationApplier
|
|
32
38
|
def initialize(syntax_validator: Evilution::Integration::Loading::SyntaxValidator.new,
|
|
33
39
|
constant_pinner: Evilution::Integration::Loading::ConstantPinner.new,
|
|
@@ -42,16 +48,26 @@ class Evilution::Integration::Loading::MutationApplier
|
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
def call(mutation)
|
|
51
|
+
namespaces = Evilution::Integration::Loading::FrozenNamespaces::NONE
|
|
45
52
|
eval_target = resolve_eval_target(mutation)
|
|
46
53
|
syntax_error = @syntax_validator.call(eval_target)
|
|
47
54
|
return syntax_error if syntax_error
|
|
48
55
|
|
|
56
|
+
namespaces = Evilution::Integration::Loading::FrozenNamespaces.taken(@constant_pinner.call(mutation.original_source))
|
|
49
57
|
apply(mutation, eval_target)
|
|
50
58
|
nil
|
|
51
59
|
rescue SyntaxError => e
|
|
52
60
|
failure_result(e, "syntax error in mutated source: #{e.message}")
|
|
53
61
|
rescue ScriptError, StandardError => e
|
|
54
|
-
load_failure_result(mutation, e)
|
|
62
|
+
load_failure_result(mutation, e, namespaces)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Fills, ahead of the first mutation, what applying one looks up on the
|
|
66
|
+
# heap. Called in the parent of a run, so a forked mutation process
|
|
67
|
+
# inherits it rather than walking its own copy of the heap.
|
|
68
|
+
def warm
|
|
69
|
+
@concern_state_cleaner.warm
|
|
70
|
+
nil
|
|
55
71
|
end
|
|
56
72
|
|
|
57
73
|
# Evaluates the mutation's restore_source: the original file. Runs after the
|
|
@@ -60,32 +76,48 @@ class Evilution::Integration::Loading::MutationApplier
|
|
|
60
76
|
# applying: a concern ignores an `included` block handed to it twice from
|
|
61
77
|
# the same place, and would keep the mutated one.
|
|
62
78
|
def restore(mutation)
|
|
63
|
-
evaluate_original(mutation)
|
|
79
|
+
evaluate_original(mutation, swallow_idempotency: true)
|
|
64
80
|
rescue ScriptError, StandardError => e
|
|
65
81
|
Evilution::Diagnostic.warn("[evilution] could not restore #{mutation.file_path}: #{e.class}: #{e.message}")
|
|
66
82
|
end
|
|
67
83
|
|
|
68
84
|
private
|
|
69
85
|
|
|
70
|
-
# Whether there was an original to evaluate.
|
|
71
|
-
|
|
86
|
+
# Whether there was an original to evaluate. The original goes over the
|
|
87
|
+
# classes the file loaded before, so a class-body DSL that rejects being
|
|
88
|
+
# declared twice (ActiveRecord's `enum`) raises on it as it does on the
|
|
89
|
+
# mutated source, and is recovered from the same way: the file's constants
|
|
90
|
+
# are removed and its classes defined afresh. Whatever still holds the old
|
|
91
|
+
# class objects (subclasses defined in other files, association
|
|
92
|
+
# reflections, caches keyed by class) keeps holding them; the mutated load
|
|
93
|
+
# replaces them the same way.
|
|
94
|
+
#
|
|
95
|
+
# Restoring may swallow a registry's refusal of a second registration and
|
|
96
|
+
# keep what the class body defined up to it. Checking that the original
|
|
97
|
+
# loads may not: the class body stopped there, so nothing after it was
|
|
98
|
+
# evaluated, and the original is not known to load.
|
|
99
|
+
def evaluate_original(mutation, swallow_idempotency:)
|
|
72
100
|
source = mutation.respond_to?(:restore_source) ? mutation.restore_source : nil
|
|
73
101
|
return false unless source
|
|
74
102
|
|
|
75
103
|
@concern_state_cleaner.call(mutation.file_path)
|
|
76
|
-
@
|
|
104
|
+
@redefinition_recovery.call(source, swallow_idempotency: swallow_idempotency) do
|
|
105
|
+
@source_evaluator.call(source, mutation.file_path)
|
|
106
|
+
end
|
|
77
107
|
true
|
|
78
108
|
end
|
|
79
109
|
|
|
80
|
-
|
|
81
|
-
|
|
110
|
+
# `namespaces` are the file's classes as they were before the mutant was
|
|
111
|
+
# applied, so that one the mutant froze can be set aside.
|
|
112
|
+
def original_loads?(mutation, namespaces)
|
|
113
|
+
namespaces.recover { evaluate_original(mutation, swallow_idempotency: false) }
|
|
82
114
|
rescue ScriptError, StandardError
|
|
83
115
|
false
|
|
84
116
|
end
|
|
85
117
|
|
|
86
|
-
def load_failure_result(mutation, error)
|
|
118
|
+
def load_failure_result(mutation, error, namespaces)
|
|
87
119
|
message = "#{error.class}: #{error.message}"
|
|
88
|
-
return failure_result(error, message) unless original_loads?(mutation)
|
|
120
|
+
return failure_result(error, message) unless original_loads?(mutation, namespaces)
|
|
89
121
|
|
|
90
122
|
failure_result(error, "load failed: #{message}").merge(load_crashed: true)
|
|
91
123
|
end
|
|
@@ -97,7 +129,6 @@ class Evilution::Integration::Loading::MutationApplier
|
|
|
97
129
|
end
|
|
98
130
|
|
|
99
131
|
def apply(mutation, eval_target)
|
|
100
|
-
@constant_pinner.call(mutation.original_source)
|
|
101
132
|
@concern_state_cleaner.call(mutation.file_path)
|
|
102
133
|
mark_feature_loaded(mutation.file_path)
|
|
103
134
|
@redefinition_recovery.call(mutation.original_source) do
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../loading"
|
|
4
|
+
require_relative "../../ast/source_surgeon"
|
|
5
|
+
|
|
6
|
+
# A file's source with its class-body calls neutralized (see
|
|
7
|
+
# BodyCallNeutralizer), and the edits that made it from the file:
|
|
8
|
+
# [start offset, end offset, replacement], in order.
|
|
9
|
+
#
|
|
10
|
+
# A mutation made where no edit is changes nothing the edits depend on as
|
|
11
|
+
# long as it adds no class body of its own, which the caller checks: the
|
|
12
|
+
# mutated file then neutralizes to this source with the mutation spliced in,
|
|
13
|
+
# and #carry builds that without parsing the mutated file.
|
|
14
|
+
class Evilution::Integration::Loading::Neutralization
|
|
15
|
+
attr_reader :source, :edits
|
|
16
|
+
|
|
17
|
+
# edits: nil when the file could not be neutralized, so nothing can be
|
|
18
|
+
# carried into it.
|
|
19
|
+
def initialize(source:, edits:)
|
|
20
|
+
@source = source
|
|
21
|
+
@edits = edits
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# The neutralized mutated file, for a mutation made inside span (a range
|
|
26
|
+
# of offsets in the file), or nil when an edit touches the span.
|
|
27
|
+
def carry(span, offset:, length:, replacement:, mutated:)
|
|
28
|
+
return if @edits.nil? || @edits.any? { |from, to, _| from <= span.end && to >= span.begin }
|
|
29
|
+
return mutated if @edits.empty?
|
|
30
|
+
|
|
31
|
+
Evilution::AST::SourceSurgeon.splice(@source, offset: offset + shift_before(span.begin), length: length,
|
|
32
|
+
replacement: replacement)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
# How far the edits before an offset move it in the neutralized source.
|
|
38
|
+
def shift_before(offset)
|
|
39
|
+
@edits.sum { |from, to, replacement| to < offset ? replacement.bytesize - (to - from) : 0 }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -14,7 +14,9 @@ require_relative "../../ast/constant_names"
|
|
|
14
14
|
# registry call are already in place — and any state change blocked by the
|
|
15
15
|
# guard was intentional duplicate-prevention from the gem's side. Mutations
|
|
16
16
|
# that target a def *after* such a class-body call would not be applied;
|
|
17
|
-
# emit a one-shot warning so that mode is visible.
|
|
17
|
+
# emit a one-shot warning so that mode is visible. A caller that must know
|
|
18
|
+
# the whole source evaluated passes `swallow_idempotency: false` and gets the
|
|
19
|
+
# violation raised instead.
|
|
18
20
|
class Evilution::Integration::Loading::RedefinitionRecovery
|
|
19
21
|
IDEMPOTENCY_PATTERNS = [
|
|
20
22
|
"already registered",
|
|
@@ -27,13 +29,13 @@ class Evilution::Integration::Loading::RedefinitionRecovery
|
|
|
27
29
|
@warned_messages = Set.new
|
|
28
30
|
end
|
|
29
31
|
|
|
30
|
-
def call(source, &block)
|
|
32
|
+
def call(source, swallow_idempotency: true, &block)
|
|
31
33
|
block.call
|
|
32
34
|
rescue ArgumentError => e
|
|
33
35
|
if redefinition_conflict?(e)
|
|
34
36
|
remove_defined_constants(source)
|
|
35
37
|
block.call
|
|
36
|
-
elsif idempotency_violation?(e)
|
|
38
|
+
elsif swallow_idempotency && idempotency_violation?(e)
|
|
37
39
|
warn_once_for(e)
|
|
38
40
|
nil
|
|
39
41
|
else
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "../loading"
|
|
4
|
+
require_relative "created_modules"
|
|
4
5
|
|
|
5
6
|
# Empties the anonymous modules an earlier evaluation of a file left behind.
|
|
6
7
|
#
|
|
@@ -20,7 +21,8 @@ require_relative "../loading"
|
|
|
20
21
|
# A module cannot be taken off, but its methods can be removed, and method
|
|
21
22
|
# lookup passes through a module that has none. So the modules created while a
|
|
22
23
|
# file is evaluated are remembered, and emptied when the same file is evaluated
|
|
23
|
-
# next.
|
|
24
|
+
# next. They are seen being created (CreatedModules), not looked for on the
|
|
25
|
+
# heap before and after the evaluation.
|
|
24
26
|
#
|
|
25
27
|
# Two limits keep this to what the new evaluation really replaces. Only
|
|
26
28
|
# modules are emptied, not anonymous classes, whose instances may be held
|
|
@@ -50,25 +52,24 @@ class Evilution::Integration::Loading::SupersededModules
|
|
|
50
52
|
# whether or not it completes.
|
|
51
53
|
#
|
|
52
54
|
# A fork child holds one mutation and ends with it, so there is nothing for
|
|
53
|
-
# it to empty later
|
|
54
|
-
|
|
55
|
-
def track(file_path)
|
|
55
|
+
# it to empty later. It evaluates and no more.
|
|
56
|
+
def track(file_path, &)
|
|
56
57
|
return yield if Evilution.single_mutation_process?
|
|
57
58
|
|
|
58
59
|
retire(file_path)
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
created = []
|
|
61
|
+
Evilution::Integration::Loading::CreatedModules.into(created, &)
|
|
61
62
|
ensure
|
|
62
|
-
remember(file_path,
|
|
63
|
+
remember(file_path, created) if created
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
private
|
|
66
67
|
|
|
67
68
|
# Nothing is kept for a file whose evaluation created none, which is most
|
|
68
69
|
# files: an entry is only worth carrying when there is a module to empty.
|
|
69
|
-
def remember(file_path,
|
|
70
|
-
|
|
71
|
-
@registry[file_path] =
|
|
70
|
+
def remember(file_path, created)
|
|
71
|
+
anonymous = anonymous_modules(created)
|
|
72
|
+
@registry[file_path] = anonymous unless anonymous.empty?
|
|
72
73
|
end
|
|
73
74
|
|
|
74
75
|
def retire(file_path)
|
|
@@ -87,17 +88,19 @@ class Evilution::Integration::Loading::SupersededModules
|
|
|
87
88
|
!location.nil? && location.first == file_path
|
|
88
89
|
end
|
|
89
90
|
|
|
90
|
-
#
|
|
91
|
-
#
|
|
92
|
-
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
|
|
91
|
+
# Plain modules only, and only the ones still without a name once the
|
|
92
|
+
# evaluation is over: one assigned to a constant is the file's to keep.
|
|
93
|
+
#
|
|
94
|
+
# No message is sent to the modules created. Some answer messages in their
|
|
95
|
+
# own way: a class may define `name`, `hash` or `==` for itself, and
|
|
96
|
+
# ActiveSupport's DeprecatedConstantProxy, a Module subclass, turns any
|
|
97
|
+
# message into a deprecation, which a project may have set to raise. Hence
|
|
98
|
+
# the identity keys and the methods bound from Module and Kernel.
|
|
99
|
+
def anonymous_modules(created)
|
|
97
100
|
found = {}.compare_by_identity
|
|
98
|
-
|
|
101
|
+
created.each do |mod|
|
|
99
102
|
found[mod] = true if INSTANCE_OF.bind_call(mod, Module) && MODULE_NAME.bind_call(mod).nil?
|
|
100
103
|
end
|
|
101
|
-
found
|
|
104
|
+
found.keys
|
|
102
105
|
end
|
|
103
106
|
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../minitest"
|
|
4
|
+
require_relative "../stop_policy"
|
|
5
|
+
|
|
6
|
+
# Ends a mutation's Minitest run at its first decisive failure.
|
|
7
|
+
#
|
|
8
|
+
# Minitest has no switch to stop a run, so the hook sits in front of the
|
|
9
|
+
# method that runs one test and lets no further test start once the run's
|
|
10
|
+
# policy has stopped: the skipped tests are neither run nor recorded.
|
|
11
|
+
#
|
|
12
|
+
# The hook is installed for the whole process and asks whatever policy is set
|
|
13
|
+
# when each test starts. Only a mutation's own run sets one; between runs, and
|
|
14
|
+
# for the baseline and the canary, the policy is DISABLED and every test runs.
|
|
15
|
+
#
|
|
16
|
+
# Classes that call parallelize_me! are never stopped early: the run (6.x) or
|
|
17
|
+
# run_one_method (5.x) override they extend from
|
|
18
|
+
# Minitest::Parallel::Test::ClassMethods sits ahead of the hook and does not
|
|
19
|
+
# call super, so their tests all run, as they would without stop_on_kill.
|
|
20
|
+
module Evilution::Integration::Minitest::StopHook
|
|
21
|
+
# Minitest 6 runs each test through Runnable.run(klass, method_name, reporter).
|
|
22
|
+
module Run
|
|
23
|
+
def run(klass, method_name, reporter)
|
|
24
|
+
return if Evilution::Integration::Minitest::StopHook.policy.stopped?
|
|
25
|
+
|
|
26
|
+
super
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Minitest 5 runs each test through run_one_method; its Runnable.run is the
|
|
31
|
+
# suite runner.
|
|
32
|
+
module RunOneMethod
|
|
33
|
+
def run_one_method(klass, method_name, reporter)
|
|
34
|
+
return if Evilution::Integration::Minitest::StopHook.policy.stopped?
|
|
35
|
+
|
|
36
|
+
super
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
@policy = Evilution::Integration::StopPolicy::DISABLED
|
|
41
|
+
|
|
42
|
+
class << self
|
|
43
|
+
# The current run's policy; DISABLED when no mutation run is under way.
|
|
44
|
+
attr_accessor :policy
|
|
45
|
+
|
|
46
|
+
def install!
|
|
47
|
+
runnable = ::Minitest::Runnable.singleton_class
|
|
48
|
+
runnable.prepend(hook) unless runnable.include?(hook)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Minitest 6 is told apart by Runnable.run_suite, the suite runner it
|
|
52
|
+
# split off from Runnable.run.
|
|
53
|
+
def hook
|
|
54
|
+
::Minitest::Runnable.respond_to?(:run_suite) ? Run : RunOneMethod
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -5,6 +5,7 @@ require_relative "base"
|
|
|
5
5
|
require_relative "../diagnostic"
|
|
6
6
|
require_relative "minitest_crash_detector"
|
|
7
7
|
require_relative "known_failures"
|
|
8
|
+
require_relative "stop_policy"
|
|
8
9
|
require_relative "loading/test_load_path"
|
|
9
10
|
require_relative "loading/test_class_cache"
|
|
10
11
|
require_relative "../spec_resolver"
|
|
@@ -112,9 +113,11 @@ class Evilution::Integration::Minitest < Evilution::Integration::Base
|
|
|
112
113
|
end
|
|
113
114
|
|
|
114
115
|
# known_failures: the ids of the tests the baseline saw failing (see TestIds).
|
|
115
|
-
def initialize(test_files: nil, hooks: nil, fallback_to_full_suite: false, spec_selector: nil, known_failures: []
|
|
116
|
+
def initialize(test_files: nil, hooks: nil, fallback_to_full_suite: false, spec_selector: nil, known_failures: [],
|
|
117
|
+
stop_on_kill: false)
|
|
116
118
|
@test_files = test_files
|
|
117
119
|
@known_failures = Evilution::Integration::KnownFailures.new(known_failures)
|
|
120
|
+
@stop_policy = Evilution::Integration::StopPolicy.new(enabled: stop_on_kill, known_failures: @known_failures)
|
|
118
121
|
@minitest_loaded = false
|
|
119
122
|
@spec_selector = spec_selector || Evilution::SpecSelector.new(
|
|
120
123
|
spec_resolver: Evilution::SpecResolver.new(test_dir: "test", test_suffix: "_test.rb", request_dir: "integration")
|
|
@@ -156,7 +159,7 @@ class Evilution::Integration::Minitest < Evilution::Integration::Base
|
|
|
156
159
|
load_test_classes(files)
|
|
157
160
|
|
|
158
161
|
detector = reset_crash_detector
|
|
159
|
-
run = run_minitest(build_args(mutation), detector)
|
|
162
|
+
run = with_stop_policy { run_minitest(build_args(mutation), detector) }
|
|
160
163
|
|
|
161
164
|
return no_tests_ran_result(command) if run[:count].zero?
|
|
162
165
|
# Before the crash check: a test that was already failing may fail by
|
|
@@ -272,10 +275,24 @@ class Evilution::Integration::Minitest < Evilution::Integration::Base
|
|
|
272
275
|
@crash_detector.reset
|
|
273
276
|
else
|
|
274
277
|
@crash_detector = Evilution::Integration::MinitestCrashDetector.new
|
|
278
|
+
@crash_detector.policy = @stop_policy
|
|
275
279
|
end
|
|
276
280
|
@crash_detector
|
|
277
281
|
end
|
|
278
282
|
|
|
283
|
+
# Hands the stop hook this run's policy, reset: one latched by the previous
|
|
284
|
+
# run would skip every test of this one. Taken back after the run, so that
|
|
285
|
+
# whatever runs Minitest next -- the baseline, another integration -- runs
|
|
286
|
+
# every test.
|
|
287
|
+
def with_stop_policy
|
|
288
|
+
@stop_policy.reset
|
|
289
|
+
StopHook.install!
|
|
290
|
+
StopHook.policy = @stop_policy
|
|
291
|
+
yield
|
|
292
|
+
ensure
|
|
293
|
+
StopHook.policy = Evilution::Integration::StopPolicy::DISABLED
|
|
294
|
+
end
|
|
295
|
+
|
|
279
296
|
def build_minitest_result(passed, command, detector)
|
|
280
297
|
if passed
|
|
281
298
|
{ passed: true, test_command: command }
|
|
@@ -331,4 +348,7 @@ class Evilution::Integration::Minitest < Evilution::Integration::Base
|
|
|
331
348
|
end
|
|
332
349
|
end
|
|
333
350
|
|
|
351
|
+
# Loaded once the class is defined, as both nest under it. The crash detector
|
|
352
|
+
# names failures by TestIds and leaves loading them to this file.
|
|
334
353
|
require_relative "minitest/test_ids"
|
|
354
|
+
require_relative "minitest/stop_hook"
|