aboutsummaryrefslogtreecommitdiff
path: root/test/unit/os
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/os')
-rw-r--r--test/unit/os/env_spec.lua19
-rw-r--r--test/unit/os/fileio_spec.lua155
-rw-r--r--test/unit/os/fs_spec.lua285
-rw-r--r--test/unit/os/shell_spec.lua50
4 files changed, 224 insertions, 285 deletions
diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua
index 24b92edee5..2c638fcb37 100644
--- a/test/unit/os/env_spec.lua
+++ b/test/unit/os/env_spec.lua
@@ -62,7 +62,7 @@ describe('env.c', function()
eq('non-empty', os.getenv(name))
end)
- itp("`overwrite` behavior", function()
+ itp('`overwrite` behavior', function()
local name = 'NVIM_UNIT_TEST_SETENV_2N'
local value = 'NVIM_UNIT_TEST_SETENV_2V'
local value_updated = 'NVIM_UNIT_TEST_SETENV_2V_UPDATED'
@@ -79,7 +79,7 @@ describe('env.c', function()
itp('appends :/foo/bar to $PATH', function()
local original_path = os.getenv('PATH')
eq(true, cimp.os_setenv_append_path(to_cstr('/foo/bar/baz.exe')))
- eq(original_path..':/foo/bar', os.getenv('PATH'))
+ eq(original_path .. ':/foo/bar', os.getenv('PATH'))
end)
itp('avoids redundant separator when appending to $PATH #7377', function()
@@ -166,7 +166,7 @@ describe('env.c', function()
local test_value = 'NVIM_UNIT_TEST_GETENVNAME_AT_INDEX_1V'
os_setenv(test_name, test_value, 1)
local i = 0
- local names = { }
+ local names = {}
local found_name = false
local name = cimp.os_getenvname_at_index(i)
while name ~= NULL do
@@ -245,7 +245,7 @@ describe('env.c', function()
local input = '~/foo ~ foo'
local homedir = cstr(255, '')
cimp.expand_env_esc(to_cstr('~'), homedir, 255, false, true, NULL)
- local output_expected = ffi.string(homedir) .. "/foo ~ foo"
+ local output_expected = ffi.string(homedir) .. '/foo ~ foo'
local output = cstr(255, '')
cimp.expand_env_esc(to_cstr(input), output, 255, false, true, NULL)
eq(ffi.string(output), ffi.string(output_expected))
@@ -256,7 +256,7 @@ describe('env.c', function()
local dst = cstr(255, '')
cimp.expand_env_esc(to_cstr('~'), dst, 255, false, true, NULL)
local homedir = ffi.string(dst)
- local output_expected = homedir .. "/foo " .. homedir .. " foo"
+ local output_expected = homedir .. '/foo ' .. homedir .. ' foo'
local output = cstr(255, '')
cimp.expand_env_esc(input, output, 255, false, false, NULL)
eq(output_expected, ffi.string(output))
@@ -267,8 +267,9 @@ describe('env.c', function()
cimp.os_get_username(name_out, 100)
local curuser = ffi.string(name_out)
- local src = to_cstr("~"..curuser.."/Vcs/django-rest-framework/rest_framework/renderers.py")
- local dst = cstr(256, "~"..curuser)
+ local src =
+ to_cstr('~' .. curuser .. '/Vcs/django-rest-framework/rest_framework/renderers.py')
+ local dst = cstr(256, '~' .. curuser)
cimp.expand_env_esc(src, dst, 256, false, false, NULL)
local len = string.len(ffi.string(dst))
assert.True(len > 56)
@@ -283,7 +284,7 @@ describe('env.c', function()
cimp.expand_env_esc(input, output, 5, false, true, NULL)
-- Make sure the first few characters are copied properly and that there is a
-- terminating null character
- for i=0,3 do
+ for i = 0, 3 do
eq(input[i], output[i])
end
eq(0, output[4])
@@ -304,7 +305,7 @@ describe('env.c', function()
-- terminating null character
-- expand_env_esc SHOULD NOT expand the variable if there is not enough space to
-- contain the result
- for i=0,3 do
+ for i = 0, 3 do
eq(output[i], input[i])
end
eq(output[4], 0)
diff --git a/test/unit/os/fileio_spec.lua b/test/unit/os/fileio_spec.lua
index fd30ca70da..617141fd3a 100644
--- a/test/unit/os/fileio_spec.lua
+++ b/test/unit/os/fileio_spec.lua
@@ -1,4 +1,4 @@
-local luv = require('luv')
+local uv = vim.uv
local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
@@ -26,7 +26,7 @@ local linkb = dir .. '/broken.lnk'
local filec = dir .. '/created-file.dat'
before_each(function()
- mkdir(dir);
+ mkdir(dir)
local f1 = io.open(file1, 'w')
f1:write(fcontents)
@@ -36,8 +36,8 @@ before_each(function()
f2:write(fcontents)
f2:close()
- luv.fs_symlink('file1.dat', linkf)
- luv.fs_symlink('broken.dat', linkb)
+ uv.fs_symlink('file1.dat', linkf)
+ uv.fs_symlink('broken.dat', linkb)
end)
after_each(function()
@@ -46,7 +46,7 @@ after_each(function()
os.remove(linkf)
os.remove(linkb)
os.remove(filec)
- luv.fs_rmdir(dir)
+ uv.fs_rmdir(dir)
end)
local function file_open(fname, flags, mode)
@@ -55,32 +55,16 @@ local function file_open(fname, flags, mode)
return ret1, ret2
end
-local function file_open_new(fname, flags, mode)
- local ret1 = ffi.new('int[?]', 1, {0})
- local ret2 = ffi.gc(m.file_open_new(ret1, fname, flags, mode), nil)
- return ret1[0], ret2
-end
-
local function file_open_fd(fd, flags)
local ret2 = ffi.new('FileDescriptor')
local ret1 = m.file_open_fd(ret2, fd, flags)
return ret1, ret2
end
-local function file_open_fd_new(fd, flags)
- local ret1 = ffi.new('int[?]', 1, {0})
- local ret2 = ffi.gc(m.file_open_fd_new(ret1, fd, flags), nil)
- return ret1[0], ret2
-end
-
local function file_write(fp, buf)
return m.file_write(fp, buf, #buf)
end
-local function msgpack_file_write(fp, buf)
- return m.msgpack_file_write(fp, buf, #buf)
-end
-
local function file_read(fp, size)
local buf = nil
if size == nil then
@@ -116,37 +100,17 @@ describe('file_open_fd', function()
local fd = m.os_open(file1, m.kO_RDONLY, 0)
local err, fp = file_open_fd(fd, m.kFileReadOnly)
eq(0, err)
- eq({#fcontents, fcontents}, {file_read(fp, #fcontents)})
+ eq({ #fcontents, fcontents }, { file_read(fp, #fcontents) })
eq(0, m.file_close(fp, false))
end)
itp('can use file descriptor returned by os_open for writing', function()
- eq(nil, luv.fs_stat(filec))
+ eq(nil, uv.fs_stat(filec))
local fd = m.os_open(filec, m.kO_WRONLY + m.kO_CREAT, 384)
local err, fp = file_open_fd(fd, m.kFileWriteOnly)
eq(0, err)
eq(4, file_write(fp, 'test'))
eq(0, m.file_close(fp, false))
- eq(4, luv.fs_stat(filec).size)
- eq('test', io.open(filec):read('*a'))
- end)
-end)
-
-describe('file_open_fd_new', function()
- itp('can use file descriptor returned by os_open for reading', function()
- local fd = m.os_open(file1, m.kO_RDONLY, 0)
- local err, fp = file_open_fd_new(fd, m.kFileReadOnly)
- eq(0, err)
- eq({#fcontents, fcontents}, {file_read(fp, #fcontents)})
- eq(0, m.file_free(fp, false))
- end)
- itp('can use file descriptor returned by os_open for writing', function()
- eq(nil, luv.fs_stat(filec))
- local fd = m.os_open(filec, m.kO_WRONLY + m.kO_CREAT, 384)
- local err, fp = file_open_fd_new(fd, m.kFileWriteOnly)
- eq(0, err)
- eq(4, file_write(fp, 'test'))
- eq(0, m.file_free(fp, false))
- eq(4, luv.fs_stat(filec).size)
+ eq(4, uv.fs_stat(filec).size)
eq('test', io.open(filec):read('*a'))
end)
end)
@@ -155,7 +119,7 @@ describe('file_open', function()
itp('can create a rwx------ file with kFileCreate', function()
local err, fp = file_open(filec, m.kFileCreate, 448)
eq(0, err)
- local attrs = luv.fs_stat(filec)
+ local attrs = uv.fs_stat(filec)
eq(33216, attrs.mode)
eq(0, m.file_close(fp, false))
end)
@@ -163,7 +127,7 @@ describe('file_open', function()
itp('can create a rw------- file with kFileCreate', function()
local err, fp = file_open(filec, m.kFileCreate, 384)
eq(0, err)
- local attrs = luv.fs_stat(filec)
+ local attrs = uv.fs_stat(filec)
eq(33152, attrs.mode)
eq(0, m.file_close(fp, false))
end)
@@ -171,7 +135,7 @@ describe('file_open', function()
itp('can create a rwx------ file with kFileCreateOnly', function()
local err, fp = file_open(filec, m.kFileCreateOnly, 448)
eq(0, err)
- local attrs = luv.fs_stat(filec)
+ local attrs = uv.fs_stat(filec)
eq(33216, attrs.mode)
eq(0, m.file_close(fp, false))
end)
@@ -179,7 +143,7 @@ describe('file_open', function()
itp('can create a rw------- file with kFileCreateOnly', function()
local err, fp = file_open(filec, m.kFileCreateOnly, 384)
eq(0, err)
- local attrs = luv.fs_stat(filec)
+ local attrs = uv.fs_stat(filec)
eq(33152, attrs.mode)
eq(0, m.file_close(fp, false))
end)
@@ -193,7 +157,9 @@ describe('file_open', function()
local err, _ = file_open(linkf, m.kFileNoSymlink, 384)
-- err is UV_EMLINK in FreeBSD, but if I use `ok(err == m.UV_ELOOP or err ==
-- m.UV_EMLINK)`, then I loose the ability to see actual `err` value.
- if err ~= m.UV_ELOOP then eq(m.UV_EMLINK, err) end
+ if err ~= m.UV_ELOOP then
+ eq(m.UV_EMLINK, err)
+ end
end)
itp('can open an existing file write-only with kFileCreate', function()
@@ -229,7 +195,7 @@ describe('file_open', function()
eq(0, err)
eq(true, fp.wr)
eq(0, m.file_close(fp, false))
- local attrs = luv.fs_stat(file1)
+ local attrs = uv.fs_stat(file1)
eq(0, attrs.size)
end)
@@ -238,24 +204,23 @@ describe('file_open', function()
eq(0, err)
eq(true, fp.wr)
eq(0, m.file_close(fp, false))
- local attrs = luv.fs_stat(file1)
+ local attrs = uv.fs_stat(file1)
eq(4096, attrs.size)
end)
itp('fails to create a file with just kFileWriteOnly', function()
local err, _ = file_open(filec, m.kFileWriteOnly, 384)
eq(m.UV_ENOENT, err)
- local attrs = luv.fs_stat(filec)
+ local attrs = uv.fs_stat(filec)
eq(nil, attrs)
end)
- itp('can truncate an existing file with kFileTruncate when opening a symlink',
- function()
+ itp('can truncate an existing file with kFileTruncate when opening a symlink', function()
local err, fp = file_open(linkf, m.kFileTruncate, 384)
eq(0, err)
eq(true, fp.wr)
eq(0, m.file_close(fp, false))
- local attrs = luv.fs_stat(file1)
+ local attrs = uv.fs_stat(file1)
eq(0, attrs.size)
end)
@@ -275,42 +240,15 @@ describe('file_open', function()
end)
end)
-describe('file_open_new', function()
- itp('can open a file read-only', function()
- local err, fp = file_open_new(file1, 0, 384)
- eq(0, err)
- eq(false, fp.wr)
- eq(0, m.file_free(fp, false))
- end)
-
- itp('fails to open an existing file with kFileCreateOnly', function()
- local err, fp = file_open_new(file1, m.kFileCreateOnly, 384)
- eq(m.UV_EEXIST, err)
- eq(nil, fp)
- end)
-end)
-
describe('file_close', function()
itp('can flush writes to disk also with true argument', function()
local err, fp = file_open(filec, m.kFileCreateOnly, 384)
eq(0, err)
local wsize = file_write(fp, 'test')
eq(4, wsize)
- eq(0, luv.fs_stat(filec).size)
+ eq(0, uv.fs_stat(filec).size)
eq(0, m.file_close(fp, true))
- eq(wsize, luv.fs_stat(filec).size)
- end)
-end)
-
-describe('file_free', function()
- itp('can flush writes to disk also with true argument', function()
- local err, fp = file_open_new(filec, m.kFileCreateOnly, 384)
- eq(0, err)
- local wsize = file_write(fp, 'test')
- eq(4, wsize)
- eq(0, luv.fs_stat(filec).size)
- eq(0, m.file_free(fp, true))
- eq(wsize, luv.fs_stat(filec).size)
+ eq(wsize, uv.fs_stat(filec).size)
end)
end)
@@ -319,12 +257,12 @@ describe('file_fsync', function()
local err, fp = file_open(filec, m.kFileCreateOnly, 384)
eq(0, file_fsync(fp))
eq(0, err)
- eq(0, luv.fs_stat(filec).size)
+ eq(0, uv.fs_stat(filec).size)
local wsize = file_write(fp, 'test')
eq(4, wsize)
- eq(0, luv.fs_stat(filec).size)
+ eq(0, uv.fs_stat(filec).size)
eq(0, file_fsync(fp))
- eq(wsize, luv.fs_stat(filec).size)
+ eq(wsize, uv.fs_stat(filec).size)
eq(0, m.file_close(fp, false))
end)
end)
@@ -334,12 +272,12 @@ describe('file_flush', function()
local err, fp = file_open(filec, m.kFileCreateOnly, 384)
eq(0, file_flush(fp))
eq(0, err)
- eq(0, luv.fs_stat(filec).size)
+ eq(0, uv.fs_stat(filec).size)
local wsize = file_write(fp, 'test')
eq(4, wsize)
- eq(0, luv.fs_stat(filec).size)
+ eq(0, uv.fs_stat(filec).size)
eq(0, file_flush(fp))
- eq(wsize, luv.fs_stat(filec).size)
+ eq(wsize, uv.fs_stat(filec).size)
eq(0, m.file_close(fp, false))
end)
end)
@@ -356,10 +294,9 @@ describe('file_read', function()
local exp_s = fcontents:sub(shift + 1, shift + size)
if shift + size >= #fcontents then
exp_err = #fcontents - shift
- exp_s = (fcontents:sub(shift + 1, shift + size)
- .. (('\0'):rep(size - exp_err)))
+ exp_s = (fcontents:sub(shift + 1, shift + size) .. (('\0'):rep(size - exp_err)))
end
- eq({exp_err, exp_s}, {file_read(fp, size)})
+ eq({ exp_err, exp_s }, { file_read(fp, size) })
shift = shift + size
end
eq(0, m.file_close(fp, false))
@@ -369,8 +306,8 @@ describe('file_read', function()
local err, fp = file_open(file1, 0, 384)
eq(0, err)
eq(false, fp.wr)
- eq({#fcontents, fcontents}, {file_read(fp, #fcontents)})
- eq({0, ('\0'):rep(#fcontents)}, {file_read(fp, #fcontents)})
+ eq({ #fcontents, fcontents }, { file_read(fp, #fcontents) })
+ eq({ 0, ('\0'):rep(#fcontents) }, { file_read(fp, #fcontents) })
eq(0, m.file_close(fp, false))
end)
@@ -378,9 +315,8 @@ describe('file_read', function()
local err, fp = file_open(file1, 0, 384)
eq(0, err)
eq(false, fp.wr)
- eq({5, fcontents:sub(1, 5)}, {file_read(fp, 5)})
- eq({#fcontents - 5, fcontents:sub(6) .. (('\0'):rep(5))},
- {file_read(fp, #fcontents)})
+ eq({ 5, fcontents:sub(1, 5) }, { file_read(fp, 5) })
+ eq({ #fcontents - 5, fcontents:sub(6) .. (('\0'):rep(5)) }, { file_read(fp, #fcontents) })
eq(0, m.file_close(fp, false))
end)
@@ -395,10 +331,9 @@ describe('file_read', function()
local exp_s = fcontents:sub(shift + 1, shift + size)
if shift + size >= #fcontents then
exp_err = #fcontents - shift
- exp_s = (fcontents:sub(shift + 1, shift + size)
- .. (('\0'):rep(size - exp_err)))
+ exp_s = (fcontents:sub(shift + 1, shift + size) .. (('\0'):rep(size - exp_err)))
end
- eq({exp_err, exp_s}, {file_read(fp, size)})
+ eq({ exp_err, exp_s }, { file_read(fp, size) })
shift = shift + size
end
eq(0, m.file_close(fp, false))
@@ -413,7 +348,7 @@ describe('file_write', function()
local wr = file_write(fp, fcontents)
eq(#fcontents, wr)
eq(0, m.file_close(fp, false))
- eq(wr, luv.fs_stat(filec).size)
+ eq(wr, uv.fs_stat(filec).size)
eq(fcontents, io.open(filec):read('*a'))
end)
@@ -430,7 +365,7 @@ describe('file_write', function()
shift = shift + size
end
eq(0, m.file_close(fp, false))
- eq(#fcontents, luv.fs_stat(filec).size)
+ eq(#fcontents, uv.fs_stat(filec).size)
eq(fcontents, io.open(filec):read('*a'))
end)
@@ -447,19 +382,7 @@ describe('file_write', function()
shift = shift + size
end
eq(0, m.file_close(fp, false))
- eq(#fcontents, luv.fs_stat(filec).size)
- eq(fcontents, io.open(filec):read('*a'))
- end)
-end)
-
-describe('msgpack_file_write', function()
- itp('can write the whole file at once', function()
- local err, fp = file_open(filec, m.kFileCreateOnly, 384)
- eq(0, err)
- eq(true, fp.wr)
- local wr = msgpack_file_write(fp, fcontents)
- eq(0, wr)
- eq(0, m.file_close(fp, false))
+ eq(#fcontents, uv.fs_stat(filec).size)
eq(fcontents, io.open(filec):read('*a'))
end)
end)
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua
index 8f45d2b0c7..c15cd12fef 100644
--- a/test/unit/os/fs_spec.lua
+++ b/test/unit/os/fs_spec.lua
@@ -1,4 +1,4 @@
-local luv = require('luv')
+local uv = vim.uv
local bit = require('bit')
local helpers = require('test.unit.helpers')(after_each)
@@ -17,7 +17,7 @@ local OK = helpers.OK
local FAIL = helpers.FAIL
local NULL = helpers.NULL
local mkdir = helpers.mkdir
-local endswith = helpers.endswith
+local endswith = vim.endswith
local NODE_NORMAL = 0
local NODE_WRITABLE = 1
@@ -46,11 +46,11 @@ local function unset_bit(number, to_unset)
end
local function assert_file_exists(filepath)
- neq(nil, luv.fs_stat(filepath))
+ neq(nil, uv.fs_stat(filepath))
end
local function assert_file_does_not_exist(filepath)
- eq(nil, luv.fs_stat(filepath))
+ eq(nil, uv.fs_stat(filepath))
end
local function os_setperm(filename, perm)
@@ -68,14 +68,14 @@ describe('fs.c', function()
end
before_each(function()
- mkdir('unit-test-directory');
+ mkdir('unit-test-directory')
io.open('unit-test-directory/test.file', 'w'):close()
io.open('unit-test-directory/test_2.file', 'w'):close()
- luv.fs_symlink('test.file', 'unit-test-directory/test_link.file')
+ uv.fs_symlink('test.file', 'unit-test-directory/test_link.file')
- luv.fs_symlink('non_existing_file.file', 'unit-test-directory/test_broken_link.file')
+ uv.fs_symlink('non_existing_file.file', 'unit-test-directory/test_broken_link.file')
-- The tests are invoked with an absolute path to `busted` executable.
absolute_executable = arg[0]
-- Split the absolute_executable path into a directory and filename.
@@ -88,19 +88,19 @@ describe('fs.c', function()
os.remove('unit-test-directory/test_link.file')
os.remove('unit-test-directory/test_hlink.file')
os.remove('unit-test-directory/test_broken_link.file')
- luv.fs_rmdir('unit-test-directory')
+ uv.fs_rmdir('unit-test-directory')
end)
describe('os_dirname', function()
itp('returns OK and writes current directory to the buffer', function()
- local length = string.len(luv.cwd()) + 1
+ local length = string.len(uv.cwd()) + 1
local buf = cstr(length, '')
eq(OK, fs.os_dirname(buf, length))
- eq(luv.cwd(), ffi.string(buf))
+ eq(uv.cwd(), ffi.string(buf))
end)
itp('returns FAIL if the buffer is too small', function()
- local length = string.len(luv.cwd()) + 1
+ local length = string.len(uv.cwd()) + 1
local buf = cstr(length - 1, '')
eq(FAIL, fs.os_dirname(buf, length - 1))
end)
@@ -115,8 +115,8 @@ describe('fs.c', function()
eq(OK, fs.os_dirname(expected_cwd, length))
-- os_chdir returns 0 for success, not OK (1).
- neq(0, fs.os_chdir('~')) -- fail
- neq(0, fs.os_chdir('~/')) -- fail
+ neq(0, fs.os_chdir('~')) -- fail
+ neq(0, fs.os_chdir('~/')) -- fail
eq(OK, fs.os_dirname(cwd, length))
-- CWD did not change.
@@ -197,24 +197,24 @@ describe('fs.c', function()
itp('returns the absolute path when given an executable inside $PATH', function()
local fullpath = exe('ls')
- eq(1, fs.path_is_absolute(to_cstr(fullpath)))
+ eq(true, fs.path_is_absolute(to_cstr(fullpath)))
end)
itp('returns the absolute path when given an executable relative to the current dir', function()
- local old_dir = luv.cwd()
+ local old_dir = uv.cwd()
- luv.chdir(directory)
+ uv.chdir(directory)
-- Rely on currentdir to resolve symlinks, if any. Testing against
-- the absolute path taken from arg[0] may result in failure where
-- the path has a symlink in it.
- local canonical = luv.cwd() .. '/' .. executable_name
+ local canonical = uv.cwd() .. '/' .. executable_name
local expected = exe(canonical)
local relative_executable = './' .. executable_name
local res = exe(relative_executable)
-- Don't test yet; we need to chdir back first.
- luv.chdir(old_dir)
+ uv.chdir(old_dir)
eq(expected, res)
end)
end)
@@ -276,39 +276,42 @@ describe('fs.c', function()
describe('os_fchown', function()
local filename = 'unit-test-directory/test.file'
itp('does not change owner and group if respective IDs are equal to -1', function()
- local uid = luv.fs_stat(filename).uid
- local gid = luv.fs_stat(filename).gid
+ local uid = uv.fs_stat(filename).uid
+ local gid = uv.fs_stat(filename).gid
eq(0, os_fchown(filename, -1, -1))
- eq(uid, luv.fs_stat(filename).uid)
- return eq(gid, luv.fs_stat(filename).gid)
+ eq(uid, uv.fs_stat(filename).uid)
+ return eq(gid, uv.fs_stat(filename).gid)
end)
-- Some systems may not have `id` utility.
- if (os.execute('id -G > /dev/null 2>&1') ~= 0) then
+ if os.execute('id -G > /dev/null 2>&1') ~= 0 then
pending('skipped (missing `id` utility)', function() end)
else
- itp('owner of a file may change the group of the file to any group of which that owner is a member', function()
- local file_gid = luv.fs_stat(filename).gid
-
- -- Gets ID of any group of which current user is a member except the
- -- group that owns the file.
- local id_fd = io.popen('id -G')
- local new_gid = id_fd:read('*n')
- if (new_gid == file_gid) then
- new_gid = id_fd:read('*n')
+ itp(
+ 'owner of a file may change the group of the file to any group of which that owner is a member',
+ function()
+ local file_gid = uv.fs_stat(filename).gid
+
+ -- Gets ID of any group of which current user is a member except the
+ -- group that owns the file.
+ local id_fd = io.popen('id -G')
+ local new_gid = id_fd:read('*n')
+ if new_gid == file_gid then
+ new_gid = id_fd:read('*n')
+ end
+ id_fd:close()
+
+ -- User can be a member of only one group.
+ -- In that case we can not perform this test.
+ if new_gid then
+ eq(0, (os_fchown(filename, -1, new_gid)))
+ eq(new_gid, uv.fs_stat(filename).gid)
+ end
end
- id_fd:close()
-
- -- User can be a member of only one group.
- -- In that case we can not perform this test.
- if new_gid then
- eq(0, (os_fchown(filename, -1, new_gid)))
- eq(new_gid, luv.fs_stat(filename).gid)
- end
- end)
+ )
end
- if (ffi.os == 'Windows' or ffi.C.geteuid() == 0) then
+ if ffi.os == 'Windows' or ffi.C.geteuid() == 0 then
pending('skipped (uv_fs_chown is no-op on Windows)', function() end)
else
itp('returns nonzero if process has not enough permissions', function()
@@ -318,7 +321,6 @@ describe('fs.c', function()
end
end)
-
describe('os_file_is_readable', function()
itp('returns false if the file is not readable', function()
local perm = os_getperm('unit-test-directory/test.file')
@@ -330,13 +332,11 @@ describe('fs.c', function()
end)
itp('returns false if the file does not exist', function()
- eq(false, os_file_is_readable(
- 'unit-test-directory/what_are_you_smoking.gif'))
+ eq(false, os_file_is_readable('unit-test-directory/what_are_you_smoking.gif'))
end)
itp('returns true if the file is readable', function()
- eq(true, os_file_is_readable(
- 'unit-test-directory/test.file'))
+ eq(true, os_file_is_readable('unit-test-directory/test.file'))
end)
end)
@@ -387,7 +387,7 @@ describe('fs.c', function()
else
buf = ffi.new('char[?]', size + 1, ('\0'):rep(size))
end
- local eof = ffi.new('bool[?]', 1, {true})
+ local eof = ffi.new('bool[?]', 1, { true })
local ret2 = fs.os_read(fd, eof, buf, size, false)
local ret1 = eof[0]
local ret3 = ''
@@ -400,16 +400,16 @@ describe('fs.c', function()
local bufs = {}
for i, size in ipairs(sizes) do
bufs[i] = {
- iov_base=ffi.new('char[?]', size + 1, ('\0'):rep(size)),
- iov_len=size,
+ iov_base = ffi.new('char[?]', size + 1, ('\0'):rep(size)),
+ iov_len = size,
}
end
local iov = ffi.new('struct iovec[?]', #sizes, bufs)
- local eof = ffi.new('bool[?]', 1, {true})
+ local eof = ffi.new('bool[?]', 1, { true })
local ret2 = fs.os_readv(fd, eof, iov, #sizes, false)
local ret1 = eof[0]
local ret3 = {}
- for i = 1,#sizes do
+ for i = 1, #sizes do
-- Warning: iov may not be used.
ret3[i] = ffi.string(bufs[i].iov_base, bufs[i].iov_len)
end
@@ -445,7 +445,7 @@ describe('fs.c', function()
eq(OK, (os_rename(test, not_exist)))
eq(false, (os_path_exists(test)))
eq(true, (os_path_exists(not_exist)))
- eq(OK, (os_rename(not_exist, test))) -- restore test file
+ eq(OK, (os_rename(not_exist, test))) -- restore test file
end)
itp('fail if source file does not exist', function()
@@ -494,14 +494,19 @@ describe('fs.c', function()
local dup0 = fs.os_dup(0)
local dup1 = fs.os_dup(1)
local dup2 = fs.os_dup(2)
- local tbl = {[0]=true, [1]=true, [2]=true,
- [tonumber(dup0)]=true, [tonumber(dup1)]=true,
- [tonumber(dup2)]=true}
+ local tbl = {
+ [0] = true,
+ [1] = true,
+ [2] = true,
+ [tonumber(dup0)] = true,
+ [tonumber(dup1)] = true,
+ [tonumber(dup2)] = true,
+ }
local i = 0
for _, _ in pairs(tbl) do
i = i + 1
end
- eq(i, 6) -- All fds must be unique
+ eq(i, 6) -- All fds must be unique
end)
end)
@@ -522,12 +527,15 @@ describe('fs.c', function()
eq(ffi.C.UV_ENOENT, (os_open('non-existing-file', ffi.C.kO_RDWR, 0)))
end)
- itp('returns non-negative for O_CREAT on a non-existing file which then can be closed', function()
- assert_file_does_not_exist(new_file)
- local fd = os_open(new_file, ffi.C.kO_CREAT, 0)
- assert.is_true(0 <= fd)
- eq(0, os_close(fd))
- end)
+ itp(
+ 'returns non-negative for O_CREAT on a non-existing file which then can be closed',
+ function()
+ assert_file_does_not_exist(new_file)
+ local fd = os_open(new_file, ffi.C.kO_CREAT, 0)
+ assert.is_true(0 <= fd)
+ eq(0, os_close(fd))
+ end
+ )
itp('returns non-negative for O_CREAT on a existing file which then can be closed', function()
assert_file_exists(existing_file)
@@ -544,26 +552,29 @@ describe('fs.c', function()
itp('sets `rwx` permissions for O_CREAT 700 which then can be closed', function()
assert_file_does_not_exist(new_file)
--create the file
- local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber("700", 8))
+ local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber('700', 8))
--verify permissions
- eq(33216, luv.fs_stat(new_file).mode)
+ eq(33216, uv.fs_stat(new_file).mode)
eq(0, os_close(fd))
end)
itp('sets `rw` permissions for O_CREAT 600 which then can be closed', function()
assert_file_does_not_exist(new_file)
--create the file
- local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber("600", 8))
+ local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber('600', 8))
--verify permissions
- eq(33152, luv.fs_stat(new_file).mode)
+ eq(33152, uv.fs_stat(new_file).mode)
eq(0, os_close(fd))
end)
- itp('returns a non-negative file descriptor for an existing file which then can be closed', function()
- local fd = os_open(existing_file, ffi.C.kO_RDWR, 0)
- assert.is_true(0 <= fd)
- eq(0, os_close(fd))
- end)
+ itp(
+ 'returns a non-negative file descriptor for an existing file which then can be closed',
+ function()
+ local fd = os_open(existing_file, ffi.C.kO_RDWR, 0)
+ assert.is_true(0 <= fd)
+ eq(0, os_close(fd))
+ end
+ )
end)
describe('os_close', function()
@@ -589,43 +600,48 @@ describe('fs.c', function()
itp('can read zero bytes from a file', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, 0, ''}, {os_read(fd, nil)})
- eq({false, 0, ''}, {os_read(fd, 0)})
+ eq({ false, 0, '' }, { os_read(fd, nil) })
+ eq({ false, 0, '' }, { os_read(fd, 0) })
eq(0, os_close(fd))
end)
itp('can read from a file multiple times', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, 2, '\000\001'}, {os_read(fd, 2)})
- eq({false, 2, '\002\003'}, {os_read(fd, 2)})
+ eq({ false, 2, '\000\001' }, { os_read(fd, 2) })
+ eq({ false, 2, '\002\003' }, { os_read(fd, 2) })
eq(0, os_close(fd))
end)
itp('can read the whole file at once and then report eof', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, #fcontents, fcontents}, {os_read(fd, #fcontents)})
- eq({true, 0, ('\0'):rep(#fcontents)}, {os_read(fd, #fcontents)})
+ eq({ false, #fcontents, fcontents }, { os_read(fd, #fcontents) })
+ eq({ true, 0, ('\0'):rep(#fcontents) }, { os_read(fd, #fcontents) })
eq(0, os_close(fd))
end)
itp('can read the whole file in two calls, one partially', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, #fcontents * 3/4, fcontents:sub(1, #fcontents * 3/4)},
- {os_read(fd, #fcontents * 3/4)})
- eq({true,
- (#fcontents * 1/4),
- fcontents:sub(#fcontents * 3/4 + 1) .. ('\0'):rep(#fcontents * 2/4)},
- {os_read(fd, #fcontents * 3/4)})
+ eq(
+ { false, #fcontents * 3 / 4, fcontents:sub(1, #fcontents * 3 / 4) },
+ { os_read(fd, #fcontents * 3 / 4) }
+ )
+ eq({
+ true,
+ (#fcontents * 1 / 4),
+ fcontents:sub(#fcontents * 3 / 4 + 1) .. ('\0'):rep(#fcontents * 2 / 4),
+ }, { os_read(fd, #fcontents * 3 / 4) })
eq(0, os_close(fd))
end)
end)
describe('os_readv', function()
-- Function may be absent
- if not pcall(function() return fs.os_readv end) then
+ if not pcall(function()
+ return fs.os_readv
+ end) then
return
end
local file = 'test-unit-os-fs_spec-os_readv.dat'
@@ -643,45 +659,53 @@ describe('fs.c', function()
itp('can read zero bytes from a file', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, 0, {}}, {os_readv(fd, {})})
- eq({false, 0, {'', '', ''}}, {os_readv(fd, {0, 0, 0})})
+ eq({ false, 0, {} }, { os_readv(fd, {}) })
+ eq({ false, 0, { '', '', '' } }, { os_readv(fd, { 0, 0, 0 }) })
eq(0, os_close(fd))
end)
itp('can read from a file multiple times to a differently-sized buffers', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, 2, {'\000\001'}}, {os_readv(fd, {2})})
- eq({false, 5, {'\002\003', '\004\005\006'}}, {os_readv(fd, {2, 3})})
+ eq({ false, 2, { '\000\001' } }, { os_readv(fd, { 2 }) })
+ eq({ false, 5, { '\002\003', '\004\005\006' } }, { os_readv(fd, { 2, 3 }) })
eq(0, os_close(fd))
end)
itp('can read the whole file at once and then report eof', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false,
- #fcontents,
- {fcontents:sub(1, #fcontents * 1/4),
- fcontents:sub(#fcontents * 1/4 + 1, #fcontents * 3/4),
- fcontents:sub(#fcontents * 3/4 + 1, #fcontents * 15/16),
- fcontents:sub(#fcontents * 15/16 + 1, #fcontents)}},
- {os_readv(fd, {#fcontents * 1/4,
- #fcontents * 2/4,
- #fcontents * 3/16,
- #fcontents * 1/16})})
- eq({true, 0, {'\0'}}, {os_readv(fd, {1})})
+ eq({
+ false,
+ #fcontents,
+ {
+ fcontents:sub(1, #fcontents * 1 / 4),
+ fcontents:sub(#fcontents * 1 / 4 + 1, #fcontents * 3 / 4),
+ fcontents:sub(#fcontents * 3 / 4 + 1, #fcontents * 15 / 16),
+ fcontents:sub(#fcontents * 15 / 16 + 1, #fcontents),
+ },
+ }, {
+ os_readv(
+ fd,
+ { #fcontents * 1 / 4, #fcontents * 2 / 4, #fcontents * 3 / 16, #fcontents * 1 / 16 }
+ ),
+ })
+ eq({ true, 0, { '\0' } }, { os_readv(fd, { 1 }) })
eq(0, os_close(fd))
end)
itp('can read the whole file in two calls, one partially', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, #fcontents * 3/4, {fcontents:sub(1, #fcontents * 3/4)}},
- {os_readv(fd, {#fcontents * 3/4})})
- eq({true,
- (#fcontents * 1/4),
- {fcontents:sub(#fcontents * 3/4 + 1) .. ('\0'):rep(#fcontents * 2/4)}},
- {os_readv(fd, {#fcontents * 3/4})})
+ eq(
+ { false, #fcontents * 3 / 4, { fcontents:sub(1, #fcontents * 3 / 4) } },
+ { os_readv(fd, { #fcontents * 3 / 4 }) }
+ )
+ eq({
+ true,
+ (#fcontents * 1 / 4),
+ { fcontents:sub(#fcontents * 3 / 4 + 1) .. ('\0'):rep(#fcontents * 2 / 4) },
+ }, { os_readv(fd, { #fcontents * 3 / 4 }) })
eq(0, os_close(fd))
end)
end)
@@ -744,8 +768,8 @@ describe('fs.c', function()
end
local function os_mkdir_recurse(path, mode)
- local failed_str = ffi.new('char *[1]', {nil})
- local created_str = ffi.new('char *[1]', {nil})
+ local failed_str = ffi.new('char *[1]', { nil })
+ local created_str = ffi.new('char *[1]', { nil })
local ret = fs.os_mkdir_recurse(path, mode, failed_str, created_str)
local failed_dir = failed_str[0]
if failed_dir ~= nil then
@@ -769,7 +793,7 @@ describe('fs.c', function()
eq(false, (os_isdir('unit-test-directory/new-dir')))
eq(0, (os_mkdir('unit-test-directory/new-dir', mode)))
eq(true, (os_isdir('unit-test-directory/new-dir')))
- luv.fs_rmdir('unit-test-directory/new-dir')
+ uv.fs_rmdir('unit-test-directory/new-dir')
end)
end)
@@ -784,8 +808,7 @@ describe('fs.c', function()
itp('fails to create a directory where there is a file', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
- local ret, failed_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/test.file', mode)
+ local ret, failed_dir, created_dir = os_mkdir_recurse('unit-test-directory/test.file', mode)
neq(0, ret)
eq('unit-test-directory/test.file', failed_dir)
eq(nil, created_dir)
@@ -793,8 +816,8 @@ describe('fs.c', function()
itp('fails to create a directory where there is a file in path', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
- local ret, failed_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/test.file/test', mode)
+ local ret, failed_dir, created_dir =
+ os_mkdir_recurse('unit-test-directory/test.file/test', mode)
neq(0, ret)
eq('unit-test-directory/test.file', failed_dir)
eq(nil, created_dir)
@@ -802,44 +825,44 @@ describe('fs.c', function()
itp('succeeds to create a directory', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
- local ret, failed_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/new-dir-recurse', mode)
+ local ret, failed_dir, created_dir =
+ os_mkdir_recurse('unit-test-directory/new-dir-recurse', mode)
eq(0, ret)
eq(nil, failed_dir)
ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse'))
eq(true, os_isdir('unit-test-directory/new-dir-recurse'))
- luv.fs_rmdir('unit-test-directory/new-dir-recurse')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse')
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
itp('succeeds to create a directory ending with ///', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
- local ret, failed_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/new-dir-recurse///', mode)
+ local ret, failed_dir, created_dir =
+ os_mkdir_recurse('unit-test-directory/new-dir-recurse///', mode)
eq(0, ret)
eq(nil, failed_dir)
ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse'))
eq(true, os_isdir('unit-test-directory/new-dir-recurse'))
- luv.fs_rmdir('unit-test-directory/new-dir-recurse')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse')
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
itp('succeeds to create a directory ending with /', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
- local ret, failed_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/new-dir-recurse/', mode)
+ local ret, failed_dir, created_dir =
+ os_mkdir_recurse('unit-test-directory/new-dir-recurse/', mode)
eq(0, ret)
eq(nil, failed_dir)
ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse'))
eq(true, os_isdir('unit-test-directory/new-dir-recurse'))
- luv.fs_rmdir('unit-test-directory/new-dir-recurse')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse')
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
itp('succeeds to create a directory tree', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
- local ret, failed_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/new-dir-recurse/1/2/3', mode)
+ local ret, failed_dir, created_dir =
+ os_mkdir_recurse('unit-test-directory/new-dir-recurse/1/2/3', mode)
eq(0, ret)
eq(nil, failed_dir)
ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse'))
@@ -847,10 +870,10 @@ describe('fs.c', function()
eq(true, os_isdir('unit-test-directory/new-dir-recurse/1'))
eq(true, os_isdir('unit-test-directory/new-dir-recurse/1/2'))
eq(true, os_isdir('unit-test-directory/new-dir-recurse/1/2/3'))
- luv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2/3')
- luv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2')
- luv.fs_rmdir('unit-test-directory/new-dir-recurse/1')
- luv.fs_rmdir('unit-test-directory/new-dir-recurse')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2/3')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse/1')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse')
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
end)
@@ -1015,7 +1038,7 @@ describe('fs.c', function()
file:write('some bytes to get filesize != 0')
file:flush()
file:close()
- local size = luv.fs_stat(path).size
+ local size = uv.fs_stat(path).size
local info = file_info_new()
assert.is_true(fs.os_fileinfo(path, info))
eq(size, fs.os_fileinfo_size(info))
@@ -1029,7 +1052,7 @@ describe('fs.c', function()
local info = file_info_new()
assert.is_true(fs.os_fileinfo(path, info))
eq(1, fs.os_fileinfo_hardlinks(info))
- luv.fs_link(path, path_link)
+ uv.fs_link(path, path_link)
assert.is_true(fs.os_fileinfo(path, info))
eq(2, fs.os_fileinfo_hardlinks(info))
end)
@@ -1038,7 +1061,7 @@ describe('fs.c', function()
describe('os_fileinfo_blocksize', function()
itp('returns the correct blocksize of a file', function()
local path = 'unit-test-directory/test.file'
- local blksize = luv.fs_stat(path).blksize
+ local blksize = uv.fs_stat(path).blksize
local info = file_info_new()
assert.is_true(fs.os_fileinfo(path, info))
if blksize then
diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua
index 3fb1afed44..ae162f2317 100644
--- a/test/unit/os/shell_spec.lua
+++ b/test/unit/os/shell_spec.lua
@@ -21,9 +21,7 @@ describe('shell functions', function()
end)
local function shell_build_argv(cmd, extra_args)
- local res = cimported.shell_build_argv(
- cmd and to_cstr(cmd),
- extra_args and to_cstr(extra_args))
+ local res = cimported.shell_build_argv(cmd and to_cstr(cmd), extra_args and to_cstr(extra_args))
-- `res` is zero-indexed (C pointer, not Lua table)!
local argc = 0
local ret = {}
@@ -40,9 +38,7 @@ describe('shell functions', function()
local function shell_argv_to_str(argv_table)
-- C string array (char **).
- local argv = (argv_table
- and ffi.new("char*[?]", #argv_table+1)
- or NULL)
+ local argv = (argv_table and ffi.new('char*[?]', #argv_table + 1) or NULL)
local argc = 1
while argv_table ~= nil and argv_table[argc] ~= nil do
@@ -64,8 +60,7 @@ describe('shell functions', function()
local output = ffi.new('char *[1]')
local nread = ffi.new('size_t[1]')
- local argv = ffi.cast('char**',
- cimported.shell_build_argv(to_cstr(cmd), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr(cmd), nil))
local status = cimported.os_system(argv, input_or, input_len, output, nread)
return status, intern(output[0], nread[0])
@@ -101,37 +96,35 @@ describe('shell functions', function()
describe('shell_build_argv', function()
itp('works with NULL arguments', function()
- eq({'/bin/sh'}, shell_build_argv(nil, nil))
+ eq({ '/bin/sh' }, shell_build_argv(nil, nil))
end)
itp('works with cmd', function()
- eq({'/bin/sh', '-c', 'abc def'}, shell_build_argv('abc def', nil))
+ eq({ '/bin/sh', '-c', 'abc def' }, shell_build_argv('abc def', nil))
end)
itp('works with extra_args', function()
- eq({'/bin/sh', 'ghi jkl'}, shell_build_argv(nil, 'ghi jkl'))
+ eq({ '/bin/sh', 'ghi jkl' }, shell_build_argv(nil, 'ghi jkl'))
end)
itp('works with cmd and extra_args', function()
- eq({'/bin/sh', 'ghi jkl', '-c', 'abc def'}, shell_build_argv('abc def', 'ghi jkl'))
+ eq({ '/bin/sh', 'ghi jkl', '-c', 'abc def' }, shell_build_argv('abc def', 'ghi jkl'))
end)
itp('splits and unquotes &shell and &shellcmdflag', function()
cimported.p_sh = to_cstr('/Program" "Files/zsh -f')
cimported.p_shcf = to_cstr('-x -o "sh word split" "-"c')
- eq({'/Program Files/zsh', '-f',
- 'ghi jkl',
- '-x', '-o', 'sh word split',
- '-c', 'abc def'},
- shell_build_argv('abc def', 'ghi jkl'))
+ eq(
+ { '/Program Files/zsh', '-f', 'ghi jkl', '-x', '-o', 'sh word split', '-c', 'abc def' },
+ shell_build_argv('abc def', 'ghi jkl')
+ )
end)
itp('applies shellxescape (p_sxe) and shellxquote (p_sxq)', function()
cimported.p_sxq = to_cstr('(')
cimported.p_sxe = to_cstr('"&|<>()@^')
- local argv = ffi.cast('char**',
- cimported.shell_build_argv(to_cstr('echo &|<>()@^'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo &|<>()@^'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), '(echo ^&^|^<^>^(^)^@^^)')
@@ -142,8 +135,7 @@ describe('shell functions', function()
cimported.p_sxq = to_cstr('"(')
cimported.p_sxe = to_cstr('"&|<>()@^')
- local argv = ffi.cast('char**', cimported.shell_build_argv(
- to_cstr('echo -n some text'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo -n some text'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), '"(echo -n some text)"')
@@ -154,8 +146,7 @@ describe('shell functions', function()
cimported.p_sxq = to_cstr('"')
cimported.p_sxe = to_cstr('')
- local argv = ffi.cast('char**', cimported.shell_build_argv(
- to_cstr('echo -n some text'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo -n some text'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), '"echo -n some text"')
@@ -163,8 +154,7 @@ describe('shell functions', function()
end)
itp('with empty shellxquote/shellxescape', function()
- local argv = ffi.cast('char**', cimported.shell_build_argv(
- to_cstr('echo -n some text'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo -n some text'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), 'echo -n some text')
@@ -176,9 +166,11 @@ describe('shell functions', function()
eq('', shell_argv_to_str({ nil }))
eq("''", shell_argv_to_str({ '' }))
eq("'foo' '' 'bar'", shell_argv_to_str({ 'foo', '', 'bar' }))
- eq("'/bin/sh' '-c' 'abc def'", shell_argv_to_str({'/bin/sh', '-c', 'abc def'}))
- eq("'abc def' 'ghi jkl'", shell_argv_to_str({'abc def', 'ghi jkl'}))
- eq("'/bin/sh' '-c' 'abc def' '"..('x'):rep(225).."...",
- shell_argv_to_str({'/bin/sh', '-c', 'abc def', ('x'):rep(999)}))
+ eq("'/bin/sh' '-c' 'abc def'", shell_argv_to_str({ '/bin/sh', '-c', 'abc def' }))
+ eq("'abc def' 'ghi jkl'", shell_argv_to_str({ 'abc def', 'ghi jkl' }))
+ eq(
+ "'/bin/sh' '-c' 'abc def' '" .. ('x'):rep(225) .. '...',
+ shell_argv_to_str({ '/bin/sh', '-c', 'abc def', ('x'):rep(999) })
+ )
end)
end)