Class: Henitai::Mutant

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/mutant.rb,
lib/henitai/mutant/activator.rb

Overview

Represents a single syntactic mutation applied to a Subject.

A Mutant holds:

- the original and mutated AST nodes
- the operator that generated it
- the source location of the mutation
- its current status in the pipeline

Statuses follow the Stryker mutation-testing-report-schema vocabulary:

:pending, :killed, :survived, :timeout, :compile_error, :runtime_error,
:ignored, :no_coverage

Defined Under Namespace

Classes: Activator

Constant Summary collapse

STATUSES =

Status-Vokabular folgt dem Stryker mutation-testing-report-schema. :equivalent ist ein Henitai-interner Status (wird im JSON als “Ignored” serialisiert, aber in der Scoring-Berechnung separat behandelt: confirmed equivalent mutants werden aus dem Nenner der MS-Berechnung herausgenommen).

%i[
  pending
  killed
  survived
  timeout
  compile_error
  runtime_error
  ignored
  no_coverage
  equivalent
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject:, operator:, nodes:, description:, location:, precomputed_stable_id: nil, precomputed_activation_source: nil) ⇒ Mutant

rubocop:disable Metrics/ParameterLists

Parameters:

  • subject (Subject)

    the subject being mutated

  • operator (Symbol)

    operator name, e.g. :ArithmeticOperator

  • nodes (Hash)

    AST nodes with :original and :mutated entries

  • description (String)

    human-readable description of the mutation

  • location (Hash)

    { file:, start_line:, end_line:, start_col:, end_col: }



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/henitai/mutant.rb', line 48

def initialize(subject:, operator:, nodes:, description:, location:,
               precomputed_stable_id: nil, precomputed_activation_source: nil)
  @id            = SecureRandom.uuid
  @subject       = subject
  @operator      = operator
  @original_node = nodes.fetch(:original)
  @mutated_node  = nodes.fetch(:mutated)
  @description   = description
  @location      = location
  @precomputed_stable_id = precomputed_stable_id
  @precomputed_activation_source = precomputed_activation_source
  @status        = :pending
  @killing_test  = nil
  @duration      = nil
  @covered_by    = nil
  @tests_completed = nil
end

Instance Attribute Details

#covered_byObject

Returns the value of attribute covered_by.



40
41
42
# File 'lib/henitai/mutant.rb', line 40

def covered_by
  @covered_by
end

#descriptionObject (readonly)

Returns the value of attribute description.



37
38
39
# File 'lib/henitai/mutant.rb', line 37

def description
  @description
end

#durationObject

Returns the value of attribute duration.



40
41
42
# File 'lib/henitai/mutant.rb', line 40

def duration
  @duration
end

#idObject (readonly)

Returns the value of attribute id.



37
38
39
# File 'lib/henitai/mutant.rb', line 37

def id
  @id
end

#killing_testObject

Returns the value of attribute killing_test.



40
41
42
# File 'lib/henitai/mutant.rb', line 40

def killing_test
  @killing_test
end

#locationObject (readonly)

Returns the value of attribute location.



37
38
39
# File 'lib/henitai/mutant.rb', line 37

def location
  @location
end

#mutated_nodeObject (readonly)

Returns the value of attribute mutated_node.



37
38
39
# File 'lib/henitai/mutant.rb', line 37

def mutated_node
  @mutated_node
end

#mutation_typeObject (readonly)

Returns the value of attribute mutation_type.



37
38
39
# File 'lib/henitai/mutant.rb', line 37

def mutation_type
  @mutation_type
end

#operatorObject (readonly)

Returns the value of attribute operator.



37
38
39
# File 'lib/henitai/mutant.rb', line 37

def operator
  @operator
end

#original_nodeObject (readonly)

Returns the value of attribute original_node.



37
38
39
# File 'lib/henitai/mutant.rb', line 37

def original_node
  @original_node
end

#precomputed_activation_sourceObject (readonly)

Returns the value of attribute precomputed_activation_source.



37
38
39
# File 'lib/henitai/mutant.rb', line 37

def precomputed_activation_source
  @precomputed_activation_source
end

#precomputed_stable_idObject (readonly)

Returns the value of attribute precomputed_stable_id.



37
38
39
# File 'lib/henitai/mutant.rb', line 37

def precomputed_stable_id
  @precomputed_stable_id
end

#statusObject

Returns the value of attribute status.



40
41
42
# File 'lib/henitai/mutant.rb', line 40

def status
  @status
end

#subjectObject (readonly)

Returns the value of attribute subject.



37
38
39
# File 'lib/henitai/mutant.rb', line 37

def subject
  @subject
end

#tests_completedObject

Returns the value of attribute tests_completed.



40
41
42
# File 'lib/henitai/mutant.rb', line 40

def tests_completed
  @tests_completed
end

Instance Method Details

#equivalent?Boolean

Returns:

  • (Boolean)


75
# File 'lib/henitai/mutant.rb', line 75

def equivalent?  = @status == :equivalent

#ignored?Boolean

Returns:

  • (Boolean)


74
# File 'lib/henitai/mutant.rb', line 74

def ignored?     = @status == :ignored

#killed?Boolean

Returns:

  • (Boolean)


71
# File 'lib/henitai/mutant.rb', line 71

def killed?      = @status == :killed

#pending?Boolean

Returns:

  • (Boolean)


73
# File 'lib/henitai/mutant.rb', line 73

def pending?     = @status == :pending

#stable_idObject

rubocop:enable Metrics/ParameterLists



67
68
69
# File 'lib/henitai/mutant.rb', line 67

def stable_id
  @stable_id ||= @precomputed_stable_id || MutantIdentity.stable_id(self)
end

#survived?Boolean

Returns:

  • (Boolean)


72
# File 'lib/henitai/mutant.rb', line 72

def survived?    = @status == :survived

#to_sObject



77
78
79
# File 'lib/henitai/mutant.rb', line 77

def to_s
  "#{operator}@#{location[:file]}:#{location[:start_line]}#{description}"
end