@@ -121,6 +121,26 @@ func runGoTest(path string, coverFileName string, hideStderr bool) error {
121121 return nil
122122}
123123
124+ func guessAbsPathInGOPATH (GOPATH , relPath string ) (absPath string , err error ) {
125+ if GOPATH == "" {
126+ return "" , fmt .Errorf ("GOPATH is not set" )
127+ }
128+
129+ gopathChunks := strings .Split (GOPATH , string (os .PathListSeparator ))
130+ for _ , gopathChunk := range gopathChunks {
131+ guessAbsPath := strings .Join ([]string {gopathChunk , "src" , relPath }, string (os .PathSeparator ))
132+ if _ , err = os .Stat (guessAbsPath ); err == nil {
133+ absPath = guessAbsPath
134+ break
135+ }
136+ }
137+
138+ if absPath == "" {
139+ return "" , fmt .Errorf ("File '%s' not found in GOPATH" , relPath )
140+ }
141+ return absPath , err
142+ }
143+
124144func getCoverForDir (path string , coverFileName string , filesFilter []string , colors256 bool ) (result []byte , err error ) {
125145 coverProfile , err := cover .ParseProfiles (coverFileName )
126146 if err != nil {
@@ -133,8 +153,11 @@ func getCoverForDir(path string, coverFileName string, filesFilter []string, col
133153 // absolute path (or relative in tests)
134154 fileName = strings .TrimLeft (fileProfile .FileName , "_" )
135155 } else {
136- // file in GOPATH
137- fileName = os .Getenv ("GOPATH" ) + "/src/" + fileProfile .FileName
156+ // file in one dir in GOPATH
157+ fileName , err = guessAbsPathInGOPATH (os .Getenv ("GOPATH" ), fileProfile .FileName )
158+ if err != nil {
159+ return result , err
160+ }
138161 }
139162
140163 if len (filesFilter ) > 0 && ! isSliceInString (fileName , filesFilter ) {
0 commit comments