github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/luatesting/runtests_test.go (about) 1 package luatesting_test 2 3 import ( 4 "runtime" 5 "testing" 6 7 "github.com/arnodel/golua/lib" 8 "github.com/arnodel/golua/luatesting" 9 10 rt "github.com/arnodel/golua/runtime" 11 ) 12 13 func TestRunLuaTest(t *testing.T) { 14 src := ` 15 print("hello, world!") 16 --> =hello, world! 17 18 print(1+2) 19 --> =3 20 21 print(1 == 1.0) 22 --> =true 23 24 error("hello") 25 --> ~!!! runtime:.* 26 ` 27 err := luatesting.RunLuaTest([]byte(src), lib.LoadAll) 28 if err != nil { 29 t.Fatal(err) 30 } 31 } 32 33 func TestLua(t *testing.T) { 34 luatesting.RunLuaTestsInDir(t, "lua", setup) 35 } 36 37 func setup(r *rt.Runtime) func() { 38 cleanup := lib.LoadAll(r) 39 g := r.GlobalEnv() 40 r.SetEnv(g, "goos", rt.StringValue(runtime.GOOS)) 41 return cleanup 42 }