func runFix(cmd *base.Command, args []string) {
printed := false
for _, pkg := range load.Packages(args) {
- if modload.Enabled() && !pkg.Module.Main {
+ if modload.Enabled() && pkg.Module != nil && !pkg.Module.Main {
if !printed {
fmt.Fprintf(os.Stderr, "go: not fixing packages in dependency modules\n")
printed = true
// Even if the arguments are .go files, this loop suffices.
printed := false
for _, pkg := range load.Packages(args) {
- if modload.Enabled() && !pkg.Module.Main {
+ if modload.Enabled() && pkg.Module != nil && !pkg.Module.Main {
if !printed {
fmt.Fprintf(os.Stderr, "go: not generating in packages in dependency modules\n")
printed = true
go list $GOROOT/src/fmt
stdout '^fmt$'
+# 'go list' should work with file arguments.
+go list ./foo/foo.go
+stdout 'command-line-arguments'
# 'go list -m' with an explicit version should resolve that version.
go list -m example.com/version@latest
stdout 'main is main \(devel\)'
stdout 'using example.com/version v1.1.0'
+# 'go generate' should work with file arguments.
+[exec:touch] go generate ./foo/foo.go
+[exec:touch] exists ./foo/gen.txt
+
+# 'go install' should work with file arguments.
+go install ./foo/foo.go
+
+# 'go test' should work with file arguments.
+go test -v ./foo/foo_test.go
+stdout 'foo was tested'
+
+# 'go vet' should work with file arguments.
+go vet ./foo/foo.go
+
-- README.txt --
There is no go.mod file in the working directory.
-- foo/foo.go --
+//go:generate touch gen.txt
+
package main
import (
fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version)
}
}
+
+-- foo/foo_test.go --
+package main
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestFoo(t *testing.T) {
+ fmt.Println("foo was tested")
+}