Skip to content

Commit

Permalink
fix path@patch not use
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Aug 28, 2024
1 parent 77ce770 commit cb3ef8a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
4 changes: 4 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ func (ctx *Context) buildPackage(sp *SourcePackage) (pkg *ssa.Package, err error
}
var addin []*types.Package
for _, pkg := range ctx.Loader.Packages() {
path := pkg.Path()
if _, ok := ctx.pkgs[path]; ok && strings.HasSuffix(path, "@patch") {
continue
}
if !pkg.Complete() {
addin = append(addin, pkg)
}
Expand Down
56 changes: 43 additions & 13 deletions gopbuild/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func gopClTest(t *testing.T, gopcode, expected string) {
}

func gopClTestEx(t *testing.T, filename string, gopcode, expected string) {

Check warning on line 32 in gopbuild/build_test.go

View check run for this annotation

qiniu-x / golangci-lint

gopbuild/build_test.go#L32

test helper function should start from t.Helper() (thelper)
ctx := igop.NewContext(0)
gopClTestWith(t, igop.NewContext(0), filename, gopcode, expected)
}

func gopClTestWith(t *testing.T, ctx *igop.Context, filename string, gopcode, expected string) {
data, err := BuildFile(ctx, filename, gopcode)
if err != nil {
t.Fatalf("build gop error: %v", err)
Expand Down Expand Up @@ -428,9 +431,8 @@ func main() {
`)
}

func TestPackagePatch(t *testing.T) {
ctx := igop.NewContext(0)
RegisterPackagePatch(ctx, "github.com/qiniu/x/gsh", `package gsh
var patch_data = `package gsh

Check warning on line 434 in gopbuild/build_test.go

View check run for this annotation

qiniu-x / golangci-lint

gopbuild/build_test.go#L434

ST1003: should not use underscores in Go names; var patch_data should be patchData (stylecheck)
import "github.com/qiniu/x/gsh"
type Point struct {
Expand All @@ -454,15 +456,21 @@ func Gopt_App_Gopx_GetWidget[T any](app any, name string) {
var _ gsh.App
println(app, name)
}
`)
src := `
`

func TestPackagePatch(t *testing.T) {
ctx := igop.NewContext(0)
err := RegisterPackagePatch(ctx, "github.com/qiniu/x/gsh", patch_data)
if err != nil {
t.Fatal(err)
}
gopClTestWith(t, ctx, "main.gsh", `
getWidget(int,"info")
pt := &Point{100,200}
pt.Info()
println(pt.X)
dump(pt)
`
expected := `package main
`, `package main
import (
"fmt"
Expand Down Expand Up @@ -492,12 +500,34 @@ func (this *App) Main() {
func main() {
new(App).Main()
}
`
data, err := BuildFile(ctx, "main.gsh", src)
`)
}

func TestPackagePatchNoUse(t *testing.T) {
ctx := igop.NewContext(0)
err := RegisterPackagePatch(ctx, "github.com/qiniu/x/gsh", patch_data)
if err != nil {
t.Fatal(err)
}
if string(data) != expected {
t.Fatal("build error:\n", string(data))
}
gopClTestWith(t, ctx, "main.gsh", `
ls "${HOME}"
`, `package main
import "github.com/qiniu/x/gsh"
type App struct {
gsh.App
}
//line main.gsh:2
func (this *App) MainEntry() {
//line main.gsh:2:1
this.Gop_Exec("ls", this.Gop_Env("HOME"))
}
func (this *App) Main() {
gsh.Gopt_App_Main(this)
}
func main() {
new(App).Main()
}
`)
}

0 comments on commit cb3ef8a

Please sign in to comment.