Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go test panic in vendoredImportPath #14613

Closed
wenfang opened this issue Mar 3, 2016 · 2 comments
Closed

cmd/go: go test panic in vendoredImportPath #14613

wenfang opened this issue Mar 3, 2016 · 2 comments

Comments

@wenfang
Copy link

wenfang commented Mar 3, 2016

go1.6 centos7


file: src/vendor/mylibtesttest/myapp/myapp_test.go

  package myapp
  import (
     "mylibtesttest/rds"
  )

file: src/vendor/mylibtesttest/rds/rds.go

   package rds

In src/vendor/mylibtesttest/myapp/
1.
go test


./myapp_test.go:4: imported and not used: "vendor/mylibtesttest/rds"
FAIL    vendor/mylibtesttest/myapp [build failed]

go test myapp_test.go

panic: runtime error: slice bounds out of range

goroutine 1 [running]:
panic(0x93c000, 0xc8200100a0)
        /root/source/go-go1.6/src/runtime/panic.go:464 +0x3e6
main.vendoredImportPath(0xc820186000, 0xc82000fca1, 0x11, 0x0, 0x0)
        /root/source/go-go1.6/src/cmd/go/pkg.go:460 +0x67b
main.loadImport(0xc82000fca1, 0x11, 0xc820154c30, 0x28, 0xc820186000, 0xc820195150, 0xc820154f60, 0x1, 0x1, 0x1, ...)
        /root/source/go-go1.6/src/cmd/go/pkg.go:336 +0xe52
main.(*builder).test(0xc820176f50, 0xc820186000, 0x0, 0x0, 0xc820404980, 0x0, 0x0)
        /root/source/go-go1.6/src/cmd/go/test.go:632 +0x66d
main.runTest(0xc897e0, 0xc8200621d0, 0x1, 0x1)
        /root/source/go-go1.6/src/cmd/go/test.go:507 +0x16c5
main.main()
        /root/source/go-go1.6/src/cmd/go/main.go:181 +0x783

In src/cmd/go/pkg.go function vendoredImportPath
When we use "go test myapp_test.go", parent.ImportPath is "command-line-arguments", and it will panic in return parent.ImportPath[:len(parent.ImportPath)-chopped] + "/" + vpath, because of
len(parent.ImportPath)-chopped < 0

I add some code to fix this.

    targ := filepath.Join(dir[:i], vpath)
    if isDir(targ) && hasGoFiles(targ) {

+   if parent.ImportPath == "command-line-arguments" {
+       if i == len(root) {
+         return vpath
+       }    
+       return dir[len(root)+1:i] + "/" + vpath
+      }    

      // We started with parent's dir c:\gopath\src\foo\bar\baz\quux\xyzzy.
      // We know the import path for parent's dir.
      // We chopped off some number of path elements and
      // added vendor\path to produce c:\gopath\src\foo\bar\baz\vendor\path.
      // Now we want to know the import path for that directory.
      // Construct it by chopping the same number of path elements
      // (actually the same number of bytes) from parent's import path
      // and then append /vendor/path.
      chopped := len(dir) - i
      if chopped == len(parent.ImportPath)+1 {
        // We walked up from c:\gopath\src\foo\bar
        // and found c:\gopath\src\vendor\path.
        // We chopped \foo\bar (length 8) but the import path is "foo/bar" (length 7).
        // Use "vendor/path" without any prefix.
        return vpath
      }    
      return parent.ImportPath[:len(parent.ImportPath)-chopped] + "/" + vpath
    }    
@bradfitz bradfitz added this to the Go1.6.1 milestone Mar 3, 2016
clsung added a commit to clsung/go-vendor-issue-14613 that referenced this issue Apr 6, 2016
@gopherbot
Copy link

CL https://golang.org/cl/21596 mentions this issue.

@bradfitz bradfitz modified the milestones: Go1.6.1, Go1.6.2 Apr 7, 2016
@rsc rsc added the Release-OK label Apr 7, 2016
@gopherbot
Copy link

CL https://golang.org/cl/22051 mentions this issue.

gopherbot pushed a commit that referenced this issue Apr 14, 2016
Fixes #14613

Change-Id: I40d9696db3879549e78373ef17f6c92bd4b3470b
Reviewed-on: https://go-review.googlesource.com/21596
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-on: https://go-review.googlesource.com/22051
Run-TryBot: Andrew Gerrand <adg@golang.org>
@golang golang locked and limited conversation to collaborators Apr 19, 2017
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants