mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
test/util: move general functions into global helpers
This commit is contained in:
parent
34f29ac858
commit
d6a1640260
@ -12,15 +12,18 @@ local Paths = require('test.config.paths')
|
|||||||
|
|
||||||
local check_cores = global_helpers.check_cores
|
local check_cores = global_helpers.check_cores
|
||||||
local check_logs = global_helpers.check_logs
|
local check_logs = global_helpers.check_logs
|
||||||
local neq = global_helpers.neq
|
local dedent = global_helpers.dedent
|
||||||
local eq = global_helpers.eq
|
local eq = global_helpers.eq
|
||||||
local expect_err = global_helpers.expect_err
|
local expect_err = global_helpers.expect_err
|
||||||
local ok = global_helpers.ok
|
local filter = global_helpers.filter
|
||||||
local map = global_helpers.map
|
local map = global_helpers.map
|
||||||
local matches = global_helpers.matches
|
local matches = global_helpers.matches
|
||||||
local filter = global_helpers.filter
|
local neq = global_helpers.neq
|
||||||
local dedent = global_helpers.dedent
|
local ok = global_helpers.ok
|
||||||
|
local read_file = global_helpers.read_file
|
||||||
|
local sleep = global_helpers.sleep
|
||||||
local table_flatten = global_helpers.table_flatten
|
local table_flatten = global_helpers.table_flatten
|
||||||
|
local write_file = global_helpers.write_file
|
||||||
|
|
||||||
local start_dir = lfs.currentdir()
|
local start_dir = lfs.currentdir()
|
||||||
-- XXX: NVIM_PROG takes precedence, QuickBuild sets it.
|
-- XXX: NVIM_PROG takes precedence, QuickBuild sets it.
|
||||||
@ -374,34 +377,6 @@ local function feed_command(...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Dedent the given text and write it to the file name.
|
|
||||||
local function write_file(name, text, no_dedent, append)
|
|
||||||
local file = io.open(name, (append and 'a' or 'w'))
|
|
||||||
if type(text) == 'table' then
|
|
||||||
-- Byte blob
|
|
||||||
local bytes = text
|
|
||||||
text = ''
|
|
||||||
for _, char in ipairs(bytes) do
|
|
||||||
text = ('%s%c'):format(text, char)
|
|
||||||
end
|
|
||||||
elseif not no_dedent then
|
|
||||||
text = dedent(text)
|
|
||||||
end
|
|
||||||
file:write(text)
|
|
||||||
file:flush()
|
|
||||||
file:close()
|
|
||||||
end
|
|
||||||
|
|
||||||
local function read_file(name)
|
|
||||||
local file = io.open(name, 'r')
|
|
||||||
if not file then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
local ret = file:read('*a')
|
|
||||||
file:close()
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
local sourced_fnames = {}
|
local sourced_fnames = {}
|
||||||
local function source(code)
|
local function source(code)
|
||||||
local fname = tmpname()
|
local fname = tmpname()
|
||||||
@ -466,11 +441,6 @@ local function wait()
|
|||||||
session:request('nvim_eval', '1')
|
session:request('nvim_eval', '1')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- sleeps the test runner (_not_ the nvim instance)
|
|
||||||
local function sleep(ms)
|
|
||||||
luv.sleep(ms)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function curbuf_contents()
|
local function curbuf_contents()
|
||||||
wait() -- Before inspecting the buffer, process all input.
|
wait() -- Before inspecting the buffer, process all input.
|
||||||
return table.concat(curbuf('get_lines', 0, -1, true), '\n')
|
return table.concat(curbuf('get_lines', 0, -1, true), '\n')
|
||||||
@ -682,31 +652,6 @@ local function alter_slashes(obj)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function hexdump(str)
|
|
||||||
local len = string.len(str)
|
|
||||||
local dump = ""
|
|
||||||
local hex = ""
|
|
||||||
local asc = ""
|
|
||||||
|
|
||||||
for i = 1, len do
|
|
||||||
if 1 == i % 8 then
|
|
||||||
dump = dump .. hex .. asc .. "\n"
|
|
||||||
hex = string.format("%04x: ", i - 1)
|
|
||||||
asc = ""
|
|
||||||
end
|
|
||||||
|
|
||||||
local ord = string.byte(str, i)
|
|
||||||
hex = hex .. string.format("%02x ", ord)
|
|
||||||
if ord >= 32 and ord <= 126 then
|
|
||||||
asc = asc .. string.char(ord)
|
|
||||||
else
|
|
||||||
asc = asc .. "."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return dump .. hex .. string.rep(" ", 8 - len % 8) .. asc
|
|
||||||
end
|
|
||||||
|
|
||||||
local module = {
|
local module = {
|
||||||
NIL = mpack.NIL,
|
NIL = mpack.NIL,
|
||||||
alter_slashes = alter_slashes,
|
alter_slashes = alter_slashes,
|
||||||
@ -737,7 +682,6 @@ local module = {
|
|||||||
filter = filter,
|
filter = filter,
|
||||||
funcs = funcs,
|
funcs = funcs,
|
||||||
get_pathsep = get_pathsep,
|
get_pathsep = get_pathsep,
|
||||||
hexdump = hexdump,
|
|
||||||
insert = insert,
|
insert = insert,
|
||||||
iswin = iswin,
|
iswin = iswin,
|
||||||
map = map,
|
map = map,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
local assert = require('luassert')
|
local assert = require('luassert')
|
||||||
|
local luv = require('luv')
|
||||||
local lfs = require('lfs')
|
local lfs = require('lfs')
|
||||||
|
|
||||||
local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote)
|
local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote)
|
||||||
@ -33,6 +34,11 @@ local function popen_w(...)
|
|||||||
return io.popen(argss_to_cmd(...), 'w')
|
return io.popen(argss_to_cmd(...), 'w')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- sleeps the test runner (_not_ the nvim instance)
|
||||||
|
local function sleep(ms)
|
||||||
|
luv.sleep(ms)
|
||||||
|
end
|
||||||
|
|
||||||
local check_logs_useless_lines = {
|
local check_logs_useless_lines = {
|
||||||
['Warning: noted but unhandled ioctl']=1,
|
['Warning: noted but unhandled ioctl']=1,
|
||||||
['could cause spurious value errors to appear']=2,
|
['could cause spurious value errors to appear']=2,
|
||||||
@ -612,7 +618,60 @@ local function table_flatten(arr)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
local function hexdump(str)
|
||||||
|
local len = string.len(str)
|
||||||
|
local dump = ""
|
||||||
|
local hex = ""
|
||||||
|
local asc = ""
|
||||||
|
|
||||||
|
for i = 1, len do
|
||||||
|
if 1 == i % 8 then
|
||||||
|
dump = dump .. hex .. asc .. "\n"
|
||||||
|
hex = string.format("%04x: ", i - 1)
|
||||||
|
asc = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local ord = string.byte(str, i)
|
||||||
|
hex = hex .. string.format("%02x ", ord)
|
||||||
|
if ord >= 32 and ord <= 126 then
|
||||||
|
asc = asc .. string.char(ord)
|
||||||
|
else
|
||||||
|
asc = asc .. "."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return dump .. hex .. string.rep(" ", 8 - len % 8) .. asc
|
||||||
|
end
|
||||||
|
|
||||||
|
local function read_file(name)
|
||||||
|
local file = io.open(name, 'r')
|
||||||
|
if not file then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local ret = file:read('*a')
|
||||||
|
file:close()
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Dedent the given text and write it to the file name.
|
||||||
|
local function write_file(name, text, no_dedent, append)
|
||||||
|
local file = io.open(name, (append and 'a' or 'w'))
|
||||||
|
if type(text) == 'table' then
|
||||||
|
-- Byte blob
|
||||||
|
local bytes = text
|
||||||
|
text = ''
|
||||||
|
for _, char in ipairs(bytes) do
|
||||||
|
text = ('%s%c'):format(text, char)
|
||||||
|
end
|
||||||
|
elseif not no_dedent then
|
||||||
|
text = dedent(text)
|
||||||
|
end
|
||||||
|
file:write(text)
|
||||||
|
file:flush()
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
local module = {
|
||||||
REMOVE_THIS = REMOVE_THIS,
|
REMOVE_THIS = REMOVE_THIS,
|
||||||
argss_to_cmd = argss_to_cmd,
|
argss_to_cmd = argss_to_cmd,
|
||||||
check_cores = check_cores,
|
check_cores = check_cores,
|
||||||
@ -630,6 +689,7 @@ return {
|
|||||||
format_string = format_string,
|
format_string = format_string,
|
||||||
glob = glob,
|
glob = glob,
|
||||||
hasenv = hasenv,
|
hasenv = hasenv,
|
||||||
|
hexdump = hexdump,
|
||||||
intchar2lua = intchar2lua,
|
intchar2lua = intchar2lua,
|
||||||
map = map,
|
map = map,
|
||||||
matches = matches,
|
matches = matches,
|
||||||
@ -638,11 +698,16 @@ return {
|
|||||||
ok = ok,
|
ok = ok,
|
||||||
popen_r = popen_r,
|
popen_r = popen_r,
|
||||||
popen_w = popen_w,
|
popen_w = popen_w,
|
||||||
|
read_file = read_file,
|
||||||
repeated_read_cmd = repeated_read_cmd,
|
repeated_read_cmd = repeated_read_cmd,
|
||||||
|
sleep = sleep,
|
||||||
shallowcopy = shallowcopy,
|
shallowcopy = shallowcopy,
|
||||||
table_flatten = table_flatten,
|
table_flatten = table_flatten,
|
||||||
tmpname = tmpname,
|
tmpname = tmpname,
|
||||||
uname = uname,
|
uname = uname,
|
||||||
updated = updated,
|
updated = updated,
|
||||||
which = which,
|
which = which,
|
||||||
|
write_file = write_file,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return module
|
||||||
|
Loading…
Reference in New Issue
Block a user