Skip to content

Commit

Permalink
fix tests by adding -a
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Apr 20, 2024
1 parent 7148c43 commit 0acea3a
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: go build -o /dev/null -v ./cmd/xgo

- name: Test
run: go run ./script/run-test --reset-instrument --debug -v -cover -coverpkg github.com/xhd2015/xgo/runtime/... -coverprofile cover.out
run: go run ./script/run-test --reset-instrument -a --debug -v -cover -coverpkg github.com/xhd2015/xgo/runtime/... -coverprofile cover.out

- name: Merge Coverages
run: go run ./script/cover merge ./cover-runtime.out ./cover-runtime-sub.out -o cover-runtime-merged.out
Expand Down
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import "fmt"

const VERSION = "1.0.25"
const REVISION = "9337223b46e108aefcf60d80512764558965983b+1"
const NUMBER = 191
const REVISION = "7148c433a32baac7170639d32d6eac241b62bd40+1"
const NUMBER = 192

func getRevision() string {
revSuffix := ""
Expand Down
14 changes: 9 additions & 5 deletions patch/syntax/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,8 @@ type DeclInfo struct {
FileIndex int

// this is file name after applied -trimpath
File string
FileRef string
Line int
File string
Line int
}

func (c *DeclInfo) RefName() string {
Expand Down Expand Up @@ -491,11 +490,16 @@ func getFuncDecls(files []*syntax.File, varTrap bool) []*DeclInfo {
var declFuncs []*DeclInfo
for i, f := range files {
var file string
if TrimFilename != nil {
if base.Flag.Std && false {
file = f.Pos().RelFilename()
} else if TrimFilename != nil {
// >= go1.18
file = TrimFilename(f.Pos().Base())
} else {
} else if AbsFilename != nil {
file = AbsFilename(f.Pos().Base().Filename())
} else {
// fallback to default
file = f.Pos().RelFilename()
}
for _, decl := range f.DeclList {
fnDecls := extractFuncDecls(i, f, file, decl, varTrap)
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.25"
const REVISION = "9337223b46e108aefcf60d80512764558965983b+1"
const NUMBER = 191
const REVISION = "7148c433a32baac7170639d32d6eac241b62bd40+1"
const NUMBER = 192

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
63 changes: 48 additions & 15 deletions runtime/test/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,59 @@
package debug

import (
"context"
_ "encoding/json"
_ "io"
_ "io/ioutil"
_ "net"
_ "net/http"
_ "os/exec"
"testing"
"time"
_ "time"

"github.com/xhd2015/xgo/runtime/core"
"github.com/xhd2015/xgo/runtime/trap"
"github.com/xhd2015/xgo/runtime/functab"
)

func TestNowOriginal(t *testing.T) {
var captured bool
trap.AddFuncInterceptor(time.Now, &trap.Interceptor{
Pre: func(ctx context.Context, f *core.FuncInfo, args, result core.Object) (data interface{}, err error) {
if f.Pkg == "time" && f.IdentityName == "Now" {
captured = true
func TestListStdlib(t *testing.T) {
funcs := functab.GetFuncs()

stdPkgs := map[string]bool{
"net/http.Get": true,
}
found, missing := getMissing(funcs, stdPkgs, false)
if len(missing) > 0 {
t.Fatalf("expect func list contains: %v, actual %v", missing, found)
}
}

func getMissing(funcs []*core.FuncInfo, missingPkgs map[string]bool, intf bool) (found []string, missing []string) {
for _, fn := range funcs {
pkg := fn.Pkg
if intf {
if fn.Interface {
// t.Logf("found interface: %v", fn)
key := pkg + "." + fn.RecvType
if _, ok := missingPkgs[key]; ok {
missingPkgs[key] = false
}
}
return nil, nil
},
})
time.Now()
if captured {
t.Fatalf("should not be captured")
continue
}
displayName := fn.DisplayName()
// fmt.Printf("found: %s %s\n", pkg, displayName)
// debug
key := pkg + "." + displayName
_, ok := missingPkgs[key]
if ok {
missingPkgs[key] = false
}
}
for k, ok := range missingPkgs {
if ok {
missing = append(missing, k)
} else {
found = append(found, k)
}
}
return
}
28 changes: 11 additions & 17 deletions runtime/test/func_list/func_list_stdlib_test.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
package func_list

import (
"encoding/json"
"io"
"io/ioutil"
"net"
"net/http"
"os/exec"
_ "encoding/json"
_ "io"
_ "io/ioutil"
_ "net"
_ "net/http"
_ "os/exec"
"testing"
"time"
_ "time"

"github.com/xhd2015/xgo/runtime/functab"
)

var _ http.Request
var _ net.Addr
var _ time.Time
var _ exec.Cmd
var _ = ioutil.ReadAll
var _ = ioutil.ReadFile
var _ = ioutil.ReadDir
var _ = io.ReadAll
var _ json.Encoder

// go run ./cmd/xgo test --project-dir runtime -run TestListStdlib -v ./test/func_list
func TestListStdlib(t *testing.T) {
funcs := functab.GetFuncs()
Expand Down Expand Up @@ -77,6 +67,10 @@ func TestListStdlib(t *testing.T) {
//json
"encoding/json.newTypeEncoder": true,
}
// debug
// stdPkgs = map[string]bool{
// "net/http.Get": true,
// }
found, missing := getMissing(funcs, stdPkgs, false)
if len(missing) > 0 {
t.Fatalf("expect func list contains: %v, actual %v", missing, found)
Expand Down
28 changes: 27 additions & 1 deletion script/run-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import (
//
// runtime test:
// go run ./script/run-test/ --include go1.17.13 --xgo-runtime-test-only -run TestFuncList -v ./test/func_list
//
// runtime sub test:
// go run ./script/run-test/ --include go1.17.13 --xgo-runtime-sub-test-only -run TestFuncList -v ./func_list

// xgo default test:
// go run ./script/run-test/ --include go1.18.10 --xgo-default-test-only -run TestAtomicGenericPtr -v ./test
Expand Down Expand Up @@ -71,6 +74,7 @@ func main() {
var resetInstrument bool
var xgoTestOnly bool
var xgoRuntimeTestOnly bool
var xgoRuntimeSubTestOnly bool
var xgoDefaultTestOnly bool

var debug bool
Expand Down Expand Up @@ -109,18 +113,28 @@ func main() {
if arg == "--xgo-test-only" {
xgoTestOnly = true
xgoRuntimeTestOnly = false
xgoRuntimeSubTestOnly = false
xgoDefaultTestOnly = false
continue
}
if arg == "--xgo-runtime-test-only" {
xgoTestOnly = false
xgoRuntimeTestOnly = true
xgoRuntimeSubTestOnly = false
xgoDefaultTestOnly = false
continue
}
if arg == "--xgo-runtime-sub-test-only" {
xgoTestOnly = false
xgoRuntimeTestOnly = false
xgoRuntimeSubTestOnly = true
xgoDefaultTestOnly = false
continue
}
if arg == "--xgo-default-test-only" {
xgoTestOnly = false
xgoRuntimeTestOnly = false
xgoRuntimeSubTestOnly = false
xgoDefaultTestOnly = true
continue
}
Expand Down Expand Up @@ -250,6 +264,11 @@ func main() {
runDefault = false
} else if xgoRuntimeTestOnly {
runRuntimeTestFlag = true
runRuntimeSubTestFlag = false
runXgoTestFlag = false
runDefault = false
} else if xgoRuntimeSubTestOnly {
runRuntimeTestFlag = false
runRuntimeSubTestFlag = true
runXgoTestFlag = false
runDefault = false
Expand Down Expand Up @@ -381,7 +400,14 @@ func doRunTest(goroot string, kind testKind, args []string, tests []string) erro
} else {
testArgs = append(testArgs, "./test")
testArgs = append(testArgs, "./support/...")
testArgs = append(testArgs, "./cmd/...")
// exclude ./cmd/xgo/runtime_gen
testArgs = append(testArgs, "./cmd/xgo")
testArgs = append(testArgs, "./cmd/xgo/exec_tool/...")
testArgs = append(testArgs, "./cmd/xgo/gen/...")
testArgs = append(testArgs, "./cmd/xgo/patch/...")
testArgs = append(testArgs, "./cmd/xgo/pathsum/...")
testArgs = append(testArgs, "./cmd/xgo/trace/...")
testArgs = append(testArgs, "./cmd/xgo/upgrade/...")
}
case testKind_xgoTest:
testArgs = []string{"run", "-tags", "dev", "./cmd/xgo", "test"}
Expand Down
2 changes: 1 addition & 1 deletion support/fileutil/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func TestCleanSpecial(t *testing.T) {
Res string
}{
{"", ""},
{" ", ""}, // space to _
{" ", "_"}, // space to _
{"/", ""},
{"/a", "a"},
{"C:/a", "Ca"}, // Windows
Expand Down

0 comments on commit 0acea3a

Please sign in to comment.