mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
functests: Check that -s works as expected
This commit is contained in:
60
test/functional/core/main_spec.lua
Normal file
60
test/functional/core/main_spec.lua
Normal file
@@ -0,0 +1,60 @@
|
||||
local lfs = require('lfs')
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local global_helpers = require('test.helpers')
|
||||
|
||||
local eq = helpers.eq
|
||||
local neq = helpers.neq
|
||||
local sleep = helpers.sleep
|
||||
local nvim_prog = helpers.nvim_prog
|
||||
local write_file = helpers.write_file
|
||||
|
||||
local popen_w = global_helpers.popen_w
|
||||
local popen_r = global_helpers.popen_r
|
||||
|
||||
describe('Command-line option', function()
|
||||
describe('-s', function()
|
||||
local fname = 'Xtest-functional-core-main-s'
|
||||
local dollar_fname = '$' .. fname
|
||||
before_each(function()
|
||||
os.remove(fname)
|
||||
os.remove(dollar_fname)
|
||||
end)
|
||||
after_each(function()
|
||||
os.remove(fname)
|
||||
os.remove(dollar_fname)
|
||||
end)
|
||||
it('treats - as stdin', function()
|
||||
eq(nil, lfs.attributes(fname))
|
||||
local pipe = popen_w(
|
||||
nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '-s', '-',
|
||||
fname)
|
||||
pipe:write(':call setline(1, "42")\n')
|
||||
pipe:write(':wqall!\n')
|
||||
pipe:close()
|
||||
local max_sec = 10
|
||||
while max_sec > 0 do
|
||||
local attrs = lfs.attributes(fname)
|
||||
if attrs then
|
||||
eq(#('42\n'), attrs.size)
|
||||
break
|
||||
else
|
||||
max_sec = max_sec - 1
|
||||
sleep(1000)
|
||||
end
|
||||
end
|
||||
neq(0, max_sec)
|
||||
end)
|
||||
it('does not expand $VAR', function()
|
||||
eq(nil, lfs.attributes(fname))
|
||||
eq(true, not not dollar_fname:find('%$%w+'))
|
||||
write_file(dollar_fname, ':call setline(1, "100500")\n:wqall!\n')
|
||||
local pipe = popen_r(
|
||||
nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '-s', dollar_fname,
|
||||
fname)
|
||||
local stdout = pipe:read('*a')
|
||||
eq('', stdout)
|
||||
local attrs = lfs.attributes(fname)
|
||||
eq(#('100500\n'), attrs.size)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -1,6 +1,38 @@
|
||||
local assert = require('luassert')
|
||||
local lfs = require('lfs')
|
||||
|
||||
local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote)
|
||||
local function shell_quote(str)
|
||||
if string.find(str, quote_me) or str == '' then
|
||||
return '"' .. str:gsub('[$%%"\\]', '\\%0') .. '"'
|
||||
else
|
||||
return str
|
||||
end
|
||||
end
|
||||
|
||||
local function argss_to_cmd(...)
|
||||
local cmd = ''
|
||||
for i = 1, select('#', ...) do
|
||||
local arg = select(i, ...)
|
||||
if type(arg) == 'string' then
|
||||
cmd = cmd .. ' ' ..shell_quote(arg)
|
||||
else
|
||||
for _, arg in ipairs(arg) do
|
||||
cmd = cmd .. ' ' .. shell_quote(arg)
|
||||
end
|
||||
end
|
||||
end
|
||||
return cmd
|
||||
end
|
||||
|
||||
local function popen_r(...)
|
||||
return io.popen(argss_to_cmd(...), 'r')
|
||||
end
|
||||
|
||||
local function popen_w(...)
|
||||
return io.popen(argss_to_cmd(...), 'w')
|
||||
end
|
||||
|
||||
local check_logs_useless_lines = {
|
||||
['Warning: noted but unhandled ioctl']=1,
|
||||
['could cause spurious value errors to appear']=2,
|
||||
@@ -95,7 +127,7 @@ local uname = (function()
|
||||
return platform
|
||||
end
|
||||
|
||||
local status, f = pcall(io.popen, "uname -s")
|
||||
local status, f = pcall(popen_r, 'uname', '-s')
|
||||
if status then
|
||||
platform = f:read("*l")
|
||||
f:close()
|
||||
@@ -215,7 +247,7 @@ local function check_cores(app)
|
||||
end
|
||||
|
||||
local function which(exe)
|
||||
local pipe = io.popen('which ' .. exe, 'r')
|
||||
local pipe = popen_r('which', exe)
|
||||
local ret = pipe:read('*a')
|
||||
pipe:close()
|
||||
if ret == '' then
|
||||
@@ -238,4 +270,7 @@ return {
|
||||
check_cores = check_cores,
|
||||
hasenv = hasenv,
|
||||
which = which,
|
||||
argss_to_cmd = argss_to_cmd,
|
||||
popen_r = popen_r,
|
||||
popen_w = popen_w,
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
-- windows, will probably need quite a bit of adjustment to run there.
|
||||
|
||||
local ffi = require("ffi")
|
||||
local global_helpers = require('test.helpers')
|
||||
|
||||
local popen_r = global_helpers.popen_r
|
||||
local argss_to_cmd = global_helpers.argss_to_cmd
|
||||
|
||||
local ccs = {}
|
||||
|
||||
@@ -22,15 +26,6 @@ table.insert(ccs, {path = {"/usr/bin/env", "gcc-4.7"}, type = "gcc"})
|
||||
table.insert(ccs, {path = {"/usr/bin/env", "clang"}, type = "clang"})
|
||||
table.insert(ccs, {path = {"/usr/bin/env", "icc"}, type = "gcc"})
|
||||
|
||||
local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote)
|
||||
local function shell_quote(str)
|
||||
if string.find(str, quote_me) or str == '' then
|
||||
return "'" .. string.gsub(str, "'", [['"'"']]) .. "'"
|
||||
else
|
||||
return str
|
||||
end
|
||||
end
|
||||
|
||||
-- parse Makefile format dependencies into a Lua table
|
||||
local function parse_make_deps(deps)
|
||||
-- remove line breaks and line concatenators
|
||||
@@ -149,16 +144,6 @@ function Gcc:add_to_include_path(...)
|
||||
end
|
||||
end
|
||||
|
||||
local function argss_to_cmd(...)
|
||||
local cmd = ''
|
||||
for i = 1, select('#', ...) do
|
||||
for _, arg in ipairs(select(i, ...)) do
|
||||
cmd = cmd .. ' ' .. shell_quote(arg)
|
||||
end
|
||||
end
|
||||
return cmd
|
||||
end
|
||||
|
||||
-- returns a list of the headers files upon which this file relies
|
||||
function Gcc:dependencies(hdr)
|
||||
local cmd = argss_to_cmd(self.path, {'-M', hdr}) .. ' 2>&1'
|
||||
@@ -173,9 +158,8 @@ function Gcc:dependencies(hdr)
|
||||
end
|
||||
|
||||
local function repeated_call(...)
|
||||
local cmd = argss_to_cmd(...)
|
||||
for _ = 1, 10 do
|
||||
local stream = io.popen(cmd)
|
||||
local stream = popen_r(...)
|
||||
local ret = stream:read('*a')
|
||||
stream:close()
|
||||
if ret then
|
||||
|
||||
Reference in New Issue
Block a user