Skip to content

Commit

Permalink
Add test for file writing
Browse files Browse the repository at this point in the history
  • Loading branch information
waschik committed Feb 19, 2023
1 parent 71163b6 commit 3467063
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions oslib_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package lua

import (
"testing"
)

// correctly gc-ed. There was a bug in gopher lua where local vars were not being gc-ed in all circumstances.
func TestOsWrite(t *testing.T) {
s := `
local function write(filename, content)
local f = assert(io.open(filename, "w"))
f:write(content)
assert(f:close())
end
local filename = os.tmpname()
write(filename, "abc")
write(filename, "d")
local f = assert(io.open(filename, "r"))
local content = f:read("*all"):gsub("%s+", "")
f:close()
os.remove(filename)
local expected = "d"
if content ~= expected then
error(string.format("Invalid content: Expecting \"%s\", got \"%s\"", expected, content))
end
`
L := NewState()
defer L.Close()
if err := L.DoString(s); err != nil {
t.Error(err)
}
}

0 comments on commit 3467063

Please sign in to comment.