oslib_test.go 774 B

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