Skip to content

Commit 7472604

Browse files
committed
Add --score flag to set a minimal acceptance
1 parent 6d92170 commit 7472604

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

cmd/go-mutesting/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ type options struct {
6767
} `group:"Exec options"`
6868

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

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

114-
return false, 0
115+
return false, returnOk
115116
}
116117

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

303+
exitCode := returnOk
302304
if !opts.Exec.NoExec {
303305
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())
306+
if stats.Score() < opts.Test.Score {
307+
exitCode = returnError
308+
}
304309
} else {
305310
fmt.Println("Cannot do a mutation testing summary since no exec command was executed.")
306311
}
307312

308-
return returnOk
313+
return exitCode
309314
}
310315

311316
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 {

cmd/go-mutesting/main_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ func TestMainMatch(t *testing.T) {
4949
)
5050
}
5151

52+
func TestMainScore(t *testing.T) {
53+
testMain(
54+
t,
55+
"../../example",
56+
[]string{"--debug", "--exec-timeout", "1", "--score", "0.46"},
57+
returnError,
58+
"The mutation score is 0.450000 (9 passed, 11 failed, 8 duplicated, 0 skipped, total is 20)",
59+
)
60+
}
61+
5262
func testMain(t *testing.T, root string, exec []string, expectedExitCode int, contains string) {
5363
saveStderr := os.Stderr
5464
saveStdout := os.Stdout

0 commit comments

Comments
 (0)