aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng-Lung Sung <clsung@gmail.com>2016-04-06 23:05:20 +0800
committerAndrew Gerrand <adg@golang.org>2016-04-14 05:25:03 +0000
commitd389a19c487de550a84b424109d66a2f3c3af004 (patch)
tree74d07a501be38f3d3a86f1ac21f5fb627dc49b26
parent2644b761935b2974fc2bb76be177621212b408c8 (diff)
downloadgo-d389a19c487de550a84b424109d66a2f3c3af004.tar.gz
go-d389a19c487de550a84b424109d66a2f3c3af004.zip
cmd/go: revise importPath when ImportPath is 'command-line-arguments'
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>
-rw-r--r--src/cmd/go/pkg.go10
-rw-r--r--src/cmd/go/vendor_test.go26
2 files changed, 34 insertions, 2 deletions
diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go
index 0c0cf07e71..599c2b4adf 100644
--- a/src/cmd/go/pkg.go
+++ b/src/cmd/go/pkg.go
@@ -441,6 +441,12 @@ func vendoredImportPath(parent *Package, path string) (found string) {
}
targ := filepath.Join(dir[:i], vpath)
if isDir(targ) && hasGoFiles(targ) {
+ importPath := parent.ImportPath
+ if importPath == "command-line-arguments" {
+ // If parent.ImportPath is 'command-line-arguments'.
+ // set to relative directory to root (also chopped root directory)
+ importPath = dir[len(root)+1:]
+ }
// 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
@@ -450,14 +456,14 @@ func vendoredImportPath(parent *Package, path string) (found string) {
// (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 {
+ if chopped == len(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
+ return importPath[:len(importPath)-chopped] + "/" + vpath
}
}
return path
diff --git a/src/cmd/go/vendor_test.go b/src/cmd/go/vendor_test.go
index 006a8c9d3f..4cf2b0c3e7 100644
--- a/src/cmd/go/vendor_test.go
+++ b/src/cmd/go/vendor_test.go
@@ -244,6 +244,32 @@ func TestVendorTest2(t *testing.T) {
tg.run("test", "github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx2")
}
+func TestVendorTest3(t *testing.T) {
+ testenv.MustHaveExternalNetwork(t)
+
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.makeTempdir()
+ tg.setenv("GOPATH", tg.path("."))
+ tg.run("get", "github.com/clsung/go-vendor-issue-14613")
+
+ tg.run("build", "-i", "github.com/clsung/go-vendor-issue-14613")
+
+ // test folder should work
+ tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613")
+ tg.run("test", "github.com/clsung/go-vendor-issue-14613")
+
+ // test with specified _test.go should work too
+ tg.cd(filepath.Join(tg.path("."), "src"))
+ tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613/vendor_test.go")
+ tg.run("test", "github.com/clsung/go-vendor-issue-14613/vendor_test.go")
+
+ // test with imported and not used
+ tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go")
+ tg.runFail("test", "github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go")
+ tg.grepStderr("imported and not used:", `should say "imported and not used"`)
+}
+
func TestVendorList(t *testing.T) {
testenv.MustHaveExternalNetwork(t)