Class: MutationTester::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/mutation_tester/core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file, spec_file, config = MutationTester.configuration) ⇒ Core

Returns a new instance of Core.



7
8
9
10
11
12
13
14
15
16
# File 'lib/mutation_tester/core.rb', line 7

def initialize(source_file, spec_file, config = MutationTester.configuration)
  @source_file = File.expand_path(source_file)
  @spec_file = File.expand_path(spec_file)
  @config = config
  @mutations = []
  @results = []
  @parse_failed = false
  MutationRunner.recover_in_place_backup(@source_file)
  @original_content = File.read(@source_file)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/mutation_tester/core.rb', line 5

def config
  @config
end

#mutationsObject (readonly)

Returns the value of attribute mutations.



5
6
7
# File 'lib/mutation_tester/core.rb', line 5

def mutations
  @mutations
end

#resultsObject (readonly)

Returns the value of attribute results.



5
6
7
# File 'lib/mutation_tester/core.rb', line 5

def results
  @results
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



5
6
7
# File 'lib/mutation_tester/core.rb', line 5

def source_file
  @source_file
end

#spec_fileObject (readonly)

Returns the value of attribute spec_file.



5
6
7
# File 'lib/mutation_tester/core.rb', line 5

def spec_file
  @spec_file
end

Instance Method Details

#interrupted?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/mutation_tester/core.rb', line 42

def interrupted?
  @config.fail_fast &&
    @results.size < @mutations.size &&
    @results.any? { |result| result[:status] == :survived }
end

#mutation_scoreObject



48
49
50
# File 'lib/mutation_tester/core.rb', line 48

def mutation_score
  Reporters::BaseReporter.score(@results)
end

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mutation_tester/core.rb', line 18

def run
  print_header
  return false unless run_original_tests

  generate_mutations
  return false if @parse_failed

  if @mutations.empty?
    puts Rainbow("\n✓ No mutations were generated for this file; nothing to test.").green
    return true
  end

  return false unless shadow_environment_reliable?

  run_mutations
  generate_reports
  return report_interruption if interrupted?

  check_threshold
ensure
  @mutation_runner&.cleanup_shadow_workspaces
  ForkRunner.shutdown_all
end

#threshold_met?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/mutation_tester/core.rb', line 52

def threshold_met?
  return true unless @config.fail_on_threshold

  mutation_score >= @config.minimum_score
end