diff --git a/extract/extract.go b/extract/extract.go index 7444fff40..64b1d2a98 100644 --- a/extract/extract.go +++ b/extract/extract.go @@ -16,7 +16,6 @@ import ( "io" "math/big" "os" - "path" "path/filepath" "regexp" "runtime" @@ -167,8 +166,8 @@ func (e *Extractor) genContent(importPath string, p *types.Package) ([]byte, err continue } - pname := path.Base(importPath) + "." + name - if rname := path.Base(importPath) + name; restricted[rname] { + pname := p.Name() + "." + name + if rname := p.Name() + name; restricted[rname] { // Restricted symbol, locally provided by stdlib wrapper. pname = rname } diff --git a/extract/extract_test.go b/extract/extract_test.go index cb4b9cad0..866b10d10 100644 --- a/extract/extract_test.go +++ b/extract/extract_test.go @@ -78,6 +78,13 @@ func TestPackages(t *testing.T) { importPath: "guthib.com/baz", expected: expectedOutput, }, + { + desc: "using relative path, package name is not same as import path", + wd: "./testdata/6/src/guthib.com/bar", + arg: "../baz-baz", + importPath: "guthib.com/baz", + expected: expectedOutput, + }, } for _, test := range testCases { diff --git a/extract/testdata/6/src/guthib.com/bar/main.go b/extract/testdata/6/src/guthib.com/bar/main.go new file mode 100644 index 000000000..03db97766 --- /dev/null +++ b/extract/testdata/6/src/guthib.com/bar/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "guthib.com/baz" +) + +func main() { + baz.Hello() +} diff --git a/extract/testdata/6/src/guthib.com/baz-baz/baz.go b/extract/testdata/6/src/guthib.com/baz-baz/baz.go new file mode 100644 index 000000000..3b008fa72 --- /dev/null +++ b/extract/testdata/6/src/guthib.com/baz-baz/baz.go @@ -0,0 +1,5 @@ +package baz + +func Hello() { + println("HELLO") +} diff --git a/extract/testdata/6/src/guthib.com/baz-baz/go.mod b/extract/testdata/6/src/guthib.com/baz-baz/go.mod new file mode 100644 index 000000000..655c874e7 --- /dev/null +++ b/extract/testdata/6/src/guthib.com/baz-baz/go.mod @@ -0,0 +1 @@ +module guthib.com/baz-baz \ No newline at end of file