Skip to content

Commit 3467063

Browse files
committed
Add test for file writing
1 parent 71163b6 commit 3467063

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

oslib_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
 (0)