Repository: goplus/gop
Pull request #1619 (2024-01-11 02:44:11)

run testdata for gop

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/goplus/gop/pull/1619?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goplus) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`aa1c998`)](https://app.codecov.io/gh/goplus/gop/commit/aa1c99842ab8077ae01de29f060b1712496185b2?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goplus) 91.39% compared to head [(`89fb9c6`)](https://app.codecov.io/gh/goplus/gop/pull/1619?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goplus) 91.39%.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #1619      +/-   ##
==========================================
- Coverage   91.39%   91.39%   -0.01%     
==========================================
  Files          39       38       -1     
  Lines       10260    10258       -2     
==========================================
- Hits         9377     9375       -2     
  Misses        719      719              
  Partials      164      164              
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/goplus/gop/pull/1619?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goplus).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goplus).


Patch:
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 0add4d50..cdf19d39 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -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 ./...
 
diff --git a/all.bash b/all.bash
index 8fe94a61..fad561e8 100755
--- a/all.bash
+++ b/all.bash
@@ -18,4 +18,4 @@
 
 set -ex
 
-go run cmd/make.go --install --autoproxy
+go run cmd/make.go --install --regtest --autoproxy
diff --git a/all.bat b/all.bat
index 5395a855..c21e69d3 100644
--- a/all.bat
+++ b/all.bat
@@ -1,1 +1,1 @@
-go run cmd/make.go --install --autoproxy
+go run cmd/make.go --install --regtest --autoproxy
diff --git a/cmd/internal/mod/tidy.go b/cmd/internal/mod/tidy.go
index 23879dd3..2a79d340 100644
--- a/cmd/internal/mod/tidy.go
+++ b/cmd/internal/mod/tidy.go
@@ -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)
 		}
diff --git a/cmd/make.go b/cmd/make.go
index d04c52c4..6ecf458a 100644
--- a/cmd/make.go
+++ b/cmd/make.go
@@ -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")
@@ -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 != "" {
diff --git a/doc/dsl-vs-sdf.md b/doc/dsl-vs-sdf.md
index f539a4fd..b3df6dfc 100644
--- a/doc/dsl-vs-sdf.md
+++ b/doc/dsl-vs-sdf.md
@@ -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
 ```
 
diff --git a/imp.go b/imp.go
index 0ea6b318..7de0b4b3 100644
--- a/imp.go
+++ b/imp.go
@@ -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:
diff --git a/x/c2go/c2go.go b/x/c2go/c2go.go
index d2240f11..33116cc8 100644
--- a/x/c2go/c2go.go
+++ b/x/c2go/c2go.go
@@ -18,7 +18,6 @@ package c2go
 
 import (
 	"path/filepath"
-	"syscall"
 
 	"github.com/goplus/mod/gopmod"
 )
@@ -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")
diff --git a/x/typesutil/check.go b/x/typesutil/check.go
index 88673790..f9165056 100644
--- a/x/typesutil/check.go
+++ b/x/typesutil/check.go
@@ -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
 }
 


Test patch:
diff --git a/testdata/helloc2go/README.md b/testdata/_helloc2go/README.md
similarity index 100%
rename from testdata/helloc2go/README.md
rename to testdata/_helloc2go/README.md
diff --git a/testdata/_helloc2go/go.mod b/testdata/_helloc2go/go.mod
new file mode 100644
index 00000000..050eb82f
--- /dev/null
+++ b/testdata/_helloc2go/go.mod
@@ -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
+)
diff --git a/testdata/_helloc2go/go.sum b/testdata/_helloc2go/go.sum
new file mode 100644
index 00000000..63c018c3
--- /dev/null
+++ b/testdata/_helloc2go/go.sum
@@ -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=
diff --git a/testdata/helloc2go/hello.gop b/testdata/_helloc2go/hello.gop
similarity index 100%
rename from testdata/helloc2go/hello.gop
rename to testdata/_helloc2go/hello.gop
diff --git a/testdata/_mixgo-complex/bar.go b/testdata/_mixgo-complex/bar.go
new file mode 100644
index 00000000..1711b214
--- /dev/null
+++ b/testdata/_mixgo-complex/bar.go
@@ -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
+}
diff --git a/testdata/_mixgo-complex/foo.gop b/testdata/_mixgo-complex/foo.gop
new file mode 100644
index 00000000..f607a8d1
--- /dev/null
+++ b/testdata/_mixgo-complex/foo.gop
@@ -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)