github.com/yuin/gopher-lua@v1.1.2-0.20231212122839-2348fd042596/oslib_test.go (about) 1 package lua 2 3 import ( 4 "testing" 5 ) 6 7 // correctly gc-ed. There was a bug in gopher lua where local vars were not being gc-ed in all circumstances. 8 func TestOsWrite(t *testing.T) { 9 s := ` 10 local function write(filename, content) 11 local f = assert(io.open(filename, "w")) 12 f:write(content) 13 assert(f:close()) 14 end 15 16 local filename = os.tmpname() 17 write(filename, "abc") 18 write(filename, "d") 19 local f = assert(io.open(filename, "r")) 20 local content = f:read("*all"):gsub("%s+", "") 21 f:close() 22 os.remove(filename) 23 local expected = "d" 24 if content ~= expected then 25 error(string.format("Invalid content: Expecting \"%s\", got \"%s\"", expected, content)) 26 end 27 ` 28 L := NewState() 29 defer L.Close() 30 if err := L.DoString(s); err != nil { 31 t.Error(err) 32 } 33 }