Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix path@patch not use #277

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -29,8 +29,11 @@
gopClTestEx(t, "main.gop", gopcode, expected)
}

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 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 @@
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 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()
}
`)
}
Loading