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

Open
bradfitz opened this issue Jun 5, 2020 · 0 comments
Labels
Projects
Milestone

Comments

@bradfitz
Copy link
Contributor

@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 golang.org/x/sys/windows/registry 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 $?
1

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 $?
1

dev:foo $ cat > x.go
package main

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

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 $?
0

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

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

$ go test golang.org/x/sys/windows/registry
?       golang.org/x/sys/windows/registry [no matching files]
$ echo $?
0

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
Projects
Proposals
Incoming
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.