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
11 changes: 8 additions & 3 deletions cmd/go-mutesting/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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 @@ -113,7 +114,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 @@ -317,14 +318,18 @@ MUTATOR:
debug(opts, "Remove %q", tmpDir)
}

exitCode := returnOk
// if applicable, print high-level mutation results
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
}

// mutate runs all passed in mutators on all applicable parts of a single file
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
27 changes: 12 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
module github.com/osmosis-labs/go-mutesting

go 1.10
go 1.24.0

require (
github.com/davecgh/go-spew v1.1.0
github.com/hpcloud/tail v1.0.0 // indirect
github.com/jessevdk/go-flags v1.4.0
github.com/kisielk/errcheck v1.2.0 // indirect
github.com/mattn/goveralls v0.0.3 // indirect
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 // indirect
github.com/onsi/ginkgo v1.10.2 // indirect
github.com/pmezard/go-difflib v1.0.0
github.com/stretchr/testify v1.4.0
github.com/zimmski/go-mutesting v0.0.0-20210610104036-6d9217011a00
github.com/zimmski/go-tool v0.0.0-20150119110811-2dfdc9ac8439
github.com/zimmski/osutil v0.0.0-20190128123334-0d0b3ca231ac
golang.org/x/lint v0.0.0-20190930215403-16217165b5de // indirect
golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.2.2
honnef.co/go/tools v0.0.1-2019.2.3 // indirect
golang.org/x/tools v0.40.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.31.0 // indirect
golang.org/x/sync v0.19.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)
40 changes: 8 additions & 32 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,55 +1,31 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/goveralls v0.0.3/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/zimmski/go-mutesting v0.0.0-20210610104036-6d9217011a00 h1:KNiPkpQpqXvq40f8hh/1T7QasLJT/1MuBoOYA2vlxJk=
github.com/zimmski/go-mutesting v0.0.0-20210610104036-6d9217011a00/go.mod h1:RJt5SMnyha63GbdwCKJiX9djvvEC4KsfXJSZ5oTmSPw=
github.com/zimmski/go-tool v0.0.0-20150119110811-2dfdc9ac8439 h1:yHqsjUkj0HWbKPw/6ZqC0/eMklaRpqubA199vaRLzzE=
github.com/zimmski/go-tool v0.0.0-20150119110811-2dfdc9ac8439/go.mod h1:G4FVqCRvfz74AEB1crDNdQuvMfOoKtk7DlePsnV2yGs=
github.com/zimmski/osutil v0.0.0-20190128123334-0d0b3ca231ac h1:uiFRlKzyIzHeLOthe0ethUkSGW7POlqxU3Tc21R8QpQ=
github.com/zimmski/osutil v0.0.0-20190128123334-0d0b3ca231ac/go.mod h1:wJ9WGevuM/rw8aB2pQPFMUgXZWeaouI0ueFamR0DUPE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a h1:UuQ+70Pi/ZdWHuP4v457pkXeOynTdgd/4enxeIO/98k=
golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/mod v0.31.0 h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI=
golang.org/x/mod v0.31.0/go.mod h1:43JraMp9cGx1Rx3AqioxrbrhNsLl2l/iNAvuBkrezpg=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/tools v0.40.0 h1:yLkxfA+Qnul4cs9QA3KnlFu0lVmd8JJfoq+E41uSutA=
golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
1 change: 1 addition & 0 deletions testdata/branch/mutatecase.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build test
// +build test

package main
Expand Down
25 changes: 25 additions & 0 deletions testdata/branch/mutatecase.go.0.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build test
// +build test

package main

import (
"fmt"
)

func main() {
i := 1

for i != 4 {
switch {
case i == 1:
_, _ = fmt.Println, i
case i == 2:
fmt.Println(i * 2)
default:
fmt.Println(i * 3)
}

i++
}
}
25 changes: 25 additions & 0 deletions testdata/branch/mutatecase.go.1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build test
// +build test

package main

import (
"fmt"
)

func main() {
i := 1

for i != 4 {
switch {
case i == 1:
fmt.Println(i)
case i == 2:
_, _ = fmt.Println, i
default:
fmt.Println(i * 3)
}

i++
}
}
25 changes: 25 additions & 0 deletions testdata/branch/mutatecase.go.2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build test
// +build test

package main

import (
"fmt"
)

func main() {
i := 1

for i != 4 {
switch {
case i == 1:
fmt.Println(i)
case i == 2:
fmt.Println(i * 2)
default:
_, _ = fmt.Println, i
}

i++
}
}
1 change: 1 addition & 0 deletions testdata/branch/mutateelse.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build test
// +build test

package main
Expand Down
24 changes: 24 additions & 0 deletions testdata/branch/mutateelse.go.0.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build test
// +build test

package main

import (
"fmt"
)

func main() {
i := 1

for i != 4 {
if i == 1 {
fmt.Println(i)
} else if i == 2 {
fmt.Println(i * 2)
} else {
_, _ = fmt.Println, i
}

i++
}
}
1 change: 1 addition & 0 deletions testdata/branch/mutateif.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build test
// +build test

package main
Expand Down
24 changes: 24 additions & 0 deletions testdata/branch/mutateif.go.0.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build test
// +build test

package main

import (
"fmt"
)

func main() {
i := 1

for i != 4 {
if i == 1 {
_, _ = fmt.Println, i
} else if i == 2 {
fmt.Println(i * 2)
} else {
fmt.Println(i * 3)
}

i++
}
}
24 changes: 24 additions & 0 deletions testdata/branch/mutateif.go.1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build test
// +build test

package main

import (
"fmt"
)

func main() {
i := 1

for i != 4 {
if i == 1 {
fmt.Println(i)
} else if i == 2 {
_, _ = fmt.Println, i
} else {
fmt.Println(i * 3)
}

i++
}
}
1 change: 1 addition & 0 deletions testdata/expression/comparison.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build test
// +build test

package main
Expand Down
28 changes: 28 additions & 0 deletions testdata/expression/comparison.go.0.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//go:build test
// +build test

package main

import "fmt"

func main() {
if 1 >= 2 {
fmt.Printf("1 is greater than 2!")
}

if 1 < 2 {
fmt.Printf("1 is less than 2!")
}

if 1 <= 2 {
fmt.Printf("1 is less than or equal to 2!")
}

if 1 >= 2 {
fmt.Printf("1 is greater than or equal to 2!")
}

if 1 == 2 {
fmt.Print("1 is equal to 2!")
}
}
28 changes: 28 additions & 0 deletions testdata/expression/comparison.go.1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//go:build test
// +build test

package main

import "fmt"

func main() {
if 1 > 2 {
fmt.Printf("1 is greater than 2!")
}

if 1 <= 2 {
fmt.Printf("1 is less than 2!")
}

if 1 <= 2 {
fmt.Printf("1 is less than or equal to 2!")
}

if 1 >= 2 {
fmt.Printf("1 is greater than or equal to 2!")
}

if 1 == 2 {
fmt.Print("1 is equal to 2!")
}
}
Loading