diff options
author | ZyX <kp-pav@yandex.ru> | 2017-03-17 00:04:03 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-03-19 14:13:21 +0300 |
commit | 0320a58082f922b54cb36ce57064c07a9e781aa8 (patch) | |
tree | 74f18e6450124946c5e7b1c8708232241fe55f01 | |
parent | 65c41e6c2b5015ff0b0485aadd362c0883a02a85 (diff) | |
download | rneovim-0320a58082f922b54cb36ce57064c07a9e781aa8.tar.gz rneovim-0320a58082f922b54cb36ce57064c07a9e781aa8.tar.bz2 rneovim-0320a58082f922b54cb36ce57064c07a9e781aa8.zip |
functests: Check that `-s` works as expected
-rw-r--r-- | test/functional/core/main_spec.lua | 60 | ||||
-rw-r--r-- | test/helpers.lua | 39 | ||||
-rw-r--r-- | test/unit/preprocess.lua | 26 |
3 files changed, 102 insertions, 23 deletions
diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua new file mode 100644 index 0000000000..50c6009b53 --- /dev/null +++ b/test/functional/core/main_spec.lua @@ -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) diff --git a/test/helpers.lua b/test/helpers.lua index e5224349c2..6ee95a4396 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -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, } diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index 363358d134..18b2284e3d 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -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 |