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:) ⇒ Mutant

Returns a new instance of Mutant.

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: }



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/henitai/mutant.rb', line 45

def initialize(subject:, operator:, nodes:, description:, location:)
  @id            = SecureRandom.uuid
  @subject       = subject
  @operator      = operator
  @original_node = nodes.fetch(:original)
  @mutated_node  = nodes.fetch(:mutated)
  @description   = description
  @location      = location
  @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.



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

def covered_by
  @covered_by
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#durationObject

Returns the value of attribute duration.



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

def duration
  @duration
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#killing_testObject

Returns the value of attribute killing_test.



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

def killing_test
  @killing_test
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#mutated_nodeObject (readonly)

Returns the value of attribute mutated_node.



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

def mutated_node
  @mutated_node
end

#mutation_typeObject (readonly)

Returns the value of attribute mutation_type.



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

def mutation_type
  @mutation_type
end

#operatorObject (readonly)

Returns the value of attribute operator.



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

def operator
  @operator
end

#original_nodeObject (readonly)

Returns the value of attribute original_node.



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

def original_node
  @original_node
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#subjectObject (readonly)

Returns the value of attribute subject.



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

def subject
  @subject
end

#tests_completedObject

Returns the value of attribute tests_completed.



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

def tests_completed
  @tests_completed
end

Instance Method Details

#equivalent?Boolean

Returns:

  • (Boolean)


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

def equivalent?  = @status == :equivalent

#ignored?Boolean

Returns:

  • (Boolean)


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

def ignored?     = @status == :ignored

#killed?Boolean

Returns:

  • (Boolean)


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

def killed?      = @status == :killed

#pending?Boolean

Returns:

  • (Boolean)


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

def pending?     = @status == :pending

#survived?Boolean

Returns:

  • (Boolean)


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

def survived?    = @status == :survived

#to_sObject



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

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