Dear Gophers,

I'm struggling with "go test -coverpkg=XXX ... ./... -args 
-test.gocoverdir" returning non-zero exit codes, albeit all tests are 
passing. It might well be that I'm not really yet understanding how "go 
test -coverpkg=" is supposed to work. As illustrated below, I don't want to 
-coverpkg *all* packages "./..." in my module, but instead all *but one*.

First, I'm using go version go1.22.1 linux/amd64. The same happens for 
go1.22.0, too.

Now, my repo in a minimized example might look like the following -- 
unfortunately, I don't see how I can make a useful playground example with 
the required specific "go test" invocation.

   - github.com/example/foo
      - bar -- contains tests
      - baz -- contains tests
      - foobaz -- no tests
   
Following is preparing the list of packages to cover, with the exclusion(s):

GOCOVERTMPDIR="$(mktemp -d)"
trap 'rm -rf -- "$GOCOVERTMPDIR"' EXIT
IGNORE_PKGS=("github.com/example/foobaz")
FILTER_PATTERN="$(printf '^%s$|' "${IGNORE_PKGS[@]}" | sed 's/|$//')"
PACKAGE_LIST=$(go list ./... | grep -v -E "${FILTER_PATTERN}" | tr '\n' ',' 
| sed 's/,$//')
go test -coverpkg="${PACKAGE_LIST}" -v -tags=matchers -p=1 -count=1 -race \
    ./... -args -test.gocoverdir="$GOCOVERTMPDIR"

This runs all available tests including testable examples with success, but 
exits with code 1.

Running the same tests with -coverpkg=./... succeeds.

What am I doing wrong? Or might this be an issue?

*Nota bene:* *why do I want to exclude a package from the coverage? Because 
that is a trimmed-down package (as permitted by its license) following 
CalVer(!) and having no go.mod, with otherwise large number of unnecessary 
dependencies in my particular case. It changes the coverage considerably, 
distracting from the coverage of my own code.*

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/541ca662-f052-4a99-aa2b-b4b8d6924ffbn%40googlegroups.com.

Reply via email to