mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
unittests: Add os_write test
New os/fs.c functions are now all tested.
This commit is contained in:
parent
4b9d2caec2
commit
3e7c8e7149
@ -410,6 +410,9 @@ describe('fs function', function()
|
|||||||
end
|
end
|
||||||
return ret1, ret2, ret3
|
return ret1, ret2, ret3
|
||||||
end
|
end
|
||||||
|
local function os_write(fd, data)
|
||||||
|
return fs.os_write(fd, data, data and #data or 0)
|
||||||
|
end
|
||||||
|
|
||||||
describe('os_file_exists', function()
|
describe('os_file_exists', function()
|
||||||
it('returns false when given a non-existing file', function()
|
it('returns false when given a non-existing file', function()
|
||||||
@ -666,6 +669,45 @@ describe('fs function', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('os_write', function()
|
||||||
|
-- Function may be absent
|
||||||
|
local file = 'test-unit-os-fs_spec-os_write.dat'
|
||||||
|
|
||||||
|
local s = ''
|
||||||
|
for i = 0, 255 do
|
||||||
|
s = s .. (i == 0 and '\0' or ('%c'):format(i))
|
||||||
|
end
|
||||||
|
local fcontents = s:rep(16)
|
||||||
|
|
||||||
|
before_each(function()
|
||||||
|
local f = io.open(file, 'w')
|
||||||
|
f:write(fcontents)
|
||||||
|
f:close()
|
||||||
|
end)
|
||||||
|
|
||||||
|
after_each(function()
|
||||||
|
os.remove(file)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('can write zero bytes to a file', function()
|
||||||
|
local fd = os_open(file, ffi.C.kO_WRONLY, 0)
|
||||||
|
ok(fd >= 0)
|
||||||
|
eq(0, os_write(fd, ''))
|
||||||
|
eq(0, os_write(fd, nil))
|
||||||
|
eq(fcontents, io.open(file, 'r'):read('*a'))
|
||||||
|
eq(0, os_close(fd))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('can write some data to a file', function()
|
||||||
|
local fd = os_open(file, ffi.C.kO_WRONLY, 0)
|
||||||
|
ok(fd >= 0)
|
||||||
|
eq(3, os_write(fd, 'abc'))
|
||||||
|
eq(4, os_write(fd, ' def'))
|
||||||
|
eq('abc def' .. fcontents:sub(8), io.open(file, 'r'):read('*a'))
|
||||||
|
eq(0, os_close(fd))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe('os_nodetype', function()
|
describe('os_nodetype', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
os.remove('non-existing-file')
|
os.remove('non-existing-file')
|
||||||
|
Loading…
Reference in New Issue
Block a user