diff --git a/Makefile b/Makefile index e35747d..5924729 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ export ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) export PKG := github.com/zimmski/go-mutesting export ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -export TEST_TIMEOUT_IN_SECONDS := 240 +export TEST_TIMEOUT_IN_SECONDS := 360 $(eval $(ARGS):;@:) # turn arguments into do-nothing targets export ARGS diff --git a/cmd/go-mutesting/main.go b/cmd/go-mutesting/main.go index ee786f5..5380c66 100644 --- a/cmd/go-mutesting/main.go +++ b/cmd/go-mutesting/main.go @@ -39,10 +39,11 @@ const ( type options struct { General struct { - Debug bool `long:"debug" description:"Debug log output"` - DoNotRemoveTmpFolder bool `long:"do-not-remove-tmp-folder" description:"Do not remove the tmp folder where all mutations are saved to"` - Help bool `long:"help" description:"Show this help message"` - Verbose bool `long:"verbose" description:"Verbose log output"` + Debug bool `long:"debug" description:"Debug log output"` + DoNotRemoveTmpFolder bool `long:"do-not-remove-tmp-folder" description:"Do not remove the tmp folder where all mutations are saved to"` + Help bool `long:"help" description:"Show this help message"` + Verbose bool `long:"verbose" description:"Verbose log output"` + TestTags string `long:"test-tags" description:"Build tags used when running go test"` } `group:"General options"` Files struct { @@ -407,7 +408,13 @@ func mutateExec(opts *options, pkg *types.Package, file string, src ast.Node, mu pkgName += "/..." } - test, err := exec.Command("go", "test", "-timeout", fmt.Sprintf("%ds", opts.Exec.Timeout), pkgName).CombinedOutput() + var test []byte + if opts.General.TestTags != "" { + test, err = exec.Command("go", "test", "-tags", opts.General.TestTags, "-timeout", fmt.Sprintf("%ds", opts.Exec.Timeout), pkgName).CombinedOutput() + } else { + test, err = exec.Command("go", "test", "-timeout", fmt.Sprintf("%ds", opts.Exec.Timeout), pkgName).CombinedOutput() + } + if err == nil { execExitCode = 0 } else if e, ok := err.(*exec.ExitError); ok { diff --git a/cmd/go-mutesting/main_test.go b/cmd/go-mutesting/main_test.go index 7727851..f23ae43 100644 --- a/cmd/go-mutesting/main_test.go +++ b/cmd/go-mutesting/main_test.go @@ -15,7 +15,7 @@ func TestMain(t *testing.T) { "../../example", []string{"--debug", "--exec-timeout", "1"}, returnOk, - "The mutation score is 0.450000 (9 passed, 11 failed, 8 duplicated, 0 skipped, total is 20)", + "The mutation score is 0.428571 (9 passed, 12 failed, 8 duplicated, 0 skipped, total is 21)", ) } @@ -25,7 +25,7 @@ func TestMainRecursive(t *testing.T) { "../../example", []string{"--debug", "--exec-timeout", "1", "./..."}, returnOk, - "The mutation score is 0.476190 (10 passed, 11 failed, 8 duplicated, 0 skipped, total is 21)", + "The mutation score is 0.454545 (10 passed, 12 failed, 8 duplicated, 0 skipped, total is 22)", ) } @@ -35,7 +35,7 @@ func TestMainFromOtherDirectory(t *testing.T) { "../..", []string{"--debug", "--exec-timeout", "1", "github.com/zimmski/go-mutesting/example"}, returnOk, - "The mutation score is 0.450000 (9 passed, 11 failed, 8 duplicated, 0 skipped, total is 20)", + "The mutation score is 0.428571 (9 passed, 12 failed, 8 duplicated, 0 skipped, total is 21)", ) } @@ -49,6 +49,16 @@ func TestMainMatch(t *testing.T) { ) } +func TestTagged(t *testing.T) { + testMain( + t, + "../../example", + []string{"--debug", "--exec-timeout", "1", "--test-tags", "tagged", "github.com/zimmski/go-mutesting/example"}, + returnOk, + "The mutation score is 0.476190 (10 passed, 11 failed, 8 duplicated, 0 skipped, total is 21)", + ) +} + func testMain(t *testing.T, root string, exec []string, expectedExitCode int, contains string) { saveStderr := os.Stderr saveStdout := os.Stdout diff --git a/example/tagged.go b/example/tagged.go new file mode 100644 index 0000000..8343a64 --- /dev/null +++ b/example/tagged.go @@ -0,0 +1,5 @@ +package example + +func gt(a, b int) bool { + return a > b +} diff --git a/example/tagged_test.go b/example/tagged_test.go new file mode 100644 index 0000000..120bf51 --- /dev/null +++ b/example/tagged_test.go @@ -0,0 +1,21 @@ +// +build tagged + +package example + +import ( + "testing" + + . "github.com/stretchr/testify/assert" +) + +func TestGreaterThan(t *testing.T) { + Equal(t, gt(2,1), true) +} + +func TestLessThan(t *testing.T) { + Equal(t, gt(1,2), false) +} + +func TestEqual(t *testing.T) { + Equal(t, gt(2,2), false) +}