Class: Evilution::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/config.rb

Constant Summary collapse

CONFIG_FILES =
%w[.evilution.yml config/evilution.yml].freeze
DEFAULTS =
{
  timeout: 30,
  format: :text,
  target: nil,
  min_score: 0.0,
  integration: :rspec,
  verbose: false,
  quiet: false,
  jobs: 1,
  fail_fast: nil,
  baseline: true,
  isolation: :auto,
  incremental: false,
  suggest_tests: false,
  progress: true,
  save_session: false,
  line_ranges: {},
  spec_files: [],
  ignore_patterns: [],
  show_disabled: false,
  baseline_session: nil,
  skip_heredoc_literals: false,
  related_specs_heuristic: false,
  fallback_to_full_suite: false,
  preload: nil
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Config

Returns a new instance of Config.



43
44
45
46
47
48
# File 'lib/evilution/config.rb', line 43

def initialize(**options)
  file_options = options.delete(:skip_config_file) ? {} : load_config_file
  merged = DEFAULTS.merge(file_options).merge(options)
  assign_attributes(merged)
  freeze
end

Instance Attribute Details

#baselineObject (readonly)

Returns the value of attribute baseline.



35
36
37
# File 'lib/evilution/config.rb', line 35

def baseline
  @baseline
end

#baseline_sessionObject (readonly)

Returns the value of attribute baseline_session.



35
36
37
# File 'lib/evilution/config.rb', line 35

def baseline_session
  @baseline_session
end

#fail_fastObject (readonly)

Returns the value of attribute fail_fast.



35
36
37
# File 'lib/evilution/config.rb', line 35

def fail_fast
  @fail_fast
end

#fallback_to_full_suiteObject (readonly)

Returns the value of attribute fallback_to_full_suite.



35
36
37
# File 'lib/evilution/config.rb', line 35

def fallback_to_full_suite
  @fallback_to_full_suite
end

#formatObject (readonly)

Returns the value of attribute format.



35
36
37
# File 'lib/evilution/config.rb', line 35

def format
  @format
end

#hooksObject (readonly)

Returns the value of attribute hooks.



35
36
37
# File 'lib/evilution/config.rb', line 35

def hooks
  @hooks
end

#ignore_patternsObject (readonly)

Returns the value of attribute ignore_patterns.



35
36
37
# File 'lib/evilution/config.rb', line 35

def ignore_patterns
  @ignore_patterns
end

#incrementalObject (readonly)

Returns the value of attribute incremental.



35
36
37
# File 'lib/evilution/config.rb', line 35

def incremental
  @incremental
end

#integrationObject (readonly)

Returns the value of attribute integration.



35
36
37
# File 'lib/evilution/config.rb', line 35

def integration
  @integration
end

#isolationObject (readonly)

Returns the value of attribute isolation.



35
36
37
# File 'lib/evilution/config.rb', line 35

def isolation
  @isolation
end

#jobsObject (readonly)

Returns the value of attribute jobs.



35
36
37
# File 'lib/evilution/config.rb', line 35

def jobs
  @jobs
end

#line_rangesObject (readonly)

Returns the value of attribute line_ranges.



35
36
37
# File 'lib/evilution/config.rb', line 35

def line_ranges
  @line_ranges
end

#min_scoreObject (readonly)

Returns the value of attribute min_score.



35
36
37
# File 'lib/evilution/config.rb', line 35

def min_score
  @min_score
end

#preloadObject (readonly)

Returns the value of attribute preload.



35
36
37
# File 'lib/evilution/config.rb', line 35

def preload
  @preload
end

#progressObject (readonly)

Returns the value of attribute progress.



35
36
37
# File 'lib/evilution/config.rb', line 35

def progress
  @progress
end

#quietObject (readonly)

Returns the value of attribute quiet.



35
36
37
# File 'lib/evilution/config.rb', line 35

def quiet
  @quiet
end

Returns the value of attribute related_specs_heuristic.



35
36
37
# File 'lib/evilution/config.rb', line 35

def related_specs_heuristic
  @related_specs_heuristic
end

#save_sessionObject (readonly)

Returns the value of attribute save_session.



35
36
37
# File 'lib/evilution/config.rb', line 35

def save_session
  @save_session
end

#show_disabledObject (readonly)

Returns the value of attribute show_disabled.



35
36
37
# File 'lib/evilution/config.rb', line 35

def show_disabled
  @show_disabled
end

#skip_heredoc_literalsObject (readonly)

Returns the value of attribute skip_heredoc_literals.



35
36
37
# File 'lib/evilution/config.rb', line 35

def skip_heredoc_literals
  @skip_heredoc_literals
end

#spec_filesObject (readonly)

Returns the value of attribute spec_files.



35
36
37
# File 'lib/evilution/config.rb', line 35

def spec_files
  @spec_files
end

#suggest_testsObject (readonly)

Returns the value of attribute suggest_tests.



35
36
37
# File 'lib/evilution/config.rb', line 35

def suggest_tests
  @suggest_tests
end

#targetObject (readonly)

Returns the value of attribute target.



35
36
37
# File 'lib/evilution/config.rb', line 35

def target
  @target
end

#target_filesObject (readonly)

Returns the value of attribute target_files.



35
36
37
# File 'lib/evilution/config.rb', line 35

def target_files
  @target_files
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



35
36
37
# File 'lib/evilution/config.rb', line 35

def timeout
  @timeout
end

#verboseObject (readonly)

Returns the value of attribute verbose.



35
36
37
# File 'lib/evilution/config.rb', line 35

def verbose
  @verbose
end

Class Method Details

.default_templateObject

Generates a default config file template.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/evilution/config.rb', line 126

def self.default_template
  <<~YAML
    # Evilution configuration
    # See: https://github.com/marinazzio/evilution

    # Per-mutation timeout in seconds (default: 30)
    # timeout: 30

    # Output format: text or json (default: text)
    # format: text

    # Minimum mutation score to pass (0.0 to 1.0, default: 0.0)
    # min_score: 0.0

    # Test integration: rspec, minitest (default: rspec)
    # integration: rspec

    # Number of parallel workers (default: 1)
    # jobs: 1

    # Stop after N surviving mutants (default: disabled)
    # fail_fast: 1

    # Generate concrete test code in suggestions, matching integration (default: false)
    # suggest_tests: false

    # Skip all string literal mutations inside heredocs (default: false).
    # Useful for Rails apps where heredoc content (SQL, templates, fixtures)
    # rarely has meaningful test coverage and produces noisy survivors.
    # skip_heredoc_literals: true

    # Opt into the RelatedSpecHeuristic, which appends request/integration/
    # feature/system specs for mutations that touch `.includes(...)` calls
    # (default: false). Off by default because the fan-out can be heavy and
    # push runs over the per-mutation timeout. Enable if you need coverage
    # of N+1 regressions that only surface in higher-level specs.
    # related_specs_heuristic: true

    # When no matching spec resolves for a mutation's source file, the
    # default is to skip that mutation and mark it :unresolved in the
    # report (a coverage gap signal). Set to true to fall back to running
    # the entire test suite for such mutations instead (slow, high memory).
    # fallback_to_full_suite: false

    # Preload file required in the parent process before forking workers.
    # For Rails projects, spec/rails_helper.rb or test/test_helper.rb is
    # auto-detected when isolation resolves to :fork. Set to false to disable.
    # preload: spec/rails_helper.rb # or test/test_helper.rb

    # Hooks: Ruby files returning a Proc, keyed by lifecycle event
    # hooks:
    #   worker_process_start: config/evilution_hooks/worker_start.rb
    #   mutation_insert_pre: config/evilution_hooks/mutation_pre.rb

    # AST patterns to skip during mutation generation (default: [])
    # See docs/ast_pattern_syntax.md for pattern syntax
    # ignore_patterns:
    #   - "call{name=info, receiver=call{name=logger}}"
    #   - "call{name=debug|warn}"
  YAML
end

.file_optionsObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/evilution/config.rb', line 110

def self.file_options
  CONFIG_FILES.each do |path|
    next unless File.exist?(path)

    data = YAML.safe_load_file(path, symbolize_names: true)
    return data.is_a?(Hash) ? data : {}
  rescue Psych::SyntaxError, Psych::DisallowedClass => e
    raise Evilution::ConfigError.new("failed to parse config file #{path}: #{e.message}", file: path)
  rescue SystemCallError => e
    raise Evilution::ConfigError.new("cannot read config file #{path}: #{e.message}", file: path)
  end

  {}
end

Instance Method Details

#baseline?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/evilution/config.rb', line 74

def baseline?
  baseline
end

#fail_fast?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/evilution/config.rb', line 70

def fail_fast?
  !fail_fast.nil?
end

#fallback_to_full_suite?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/evilution/config.rb', line 106

def fallback_to_full_suite?
  fallback_to_full_suite
end

#html?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/evilution/config.rb', line 58

def html?
  format == :html
end

#incremental?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/evilution/config.rb', line 78

def incremental?
  incremental
end

#json?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/evilution/config.rb', line 50

def json?
  format == :json
end

#line_ranges?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/evilution/config.rb', line 62

def line_ranges?
  !line_ranges.empty?
end

#progress?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/evilution/config.rb', line 86

def progress?
  progress
end

Returns:

  • (Boolean)


102
103
104
# File 'lib/evilution/config.rb', line 102

def related_specs_heuristic?
  related_specs_heuristic
end

#save_session?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/evilution/config.rb', line 90

def save_session?
  save_session
end

#show_disabled?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/evilution/config.rb', line 94

def show_disabled?
  show_disabled
end

#skip_heredoc_literals?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/evilution/config.rb', line 98

def skip_heredoc_literals?
  skip_heredoc_literals
end

#suggest_tests?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/evilution/config.rb', line 82

def suggest_tests?
  suggest_tests
end

#target?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/evilution/config.rb', line 66

def target?
  !target.nil?
end

#text?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/evilution/config.rb', line 54

def text?
  format == :text
end