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"
This commit is contained in:
zavla 2018-11-28 20:22:11 +02:00 committed by Alessandro Arzilli
parent c7399ac278
commit a4a5d4b7f6

@ -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 {