Skip to content

Commit e2204d0

Browse files
imsodinAudriusButkevicius
authored andcommitted
build: Add option to get test coverage (syncthing#5539)
1 parent d5ff2c4 commit e2204d0

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

.codecov.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
coverage:
2+
range: "40...100"
3+
4+
ignore:
5+
- "**.pb.go"

build.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var (
4848
pkgdir string
4949
cc string
5050
debugBinary bool
51+
coverage bool
5152
timeout = "120s"
5253
gogoProtoVersion = "v1.2.0"
5354
)
@@ -330,24 +331,27 @@ func parseFlags() {
330331
flag.StringVar(&pkgdir, "pkgdir", "", "Set -pkgdir parameter for `go build`")
331332
flag.StringVar(&cc, "cc", os.Getenv("CC"), "Set CC environment variable for `go build`")
332333
flag.BoolVar(&debugBinary, "debug-binary", debugBinary, "Create unoptimized binary to use with delve, set -gcflags='-N -l' and omit -ldflags")
334+
flag.BoolVar(&coverage, "coverage", coverage, "Write coverage profile of tests to coverage.txt")
333335
flag.Parse()
334336
}
335337

336338
func test(pkgs ...string) {
337339
lazyRebuildAssets()
338340

339-
useRace := runtime.GOARCH == "amd64"
340-
switch runtime.GOOS {
341-
case "darwin", "linux", "freebsd": // , "windows": # See https://github.com/golang/go/issues/27089
342-
default:
343-
useRace = false
341+
args := []string{"test", "-short", "-timeout", timeout, "-tags", "purego"}
342+
343+
if runtime.GOARCH == "amd64" {
344+
switch runtime.GOOS {
345+
case "darwin", "linux", "freebsd": // , "windows": # See https://github.com/golang/go/issues/27089
346+
args = append(args, "-race")
347+
}
344348
}
345349

346-
if useRace {
347-
runPrint(goCmd, append([]string{"test", "-short", "-race", "-timeout", timeout, "-tags", "purego"}, pkgs...)...)
348-
} else {
349-
runPrint(goCmd, append([]string{"test", "-short", "-timeout", timeout, "-tags", "purego"}, pkgs...)...)
350+
if coverage {
351+
args = append(args, "-covermode", "atomic", "-coverprofile", "coverage.txt")
350352
}
353+
354+
runPrint(goCmd, append(args, pkgs...)...)
351355
}
352356

353357
func bench(pkgs ...string) {

0 commit comments

Comments
 (0)