aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeschi Kreinick <heschi@google.com>2019-06-07 18:37:28 -0400
committerHeschi Kreinick <heschi@google.com>2019-06-07 22:46:22 +0000
commit755ce86c7629f15bd3128fa8dbfa6a619a9a6c7a (patch)
tree1f3359f3dae6e2860c07c9e822965ab4893c8b4b
parent68211a626cca1068197e1fa98907659c722d4222 (diff)
downloadgolang-x-tools-755ce86c7629f15bd3128fa8dbfa6a619a9a6c7a.tar.gz
internal/imports: fix TestNoMainModule
https://golang.org/cl/179998 made it an error to run go mod download without args and without a go.mod. Don't do that. Fixes golang/go#32488 Change-Id: Icd845feb8fecae69b6a8363438bb9ee546a310dc Reviewed-on: https://go-review.googlesource.com/c/tools/+/181298 Run-TryBot: Heschi Kreinick <heschi@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--internal/imports/mod_test.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/internal/imports/mod_test.go b/internal/imports/mod_test.go
index 590b1c89d..97ef715cd 100644
--- a/internal/imports/mod_test.go
+++ b/internal/imports/mod_test.go
@@ -524,10 +524,15 @@ func setup(t *testing.T, main, wd string) *modTest {
WorkingDir: filepath.Join(mainDir, wd),
}
- // go mod tidy instead of download because tidy will notice dependencies
- // in code, not just in go.mod files.
- if _, err := env.invokeGo("mod", "download"); err != nil {
- t.Fatal(err)
+ // go mod download gets mad if we don't have a go.mod, so make sure we do.
+ _, err = os.Stat(filepath.Join(mainDir, "go.mod"))
+ if err != nil && !os.IsNotExist(err) {
+ t.Fatalf("checking if go.mod exists: %v", err)
+ }
+ if err == nil {
+ if _, err := env.invokeGo("mod", "download"); err != nil {
+ t.Fatal(err)
+ }
}
return &modTest{