github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/runtime/lua_test.go (about) 1 package runtime_test 2 3 import ( 4 "fmt" 5 "io" 6 "testing" 7 8 "github.com/arnodel/golua/lib" 9 "github.com/arnodel/golua/luatesting" 10 rt "github.com/arnodel/golua/runtime" 11 ) 12 13 func TestRuntime(t *testing.T) { 14 luatesting.RunLuaTestsInDir(t, "lua", setup) 15 } 16 17 func setup(r *rt.Runtime) func() { 18 rt.SolemnlyDeclareCompliance(rt.ComplyCpuSafe, r.SetEnvGoFunc(r.GlobalEnv(), "testudata", testudata, 1, false)) 19 return lib.LoadAll(r) 20 } 21 22 // This return a test userdata that prints a message when released. Allows testing 23 func testudata(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { 24 arg, err := c.StringArg(0) 25 if err != nil { 26 return nil, err 27 } 28 return c.PushingNext1(t.Runtime, t.NewUserDataValue(&TestUData{val: arg, stdout: t.Stdout}, nil)), nil 29 } 30 31 type TestUData struct { 32 val string 33 stdout io.Writer 34 } 35 36 func (t *TestUData) ReleaseResources(d *rt.UserData) { 37 fmt.Fprintf(t.stdout, "**release %s**\n", t.val) 38 }