Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage: [no statements] #42118

Closed
NickBishop2112 opened this issue Oct 21, 2020 · 1 comment
Closed

coverage: [no statements] #42118

NickBishop2112 opened this issue Oct 21, 2020 · 1 comment

Comments

@NickBishop2112
Copy link

NickBishop2112 commented Oct 21, 2020

What version of Go are you using (go version)?

$ go version : 1.15.3 windows/amd64

Does this issue reproduce with the latest release?

Still have the same issue with the latest version

What operating system and processor architecture are you using (go env)?

go env Output
$ go env 

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Emptiness\AppData\Local\go-build
set GOENV=C:\Users\Emptiness\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Emptiness\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Emptiness\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Emptiness\source\repos\go-programming\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\EMPTIN~1\AppData\Local\Temp\go-build411590906=/tmp/go-build -gno-record-gcc-switches

What did you do?

Run go test ./test/... -cover. Unit Tests coverage shows the statement: coverage: [no statements]

The following test code is a sample:

KctuAoErhfs.txt

package playpen_test

import (
	"testing"
)

func Sum(numbers []int) int {
	sum := 0
	for _, number := range numbers {
		sum += number
	}
	return sum
}

func TestSum(t *testing.T) {

	t.Run("collection of any size", func(t *testing.T) {
		numbers := []int{1, 2, 3}

		got := Sum(numbers)
		want := 6

		if got != want {
			t.Errorf("got %d want %d given, %v", got, want, numbers)
		}
	})
}

What did you expect to see?

Showing the test coverage as per the example in https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/arrays-and-slices

What did you see instead?

Have the following shown instead
Capture

or in text: ok go-programming/test/arrays 0.200s coverage: [no statements]

@bcmills
Copy link
Contributor

bcmills commented Oct 21, 2020

-cover measures how much the test covers of the corresponding package.

In the example you have provided, the Sum function is part of the test itself (it is a test-helper function), not the package per se.

(Note that https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/arrays-and-slices#write-the-minimal-amount-of-code-for-the-test-to-run-and-check-the-failing-test-output begins, “In sum.go”.)

@bcmills bcmills closed this as completed Oct 21, 2020
@golang golang locked and limited conversation to collaborators Oct 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants