From fc44c3b7cf2c932e5c1e9f4a37980ed13b81d23c Mon Sep 17 00:00:00 2001 From: Onsi Fakhouri Date: Sun, 12 Mar 2023 12:47:23 -0600 Subject: [PATCH] document coverpkg a bit more clearly --- docs/index.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 103a7ae51..7f9528d82 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3512,7 +3512,16 @@ Ginkgo supports `--race` to analyze race conditions, `--cover` to compute code c `ginkgo -vet` allows you to configure the set of checks that are applied when your code is compiled. `ginkgo` defaults to the set of default checks that `go test` uses and you can specify additional checks by passing a comma-separated list to `--vet`. The set of available checks can be found by running `go doc cmd/vet`. #### Computing Coverage -`ginkgo -cover` will compute and emit code coverage. When running multiple suites Ginkgo will emit coverage for each suite and then emit a composite coverage across all running suites. As with `go test` the default behavior for a given suite is to measure the coverage it provides for the code in the suite's package - however you can extend coverage to additional packages using `--coverpkg`. You can also specify the `--covermode` to be one of `set` ("was this code called at all?"), `count` (how many times was it called?) and `atomic` (same as count, but threadsafe and expensive). If you run `ginkgo --race --cover` the `--covermode` is automatically set to `atomic`. +`ginkgo -cover` will compute and emit code coverage. When running multiple suites Ginkgo will emit coverage for each suite and then emit a composite coverage across all running suites. As with `go test` the default behavior for a given suite is to measure the coverage it provides for the code in the suite's package - however you can extend coverage to additional packages using `--coverpkg`. You can provide a comma-separated list of package names (as they appear in `import` statements) or a relative path. You can also use `...` for recursion. For example, say we have a package called "github.com/foo/bar". The following are equivalent: + +```bash +ginkgo -coverpkg=./... -r +ginkgo -coverpkg=github.com/foo/bar/... -r +``` + +and will have the effect of calculating coverage for **all** code in the package by **all** specs in the package. + +You can also specify the `--covermode` to be one of `set` ("was this code called at all?"), `count` (how many times was it called?) and `atomic` (same as count, but threadsafe and expensive). If you run `ginkgo --race --cover` the `--covermode` is automatically set to `atomic`. When run with `--cover`, Ginkgo will generate a single `coverprofile.out` file that captures the coverage statistics of all the suites that ran. You can change the name of this file by specifying `-coverprofile=filename`. If you would like to keep separate coverprofiles for each suite use the `--keep-separate-coverprofiles` option.