Skip to content

Commit

Permalink
run testdata for gop (#1619)
Browse files Browse the repository at this point in the history
gop regtests
  • Loading branch information
xushiwei committed Jan 11, 2024
1 parent aa1c998 commit 8ce1b2c
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 23 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ jobs:
git config --global user.name "build robot"
go test -v cmd/make_test.go
- name: Compile gop and related tools
run: go install ./...

- name: Run testcases
run: go test -v -coverprofile="coverage.txt" -covermode=atomic ./...

Expand Down
2 changes: 1 addition & 1 deletion all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

set -ex

go run cmd/make.go --install --autoproxy
go run cmd/make.go --install --regtest --autoproxy
2 changes: 1 addition & 1 deletion all.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
go run cmd/make.go --install --autoproxy
go run cmd/make.go --install --regtest --autoproxy
2 changes: 1 addition & 1 deletion cmd/internal/mod/tidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func runTidy(cmd *base.Command, args []string) {
err := gop.Tidy(".", gopenv.Get())
if err != nil {
if gop.NotFound(err) {
fmt.Fprintln(os.Stderr, "gop.mod not found")
fmt.Fprintln(os.Stderr, "go.mod not found")
} else {
fmt.Fprintln(os.Stderr, err)
}
Expand Down
21 changes: 20 additions & 1 deletion cmd/make.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,28 @@ func releaseNewVersion(tag string) {
println("Released new version:", version)
}

func runRegtests() {
println("\nStart running regtests.")

cmd := exec.Command(filepath.Join(gopRoot, "bin/"+gopBinFiles[0]), "go", "./...")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = filepath.Join(gopRoot, "testdata")
err := cmd.Run()
if err != nil {
code := cmd.ProcessState.ExitCode()
if code == 0 {
code = 1
}
os.Exit(code)
}
}

func main() {
isInstall := flag.Bool("install", false, "Install Go+")
isBuild := flag.Bool("build", false, "Build Go+ tools")
isTest := flag.Bool("test", false, "Run testcases")
isRegtest := flag.Bool("regtest", false, "Run regtests")
isUninstall := flag.Bool("uninstall", false, "Uninstall Go+")
isGoProxy := flag.Bool("proxy", false, "Set GOPROXY for people in China")
isAutoProxy := flag.Bool("autoproxy", false, "Check to set GOPROXY automatically")
Expand All @@ -572,10 +590,11 @@ func main() {
},
isUninstall: uninstall,
isTest: runTestcases,
isRegtest: runRegtests,
}

// Sort flags, for example: install flag should be checked earlier than test flag.
flags := []*bool{isBuild, isInstall, isTest, isUninstall}
flags := []*bool{isBuild, isInstall, isTest, isRegtest, isUninstall}
hasActionDone := false

if *tag != "" {
Expand Down
1 change: 0 additions & 1 deletion doc/dsl-vs-sdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ total 72
-rw-r--r-- 1 xushiwei staff 365 Jun 19 00:25 example.gsh
-rw-r--r-- 1 xushiwei staff 126 Jun 19 09:33 go.mod
-rw-r--r-- 1 xushiwei staff 165 Jun 19 09:33 go.sum
-rw-r--r-- 1 xushiwei staff 110 Jun 19 09:33 gop.mod
-rw-r--r-- 1 xushiwei staff 1938 Jun 19 10:00 gop_autogen.go
```

Expand Down
13 changes: 3 additions & 10 deletions imp.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,9 @@ func (p *Importer) Import(pkgPath string) (pkg *types.Package, err error) {
modDir := ret.ModDir
goModfile := filepath.Join(modDir, "go.mod")
if _, e := os.Lstat(goModfile); e != nil { // no go.mod
gopModfile := filepath.Join(modDir, "gop.mod")
if _, e := os.Lstat(gopModfile); e == nil { // has gop.mod
if err = p.genGoExtern(ret.Dir, isExtern); err != nil {
return
}
} else { // maybe a old Go package without go.mod
os.Chmod(modDir, modWritable)
defer os.Chmod(modDir, modReadonly)
os.WriteFile(goModfile, defaultGoMod(ret.ModPath), 0644)
}
os.Chmod(modDir, modWritable)
defer os.Chmod(modDir, modReadonly)
os.WriteFile(goModfile, defaultGoMod(ret.ModPath), 0644)
}
return p.impFrom.ImportFrom(pkgPath, ret.ModDir, 0)
case gopmod.PkgtModule, gopmod.PkgtLocal:
Expand Down
File renamed without changes.
31 changes: 31 additions & 0 deletions testdata/_helloc2go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module hello2go

go 1.21.1

require github.com/goplus/libc v0.3.15

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/gofuzz v1.0.0 // indirect
github.com/goplus/c2go v0.7.15 // indirect
github.com/goplus/gox v1.12.0 // indirect
github.com/goplus/mod v0.11.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/petermattis/goid v0.0.0-20220331194723-8ee3e6ded87a // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/qiniu/x v1.13.0 // indirect
github.com/stretchr/objx v0.1.0 // indirect
github.com/stretchr/testify v1.3.0 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
)
60 changes: 60 additions & 0 deletions testdata/_helloc2go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/goplus/c2go v0.7.15/go.mod h1:SKSY0OvbO9JBkHRjyiJz3vz0rHpwPETjNj6AQ/rQZOg=
github.com/goplus/gox v1.12.0/go.mod h1:Ek4bXv4xzfBiFuHC6yfkzHXrhUHXfrM9QyXtMusdkGo=
github.com/goplus/libc v0.3.15 h1:xfo4Lc66Sf7Dyel+gAT+5fCG0XOB7PxRE4892MH5zgg=
github.com/goplus/libc v0.3.15/go.mod h1:ExS/KlOepeNJkY10ykY1Qgg6GPql+AItHNNsXuIZwgw=
github.com/goplus/mod v0.11.5/go.mod h1:NDC5E+XOT8vcJCMjqKhLDJHTHX7lyVN4Vbfi2U7dBhs=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/petermattis/goid v0.0.0-20220331194723-8ee3e6ded87a h1:VXRRto5GMJPNfB7MNbUVoFhtxwoYjBEsIt/NpWg42U0=
github.com/petermattis/goid v0.0.0-20220331194723-8ee3e6ded87a/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qiniu/x v1.13.0/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
File renamed without changes.
24 changes: 24 additions & 0 deletions testdata/_mixgo-complex/bar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"io"
"log"
"testing"
)

type ift interface {
io.Closer
f(int) string
g()
}

type impl struct {
a T
}

func Bar(t *testing.T) int {
log.Println("Hello")
t.Log("Hello",
"world")
return 0
}
43 changes: 43 additions & 0 deletions testdata/_mixgo-complex/foo.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Pkg doc

import (
"io"
"log"
)

type ift2 interface {
io.Closer
f(int) string
g()
}

// T doc
type T struct {
io.Closer
}

func (T) Close() (err error) {
log.Println("Hi!")
return
}

func (t T) g() {}

func (t T) f(a int) (b string) {
_ = t.Closer
return
}

func Foo(i *impl) string {
i.a.f(0)
i.a.g()
return ""
}

// foo golang/go#61561: interface instances aren't concurrency-safe
// as they are not completed by the type checker.
func foo(a, b int) string {
return ""
}

println "Hello, world", T{}.f(0)
4 changes: 0 additions & 4 deletions x/c2go/c2go.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package c2go

import (
"path/filepath"
"syscall"

"github.com/goplus/mod/gopmod"
)
Expand All @@ -28,9 +27,6 @@ import (
// LookupPub returns a anonymous function required by cl.NewPackage.
func LookupPub(mod *gopmod.Module) func(pkgPath string) (pubfile string, err error) {
return func(pkgPath string) (pubfile string, err error) {
if mod.File == nil { // no go.mod/gop.mod file
return "", syscall.ENOENT
}
pkg, err := mod.Lookup(pkgPath)
if err == nil {
pubfile = filepath.Join(pkg.Dir, "c2go.a.pub")
Expand Down
2 changes: 1 addition & 1 deletion x/typesutil/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Config struct {
// Default is github.com/goplus/.
C2goBase string

// Mod represents a gop.mod object (optional).
// Mod represents a Go+ module (optional).
Mod *gopmod.Module
}

Expand Down

0 comments on commit 8ce1b2c

Please sign in to comment.