Skip to content

Commit

Permalink
add TestTrapOverlay
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Apr 2, 2024
1 parent 9144e01 commit f3d7271
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
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.11"
const REVISION = "cbc3deeffd52cddb0f9a845c0e079a658f8c8325+1"
const NUMBER = 145
const REVISION = "9144e01f0f4847402d24c04997c8077fbb3ae85e+1"
const NUMBER = 146

func getRevision() string {
return fmt.Sprintf("%s %s BUILD_%d", VERSION, REVISION, NUMBER)
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.11"
const REVISION = "cbc3deeffd52cddb0f9a845c0e079a658f8c8325+1"
const NUMBER = 145
const REVISION = "9144e01f0f4847402d24c04997c8077fbb3ae85e+1"
const NUMBER = 146

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
42 changes: 42 additions & 0 deletions runtime/test/trap/trap_overlay_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// when multiple interceptors added, the order is reversed
package trap

import (
"context"
"testing"

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

func TestTrapOverlay(t *testing.T) {
trap.AddInterceptor(&trap.Interceptor{
Pre: func(ctx context.Context, f *core.FuncInfo, args, result core.Object) (data interface{}, err error) {
if f.IdentityName == "testOverlay" {
panic("first trap should not be called")
}
return nil, nil
},
})

// overlay
var trapCalled bool
trap.AddInterceptor(&trap.Interceptor{
Pre: func(ctx context.Context, f *core.FuncInfo, args, result core.Object) (data interface{}, err error) {
if f.IdentityName == "testOverlay" {
trapCalled = true
return nil, trap.ErrAbort
}
return
},
})
testOverlay()

if !trapCalled {
t.Fatalf("expect trap to have been called, actually not called")
}
}

func testOverlay() {

}

0 comments on commit f3d7271

Please sign in to comment.