From a4a5d4b7f6cba49dc31b8d128646fb006b18fc94 Mon Sep 17 00:00:00 2001 From: zavla Date: Wed, 28 Nov 2018 20:22:11 +0200 Subject: [PATCH] main_test: Fix "gopath mode" detection in projectRoot() (#1426) * main_test: Fix "gopath mode" detection in projectRoot() Fails detect that this is a "gopath mode" when GOPATH contains several paths ex. "d:\\dir\\gopath;f:\\dir\\gopath2" --- cmd/dlv/dlv_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/dlv/dlv_test.go b/cmd/dlv/dlv_test.go index 7dc83b85..45ecdb2d 100644 --- a/cmd/dlv/dlv_test.go +++ b/cmd/dlv/dlv_test.go @@ -51,8 +51,13 @@ func projectRoot() string { if err != nil { panic(err) } - if strings.Contains(wd, os.Getenv("GOPATH")) { - return filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "derekparker", "delve") + + gopaths := strings.FieldsFunc(os.Getenv("GOPATH"), func(r rune) bool { return r == os.PathListSeparator }) + for _, curpath := range gopaths { + // Detects "gopath mode" when GOPATH contains several paths ex. "d:\\dir\\gopath;f:\\dir\\gopath2" + if strings.Contains(wd, curpath) { + return filepath.Join(curpath, "src", "github.com", "derekparker", "delve") + } } val, err := exec.Command("go", "list", "-m", "-f", "{{ .Dir }}").Output() if err != nil {