github.com/lunixbochs/luaish@v0.0.0-20181206234029-50b0cd6cedf4/script_test.go (about) 1 package lua 2 3 import ( 4 "fmt" 5 "github.com/lunixbochs/luaish/parse" 6 "os" 7 "testing" 8 ) 9 10 const maxMemory = 40 11 12 var gluaTests []string = []string{ 13 "base.lua", 14 "coroutine.lua", 15 "db.lua", 16 "issues.lua", 17 "os.lua", 18 "table.lua", 19 "vm.lua", 20 "math.lua", 21 "strings.lua", 22 } 23 24 var luaTests []string = []string{ 25 "attrib.lua", 26 "calls.lua", 27 "closure.lua", 28 "constructs.lua", 29 "events.lua", 30 "literals.lua", 31 "locals.lua", 32 "math.lua", 33 "sort.lua", 34 "strings.lua", 35 "vararg.lua", 36 "pm.lua", 37 "files.lua", 38 } 39 40 func testScriptCompile(t *testing.T, script string) { 41 file, err := os.Open(script) 42 if err != nil { 43 t.Fatal(err) 44 return 45 } 46 chunk, err2 := parse.Parse(file, script) 47 if err2 != nil { 48 t.Fatal(err2) 49 return 50 } 51 parse.Dump(chunk) 52 proto, err3 := Compile(chunk, script) 53 if err3 != nil { 54 t.Fatal(err3) 55 return 56 } 57 proto.String() 58 } 59 60 func testScriptDir(t *testing.T, tests []string, directory string) { 61 if err := os.Chdir(directory); err != nil { 62 t.Error(err) 63 } 64 defer os.Chdir("..") 65 for _, script := range tests { 66 fmt.Printf("testing %s/%s\n", directory, script) 67 testScriptCompile(t, script) 68 L := NewState(Options{ 69 RegistrySize: 1024 * 20, 70 CallStackSize: 1024, 71 }) 72 L.SetMx(maxMemory) 73 if err := L.DoFile(script); err != nil { 74 t.Error(err) 75 } 76 L.Close() 77 } 78 } 79 80 func TestGlua(t *testing.T) { 81 testScriptDir(t, gluaTests, "_glua-tests") 82 } 83 84 func TestLua(t *testing.T) { 85 testScriptDir(t, luaTests, "_lua5.1-tests") 86 }