forked from yuin/gopher-lua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oslib_test.go
33 lines (30 loc) · 774 Bytes
/
oslib_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)
}
}