Skip to content

Commit

Permalink
fix #1056, extract: replace the code for get package name.
Browse files Browse the repository at this point in the history
fix #1056
  • Loading branch information
For-ACGN authored Mar 23, 2021
1 parent ec5392d commit 84ad467
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
5 changes: 2 additions & 3 deletions extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"io"
"math/big"
"os"
"path"
"path/filepath"
"regexp"
"runtime"
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions extract/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions extract/testdata/6/src/guthib.com/bar/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"guthib.com/baz"
)

func main() {
baz.Hello()
}
5 changes: 5 additions & 0 deletions extract/testdata/6/src/guthib.com/baz-baz/baz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package baz

func Hello() {
println("HELLO")
}
1 change: 1 addition & 0 deletions extract/testdata/6/src/guthib.com/baz-baz/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module guthib.com/baz-baz

0 comments on commit 84ad467

Please sign in to comment.