1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:34:53 -07:00
go/imports/mod_112_test.go
Heschi Kreinick c74ccfb859 imports: handle missing main module
If GO111MODULE=on but there's no go.mod, GOMOD will be set to /dev/null
or NUL and there will be no main module. goimports should handle this
case roughly the same way the go command does.

Fixes golang/go#30855

Change-Id: I6fbf4c056000db5abd8788a6014ae5f13b1c8cd4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167860
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-15 20:09:29 +00:00

22 lines
386 B
Go

// +build go1.12
package imports
import (
"testing"
)
// Tests that we handle GO111MODULE=on with no go.mod file. See #30855.
func TestNoMainModule(t *testing.T) {
mt := setup(t, `
-- x.go --
package x
`, "")
defer mt.cleanup()
if _, err := mt.env.invokeGo("mod", "download", "rsc.io/quote@v1.5.1"); err != nil {
t.Fatal(err)
}
mt.assertScanFinds("rsc.io/quote", "quote")
}