gosh/interceptor/interceptor_test.go

25 lines
484 B
Go

package interceptor
import (
"path/filepath"
"runtime"
"testing"
"github.com/mattn/anko/env"
)
func TestAnkointerceptor_ExecRequire(t *testing.T) {
// 创建测试环境
e := env.NewEnv()
// 创建拦截器实例
interceptor := NewAnkointerceptor(e)
_, file, _, _ := runtime.Caller(0)
scriptPath := filepath.Join(filepath.Dir(file), "testdata/test_caller.ank")
v, _ := interceptor.Exec(scriptPath)
if v != "Hello, tom from test script" {
t.Errorf("Not equal")
}
}