Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --score flag to set a minimal acceptance #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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