Skip to content

Commit

Permalink
#2 Add mutation status
Browse files Browse the repository at this point in the history
Signed-off-by: Davide Petilli <[email protected]>
  • Loading branch information
k3rn31 committed Jun 25, 2022
1 parent 1195b78 commit 58a3249
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 13 additions & 2 deletions mutator/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ import (
"go/token"
)

type MutationStatus int

const (
NotCovered MutationStatus = iota
Runnable
Lived
Killed
)

type Mutant struct {
MutantType MutantType
Token token.Token
Position token.Position
Covered bool
Status MutationStatus
}

type Mutator struct {
Expand All @@ -49,7 +58,9 @@ func (m Mutator) RunWithFileName(fileName string) []Mutant {
if !ok {
return false
}
r.Covered = m.covProfile.IsCovered(r.Position)
if m.covProfile.IsCovered(r.Position) {
r.Status = Runnable
}
result = append(result, r)
}
return true
Expand Down
15 changes: 7 additions & 8 deletions mutator/mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,46 @@ func TestMutations(t *testing.T) {
mutantType mutator.MutantType
tokenType token.Token
covProfile coverage.Profile
covered bool
mutStatus mutator.MutationStatus
}{
{
name: "it recognizes CONDITIONAL_BOUNDARY with GTR",
fileName: "testdata/fixtures/conditional_boundary_gtr_go",
mutantType: mutator.ConditionalBoundary,
tokenType: token.GTR,
covProfile: coveredPosition("testdata/fixtures/conditional_boundary_gtr_go"),
covered: true,
mutStatus: mutator.Runnable,
},
{
name: "it recognizes CONDITIONAL_BOUNDARY with LSS",
fileName: "testdata/fixtures/conditional_boundary_lss_go",
mutantType: mutator.ConditionalBoundary,
tokenType: token.LSS,
covProfile: notCoveredPosition("testdata/fixtures/conditional_boundary_lss_go"),
covered: false,
mutStatus: mutator.NotCovered,
},
{
name: "it recognizes CONDITIONAL_BOUNDARY with LEQ",
fileName: "testdata/fixtures/conditional_boundary_leq_go",
mutantType: mutator.ConditionalBoundary,
tokenType: token.LEQ,
covProfile: notCoveredPosition("testdata/fixtures/conditional_boundary_leq_go"),
covered: false,
mutStatus: mutator.NotCovered,
},
{
name: "it recognizes CONDITIONAL_BOUNDARY with GEQ",
fileName: "testdata/fixtures/conditional_boundary_geq_go",
mutantType: mutator.ConditionalBoundary,
tokenType: token.GEQ,
covProfile: notCoveredPosition("testdata/fixtures/conditional_boundary_geq_go"),
covered: false,
mutStatus: mutator.NotCovered,
},
{
name: "it skips illegal CONDITIONAL_BOUNDARY",
fileName: "testdata/fixtures/conditional_boundary_illegal_go",
mutantType: mutator.ConditionalBoundary,
tokenType: token.ILLEGAL,
covProfile: notCoveredPosition("testdata/fixtures/conditional_boundary_illegal_go"),
covered: false,
},
}
for _, tc := range testCases {
Expand All @@ -101,8 +100,8 @@ func TestMutations(t *testing.T) {
if !cmp.Equal(got[0].Token, tc.tokenType) {
t.Errorf(cmp.Diff(got[0].Token, tc.tokenType))
}
if !cmp.Equal(got[0].Covered, tc.covered) {
t.Errorf(cmp.Diff(got[0].Covered, tc.covered))
if !cmp.Equal(got[0].Status, tc.mutStatus) {
t.Errorf(cmp.Diff(got[0].Status, tc.mutStatus))
}
})
}
Expand Down

0 comments on commit 58a3249

Please sign in to comment.