Skip to content

Commit

Permalink
Add --score flag to set a minimal acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid committed Jun 27, 2021
1 parent 6d92170 commit 9981568
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmd/go-mutesting/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ type options struct {
} `group:"Exec options"`

Test struct {
Recursive bool `long:"test-recursive" description:"Defines if the executer should test recursively"`
Recursive bool `long:"test-recursive" description:"Defines if the executer should test recursively"`
Score float64 `long:"score" description:"Minimal acceptable scores value. If result is less than given, exit code will be non-zero" default:"0"`
} `group:"Test options"`

Remaining struct {
Expand Down Expand Up @@ -111,7 +112,7 @@ func checkArguments(args []string, opts *options) (bool, int) {
opts.General.Verbose = true
}

return false, 0
return false, returnOk
}

func debug(opts *options, format string, args ...interface{}) {
Expand Down Expand Up @@ -299,13 +300,17 @@ MUTATOR:
debug(opts, "Remove %q", tmpDir)
}

exitCode := returnOk
if !opts.Exec.NoExec {
fmt.Printf("The mutation score is %f (%d passed, %d failed, %d duplicated, %d skipped, total is %d)\n", stats.Score(), stats.passed, stats.failed, stats.duplicated, stats.skipped, stats.Total())
if stats.Score() < opts.Test.Score {
exitCode = returnError
}
} else {
fmt.Println("Cannot do a mutation testing summary since no exec command was executed.")
}

return returnOk
return exitCode
}

func mutate(opts *options, mutators []mutatorItem, mutationBlackList map[string]struct{}, mutationID int, pkg *types.Package, info *types.Info, file string, fset *token.FileSet, src ast.Node, node ast.Node, tmpFile string, execs []string, stats *mutationStats) int {
Expand Down
10 changes: 10 additions & 0 deletions cmd/go-mutesting/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ func TestMainMatch(t *testing.T) {
)
}

func TestMainScore(t *testing.T) {
testMain(
t,
"../../example",
[]string{"--debug", "--exec-timeout", "1", "--score", "0.46"},
returnError,
"The mutation score is 0.450000 (9 passed, 11 failed, 8 duplicated, 0 skipped, total is 20)",
)
}

func testMain(t *testing.T, root string, exec []string, expectedExitCode int, contains string) {
saveStderr := os.Stderr
saveStdout := os.Stdout
Expand Down

0 comments on commit 9981568

Please sign in to comment.