Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions cmd/go-mutesting/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,32 +425,32 @@ func mutateExec(
execs []string,
mutant *models.Mutant,
) (execExitCode int) {
if len(execs) == 0 {
console.Debug(opts, "Execute built-in exec command for mutation")

diff, err := exec.Command("diff", "--label=Original", "--label=New", "-u", file, mutationFile).CombinedOutput()

startLine := parser.FindOriginalStartLine(diff)
mutant.Mutator.OriginalStartLine = startLine

if err == nil {
execExitCode = 0
} else if e, ok := err.(*exec.ExitError); ok {
execExitCode = e.Sys().(syscall.WaitStatus).ExitStatus()
execExitCode = 0
diff, err := exec.Command("diff", "--label=Original", "--label=New", "-u", file, mutationFile).CombinedOutput()
if err != nil {
if e, ok := err.(*exec.ExitError); ok {
execExitCode = e.ExitCode()
} else {
panic(err)
}
if execExitCode != 0 && execExitCode != 1 {
fmt.Printf("%s\n", diff)
}

panic("Could not execute diff on mutation file")
}
if execExitCode != 0 && execExitCode != 1 {
fmt.Printf("%s\n", diff)
panic("Could not execute diff on mutation file")
}

mutant.Mutator.OriginalStartLine = parser.FindOriginalStartLine(diff)
mutant.Diff = string(diff)

if len(execs) == 0 {
console.Debug(opts, "Execute built-in exec command for mutation")

defer func() {
_ = os.Rename(file+".tmp", file)
}()

err = os.Rename(file, file+".tmp")
err := os.Rename(file, file+".tmp")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -480,8 +480,6 @@ func mutateExec(
fmt.Printf("%s\n", test)
}

mutant.Diff = string(diff)

switch execExitCode {
case 0: // Tests passed -> FAIL
if !opts.Config.SilentMode {
Expand Down Expand Up @@ -532,7 +530,7 @@ func mutateExec(
execCommand.Env = append(execCommand.Env, "TEST_RECURSIVE=true")
}

err := execCommand.Start()
err = execCommand.Start()
if err != nil {
panic(err)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/go-mutesting/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func TestMainJSONReport(t *testing.T) {
for i := 0; i < len(mutationReport.Escaped); i++ {
assert.Contains(t, mutationReport.Escaped[i].ProcessOutput, "FAIL")
}
for i := 0; i < len(mutationReport.Escaped); i++ {
assert.Greater(t, len(mutationReport.Escaped[i].Diff), 0)
}
for i := 0; i < len(mutationReport.Killed); i++ {
assert.Contains(t, mutationReport.Killed[i].ProcessOutput, "PASS")
}
Expand Down