From a48508de0dd745cba94debe63f0695447f4ac82f Mon Sep 17 00:00:00 2001 From: Rui Abreu Ferreira Date: Tue, 29 Dec 2015 19:23:51 +0000 Subject: [PATCH] test/functional: Fix api/vim_spec.lua. On Windows the default file format is DOS i.e. newlines are \r\n instead of \n. --- test/functional/api/vim_spec.lua | 8 +++++-- test/functional/helpers.lua | 5 ++++ test/functional/server/server_spec.lua | 33 +++++++++++++------------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index cba0b7533b..f4a9ddc698 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers') local Screen = require('test.functional.ui.screen') local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed - +local os_is_windows = helpers.os_is_windows describe('vim_* functions', function() before_each(clear) @@ -17,7 +17,11 @@ describe('vim_* functions', function() nvim('command', 'w') local f = io.open(fname) ok(f ~= nil) - eq('testing\napi\n', f:read('*a')) + if os_is_windows() then + eq('testing\r\napi\r\n', f:read('*a')) + else + eq('testing\napi\n', f:read('*a')) + end f:close() os.remove(fname) end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 9562457c8e..67c5a6f626 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -323,6 +323,10 @@ local function expect(contents) return eq(dedent(contents), curbuf_contents()) end +local function os_is_windows() + return nvim_eval('has("win32")') == 1 +end + local function rmdir(path) if lfs.attributes(path, 'mode') ~= 'directory' then return nil @@ -425,6 +429,7 @@ return { wait = wait, set_session = set_session, write_file = write_file, + os_is_windows = os_is_windows, rmdir = rmdir, mkdir = lfs.mkdir, exc_exec = exc_exec, diff --git a/test/functional/server/server_spec.lua b/test/functional/server/server_spec.lua index e8a5743446..649e9dbabe 100644 --- a/test/functional/server/server_spec.lua +++ b/test/functional/server/server_spec.lua @@ -1,7 +1,8 @@ local helpers = require('test.functional.helpers') local nvim, eq, neq, eval = helpers.nvim, helpers.eq, helpers.neq, helpers.eval -local clear = helpers.clear +local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths +local os_is_windows = helpers.os_is_windows describe('serverstart(), serverstop()', function() before_each(clear) @@ -17,34 +18,32 @@ describe('serverstart(), serverstop()', function() eq('', eval('$NVIM_LISTEN_ADDRESS')) end) - it([[sets v:servername _only_ on nvim startup - (unless all servers are stopped)]], function() - local initial_server = eval('v:servername') + it('sets v:servername _only_ on nvim startup unless all servers are stopped', + function() + local initial_server = meths.get_vvar('servername') assert(initial_server ~= nil and initial_server:len() > 0, - "v:servername was not initialized") + 'v:servername was not initialized') -- v:servername is readonly so we cannot unset it--but we can test that it -- does not get set again thereafter. - local s = eval('serverstart()') + local s = funcs.serverstart() assert(s ~= nil and s:len() > 0, "serverstart() returned empty") neq(initial_server, s) -- serverstop() does _not_ modify v:servername... - nvim('command', "call serverstop('"..s.."')") - eq(initial_server, eval('v:servername')) + funcs.serverstop(s) + eq(initial_server, meths.get_vvar('servername')) -- ...unless we stop _all_ servers. - nvim('command', "call serverstop(serverlist()[0])") - eq('', eval('v:servername')) + funcs.serverstop(funcs.serverlist()[1]) + eq('', meths.get_vvar('servername')) -- v:servername will take the next available server. - if eval('has("win32")') then - nvim('command', "call serverstart('\\\\.\\pipe\\test_server_pipe')") - eq('\\\\.\\pipe\\test_server_pipe', eval('v:servername')) - else - nvim('command', "call serverstart('test_server_socket')") - eq('test_server_socket', eval('v:servername')) - end + local servername = (os_is_windows() + and [[\\.\pipe\Xtest-functional-server-server-pipe]] + or 'Xtest-functional-server-server-socket') + funcs.serverstart(servername) + eq(servername, meths.get_vvar('servername')) end) it('serverstop() ignores invalid input', function()