(I'm on go version go1.19.5 linux/amd64)
go test reports a warning if there's nothing to do:
$ go test -run test_that_doesn't_exist
testing: warning: no tests to run
The commands go test, go run, go build, and go install will also warn if there are no Go files in the given directory.
$ go test
no Go files in /directory
(In the case of go run, the warning is go: no go files listed)
However, unlike go test and go run, go build and go install will not warn when a Go file is present in the current directory but no binary is produced.
For example, in a directory with file helloWorld.go with the contents of the following:
package hello
import "fmt"
func talk() {
fmt.Println("Hello World!")
}
go run warns
$ go run helloWorld.go
package command-line-arguments is not a main package
go test warns
$ go test
? /helloWorldDir [no test files]
$ go test helloWorld.go
? command-line-arguments [no test files]
But go install and go build reports nothing.
$ go install helloWorld.go
$
$ go build helloWorld.go
$
And simply doing go install and go build also reports nothing.
What I would expect to see is the same warning as go run
$ go install
package is not a main package
$ go build
package is not a main package
(I'm on
go version go1.19.5 linux/amd64)go testreports a warning if there's nothing to do:The commands
go test,go run,go build, andgo installwill also warn if there are no Go files in the given directory.(In the case of
go run, the warning isgo: no go files listed)However, unlike
go testandgo run,go buildandgo installwill not warn when a Go file is present in the current directory but no binary is produced.For example, in a directory with file
helloWorld.gowith the contents of the following:go runwarnsgo testwarnsBut
go installandgo buildreports nothing.And simply doing
go installandgo buildalso reports nothing.What I would expect to see is the same warning as
go run