Skip to content

Commit d389a19

Browse files
clsungadg
authored andcommitted
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 <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-on: https://go-review.googlesource.com/22051 Run-TryBot: Andrew Gerrand <[email protected]>
1 parent 2644b76 commit d389a19

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/cmd/go/pkg.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,12 @@ func vendoredImportPath(parent *Package, path string) (found string) {
441441
}
442442
targ := filepath.Join(dir[:i], vpath)
443443
if isDir(targ) && hasGoFiles(targ) {
444+
importPath := parent.ImportPath
445+
if importPath == "command-line-arguments" {
446+
// If parent.ImportPath is 'command-line-arguments'.
447+
// set to relative directory to root (also chopped root directory)
448+
importPath = dir[len(root)+1:]
449+
}
444450
// We started with parent's dir c:\gopath\src\foo\bar\baz\quux\xyzzy.
445451
// We know the import path for parent's dir.
446452
// We chopped off some number of path elements and
@@ -450,14 +456,14 @@ func vendoredImportPath(parent *Package, path string) (found string) {
450456
// (actually the same number of bytes) from parent's import path
451457
// and then append /vendor/path.
452458
chopped := len(dir) - i
453-
if chopped == len(parent.ImportPath)+1 {
459+
if chopped == len(importPath)+1 {
454460
// We walked up from c:\gopath\src\foo\bar
455461
// and found c:\gopath\src\vendor\path.
456462
// We chopped \foo\bar (length 8) but the import path is "foo/bar" (length 7).
457463
// Use "vendor/path" without any prefix.
458464
return vpath
459465
}
460-
return parent.ImportPath[:len(parent.ImportPath)-chopped] + "/" + vpath
466+
return importPath[:len(importPath)-chopped] + "/" + vpath
461467
}
462468
}
463469
return path

src/cmd/go/vendor_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,32 @@ func TestVendorTest2(t *testing.T) {
244244
tg.run("test", "github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx2")
245245
}
246246

247+
func TestVendorTest3(t *testing.T) {
248+
testenv.MustHaveExternalNetwork(t)
249+
250+
tg := testgo(t)
251+
defer tg.cleanup()
252+
tg.makeTempdir()
253+
tg.setenv("GOPATH", tg.path("."))
254+
tg.run("get", "github.com/clsung/go-vendor-issue-14613")
255+
256+
tg.run("build", "-i", "github.com/clsung/go-vendor-issue-14613")
257+
258+
// test folder should work
259+
tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613")
260+
tg.run("test", "github.com/clsung/go-vendor-issue-14613")
261+
262+
// test with specified _test.go should work too
263+
tg.cd(filepath.Join(tg.path("."), "src"))
264+
tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613/vendor_test.go")
265+
tg.run("test", "github.com/clsung/go-vendor-issue-14613/vendor_test.go")
266+
267+
// test with imported and not used
268+
tg.run("test", "-i", "github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go")
269+
tg.runFail("test", "github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go")
270+
tg.grepStderr("imported and not used:", `should say "imported and not used"`)
271+
}
272+
247273
func TestVendorList(t *testing.T) {
248274
testenv.MustHaveExternalNetwork(t)
249275

0 commit comments

Comments
 (0)