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
17
# 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
  @shadow_aborted = 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

#infrastructure_failure?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/mutation_tester/core.rb', line 57

def infrastructure_failure?
  @shadow_aborted || (!@results.empty? && scored_count.zero?)
end

#interrupted?Boolean

Returns:

  • (Boolean)


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

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

#mutation_scoreObject



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

def mutation_score
  Reporters::BaseReporter.score(@results, policy: @config.timeout_policy)
end

#runObject



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

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

  unless shadow_environment_reliable?
    @shadow_aborted = true
    return false
  end

  run_mutations
  generate_reports
  return report_interruption if interrupted?
  return report_infrastructure_failure if infrastructure_failure?

  check_threshold
ensure
  @mutation_runner&.cleanup_shadow_workspaces
  ForkRunner.shutdown_all
end

#threshold_met?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
# File 'lib/mutation_tester/core.rb', line 61

def threshold_met?
  return true unless @config.fail_on_threshold

  mutation_score >= @config.minimum_score
end