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

proposal: cmd/go: make "go test" exit 0 if *.go files exist but none match context #39426

bradfitz opened this issue Jun 5, 2020 · 0 comments


Copy link

@bradfitz bradfitz commented Jun 5, 2020

It's a little weird right now that go test in a directory of non-context-matching *.go files (like on Linux) results in an error, but go test in a directory without tests is fine (exit 0), and go test ./... is also fine, as long as one directory somewhere has a context-matching file.

dev:~ $ mkdir /tmp/foo
dev:~ $ cd /tmp/foo
dev:foo $ go mod init foo
go: creating new go.mod: module foo

dev:foo $ go test
no Go files in /tmp/foo
dev:foo $ echo $?

dev:foo $ cat > x_windows.go
package main

dev:foo $ go test
package foo: build constraints exclude all Go files in /tmp/foo
dev:foo $ echo $?

dev:foo $ cat > x.go
package main

dev:foo $ go test
?       foo     [no test files]
dev:foo $ echo $?

dev:foo $ go test ./...
go: warning: "./..." matched no packages
no packages to test

dev:foo $ mkdir bar
dev:foo $ cat > bar/bar.go
package bar

dev:foo $ go test ./...
?       foo/bar [no test files]
dev:foo $ echo $?

dev:foo $ go test
go: finding module for package
go: downloading v0.0.0-20200602225109-6fdc65e7d980
go: found in v0.0.0-20200602225109-6fdc65e7d980
package build constraints exclude all Go files in /home/bradfitz/pkg/mod/

Can we instead make go test act more like the package has no tests? I'd like to see:

$ go test
? [no matching files]
$ echo $?

This arose due to integration of Go in another build system (that builds non-Go stuff) and that build system was using the heuristic that if a directory contains *_test.go files, it running go test in that directory was reasonable. That's currently not true for directories like x/sys/windows/registry or other such OS-specific packages.

@gopherbot gopherbot added this to the Proposal milestone Jun 5, 2020
@gopherbot gopherbot added the Proposal label Jun 5, 2020
@rsc rsc added this to Incoming in Proposals Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants