From b90d7c36cf8a93e02d834eb53f5d0c8f19a9d7fa Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 26 May 2024 09:34:29 +0200 Subject: refactor(tests): more global highlight definitions --- test/functional/core/fileio_spec.lua | 11 +++-------- test/functional/core/job_spec.lua | 13 ++++--------- 2 files changed, 7 insertions(+), 17 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 5b0be1e83c..1c4f42eb43 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -276,11 +276,6 @@ describe('fileio', function() write_file('Xtest-overwrite-forced', 'foobar') command('set nofixendofline') local screen = Screen.new(40, 4) - screen:set_default_attr_ids({ - [1] = { bold = true, foreground = Screen.colors.Blue1 }, - [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, - [3] = { bold = true, foreground = Screen.colors.SeaGreen4 }, - }) screen:attach() command('set shortmess-=F') @@ -300,9 +295,9 @@ describe('fileio', function() -- use async feed_command because nvim basically hangs on the prompt feed_command('w') screen:expect([[ - {2:WARNING: The file has been changed since}| - {2: reading it!!!} | - {3:Do you really want to write to it (y/n)?}| + {9:WARNING: The file has been changed since}| + {9: reading it!!!} | + {6:Do you really want to write to it (y/n)?}| ^ | ]]) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index e1efc07452..bf10033f53 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -910,11 +910,6 @@ describe('jobs', function() it('hides cursor and flushes messages before blocking', function() local screen = Screen.new(50, 6) - screen:set_default_attr_ids({ - [0] = { foreground = Screen.colors.Blue, bold = true }, -- NonText - [1] = { bold = true, reverse = true }, -- MsgSeparator - [2] = { bold = true, foreground = Screen.colors.SeaGreen }, -- MoreMsg - }) screen:attach() command([[let g:id = jobstart([v:progpath, '--clean', '--headless'])]]) source([[ @@ -928,8 +923,8 @@ describe('jobs', function() screen:expect { grid = [[ | - {0:~ }|*2 - {1: }| + {1:~ }|*2 + {3: }| aaa | bbb | ]], @@ -938,11 +933,11 @@ describe('jobs', function() screen:expect { grid = [[ | - {1: }| + {3: }| aaa | bbb | ccc | - {2:Press ENTER or type command to continue}^ | + {6:Press ENTER or type command to continue}^ | ]], } feed('') -- cgit From 5493fcd52f2eaab4b6a81c366529e80ca3dec535 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Fri, 31 May 2024 08:25:40 -0500 Subject: test: remove checks for failed tests on Windows --- test/functional/core/startup_spec.lua | 6 ------ 1 file changed, 6 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index a53625ab1b..1bb4ce2946 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -400,9 +400,6 @@ describe('startup', function() read_file('Xtest_startup_ttyout') ) end) - if is_os('win') then - assert_log('stream write failed. RPC canceled; closing channel', testlog) - end end) it('input from pipe: has("ttyin")==0 has("ttyout")==1', function() @@ -435,9 +432,6 @@ describe('startup', function() read_file('Xtest_startup_ttyout') ) end) - if is_os('win') then - assert_log('stream write failed. RPC canceled; closing channel', testlog) - end end) it('input from pipe (implicit) #7679', function() -- cgit From 1a1c766049826b6049610edda8f72eac1f75b38d Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 18 Jun 2024 03:23:52 +0000 Subject: refactor: Windows tilde expansion followup (#29380) Followup to #28515: Rename the static os_homedir() to os_uv_homedir() to emphasize that it is a wrapper around a libuv function. Add the function os_get_homedir() to os/env.c to return the cached homedir value as a const. Must be called after homedir is initialized or it fails. The difference between this function and the static os_uv_homedir() is that the latter gets the homedir from libuv and is used to initialize homedir in init_homedir(), while os_get_homedir() just returns homedir as a const if it's initialized and is public. Use the os_get_homedir() accessor for ~/ expansion on Windows to make the code more concise. Add a Windows section to main_spec.lua with tests for expanding ~/ and ~\ prefixes for files passed in on the command-line. Signed-off-by: Rafael Kitover --- test/functional/core/main_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index 5e903726db..a6e917b4b2 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -193,4 +193,26 @@ describe('command-line option', function() matches('Run "nvim %-V1 %-v"', fn.system({ nvim_prog_abs(), '-v' })) matches('Compilation: .*Run :checkhealth', fn.system({ nvim_prog_abs(), '-V1', '-v' })) end) + + if is_os('win') then + for _, prefix in ipairs({ '~/', '~\\' }) do + it('expands ' .. prefix .. ' on Windows', function() + local fname = os.getenv('USERPROFILE') .. '\\nvim_test.txt' + finally(function() + os.remove(fname) + end) + write_file(fname, 'some text') + eq( + 'some text', + fn.system({ + nvim_prog_abs(), + '-es', + '+%print', + '+q', + prefix .. 'nvim_test.txt', + }):gsub('\n', '') + ) + end) + end + end end) -- cgit From 5a8a34dafa2aa9e11df405745008543eef644bdc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 22 Jun 2024 21:17:36 +0800 Subject: fix(filetype): source ftdetect/* after creating scripts.vim autocmds (#29445) --- test/functional/core/startup_spec.lua | 40 +++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 1bb4ce2946..45f8294b16 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -1325,31 +1325,59 @@ describe('runtime:', function() end) it("loads ftdetect/*.{vim,lua} respecting 'rtp' order", function() - local ftdetect_folder = table.concat({ xconfig, 'nvim', 'ftdetect' }, pathsep) - local after_ftdetect_folder = table.concat({ xconfig, 'nvim', 'after', 'ftdetect' }, pathsep) + local rtp_folder = table.concat({ xconfig, 'nvim' }, pathsep) + local after_rtp_folder = table.concat({ rtp_folder, 'after' }, pathsep) + local ftdetect_folder = table.concat({ rtp_folder, 'ftdetect' }, pathsep) + local after_ftdetect_folder = table.concat({ after_rtp_folder, 'ftdetect' }, pathsep) mkdir_p(ftdetect_folder) mkdir_p(after_ftdetect_folder) finally(function() rmdir(ftdetect_folder) rmdir(after_ftdetect_folder) end) + write_file(table.concat({ rtp_folder, 'scripts.vim' }, pathsep), [[let g:aseq ..= 'S']]) + write_file(table.concat({ after_rtp_folder, 'scripts.vim' }, pathsep), [[let g:aseq ..= 's']]) -- A .lua file is loaded after a .vim file if they only differ in extension. -- All files in after/ftdetect/ are loaded after all files in ftdetect/. - write_file(table.concat({ ftdetect_folder, 'new-ft.vim' }, pathsep), [[let g:seq ..= 'A']]) + write_file( + table.concat({ ftdetect_folder, 'new-ft.vim' }, pathsep), + [[ + let g:seq ..= 'A' + autocmd BufRead,BufNewFile FTDETECT let g:aseq ..= 'A' + ]] + ) write_file( table.concat({ ftdetect_folder, 'new-ft.lua' }, pathsep), - [[vim.g.seq = vim.g.seq .. 'B']] + [[ + vim.g.seq = vim.g.seq .. 'B' + vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, { + pattern = 'FTDETECT', + command = "let g:aseq ..= 'B'", + }) + ]] ) write_file( table.concat({ after_ftdetect_folder, 'new-ft.vim' }, pathsep), - [[let g:seq ..= 'a']] + [[ + let g:seq ..= 'a' + autocmd BufRead,BufNewFile FTDETECT let g:aseq ..= 'a' + ]] ) write_file( table.concat({ after_ftdetect_folder, 'new-ft.lua' }, pathsep), - [[vim.g.seq = vim.g.seq .. 'b']] + [[ + vim.g.seq = vim.g.seq .. 'b' + vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, { + pattern = 'FTDETECT', + command = "let g:aseq ..= 'b'", + }) + ]] ) clear { args_rm = { '-u' }, args = { '--cmd', 'let g:seq = ""' }, env = xenv } eq('ABab', eval('g:seq')) + command('let g:aseq = ""') + command('edit FTDETECT') + eq('SsABab', eval('g:aseq')) end) end) -- cgit From 93347a67bf913c72ab2c1ba0aa4b26cc4ba6d1a8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Aug 2024 22:20:26 +0800 Subject: fix(filetype): fix :filetype detect error with -u NONE (#29991) :filetype detect should enable filetype detection when it hasn't been enabled before. --- test/functional/core/startup_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 45f8294b16..8d6ba9712a 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -112,6 +112,13 @@ describe('startup', function() |*2 ]]) end) + + it(':filetype detect enables filetype detection with -u NONE', function() + clear() + eq('filetype detection:OFF plugin:OFF indent:OFF', exec_capture('filetype')) + command('filetype detect') + eq('filetype detection:ON plugin:OFF indent:OFF', exec_capture('filetype')) + end) end) describe('startup', function() -- cgit From ea2d9493514a82bb5077e73957a22648cb5d7d14 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 3 Sep 2024 02:18:17 -0700 Subject: test: tmpname(create:boolean) #30242 Problem: 137f98cf6428 added the `create` parameter to `tmpname()` but didn't fully implement it. Solution: - Update impl for the `os.tmpname()` codepath. - Inspect all usages of `tmpname()`, update various tests. --- test/functional/core/fileio_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 1c4f42eb43..073041fced 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -325,7 +325,7 @@ describe('tmpdir', function() before_each(function() -- Fake /tmp dir so that we can mess it up. - os_tmpdir = vim.uv.fs_mkdtemp(vim.fs.dirname(t.tmpname()) .. '/nvim_XXXXXXXXXX') + os_tmpdir = vim.uv.fs_mkdtemp(vim.fs.dirname(t.tmpname(false)) .. '/nvim_XXXXXXXXXX') end) after_each(function() -- cgit From 8a2aec99748229ad9d1e12c1cbc0768d063e8eed Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Sep 2024 12:48:32 -0700 Subject: fix(startup): server fails if $NVIM_APPNAME is relative dir #30310 Problem: If $NVIM_APPNAME is a relative dir path, Nvim fails to start its primary/default server, and `v:servername` is empty. Root cause is d34c64e342dfba9248d1055e702d02620a1b31a8, but this wasn't noticed until 96128a5076b7 started reporting the error more loudly. Solution: - `server_address_new`: replace slashes "/" in the appname before using it as a servername. - `vim_mktempdir`: always prefer the system-wide top-level "nvim.user/" directory. That isn't intended to be specific to NVIM_APPNAME; rather, each *subdirectory* ("nvim.user/xxx") is owned by each Nvim instance. Nvim "apps" can be identified by the server socket(s) stored in those per-Nvim subdirs. fix #30256 --- test/functional/core/fileio_spec.lua | 15 +- test/functional/core/server_spec.lua | 278 +++++++++++++++++++++++++++++++++++ 2 files changed, 280 insertions(+), 13 deletions(-) create mode 100644 test/functional/core/server_spec.lua (limited to 'test/functional/core') diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 073041fced..d33710a63d 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -321,11 +321,11 @@ end) describe('tmpdir', function() local tmproot_pat = [=[.*[/\\]nvim%.[^/\\]+]=] local testlog = 'Xtest_tmpdir_log' - local os_tmpdir + local os_tmpdir ---@type string before_each(function() -- Fake /tmp dir so that we can mess it up. - os_tmpdir = vim.uv.fs_mkdtemp(vim.fs.dirname(t.tmpname(false)) .. '/nvim_XXXXXXXXXX') + os_tmpdir = assert(vim.uv.fs_mkdtemp(vim.fs.dirname(t.tmpname(false)) .. '/nvim_XXXXXXXXXX')) end) after_each(function() @@ -414,15 +414,4 @@ describe('tmpdir', function() rm_tmpdir() eq('E5431: tempdir disappeared (3 times)', api.nvim_get_vvar('errmsg')) end) - - it('$NVIM_APPNAME relative path', function() - clear({ - env = { - NVIM_APPNAME = 'a/b', - NVIM_LOG_FILE = testlog, - TMPDIR = os_tmpdir, - }, - }) - matches([=[.*[/\\]a%%b%.[^/\\]+]=], fn.tempname()) - end) end) diff --git a/test/functional/core/server_spec.lua b/test/functional/core/server_spec.lua new file mode 100644 index 0000000000..0ec11169e9 --- /dev/null +++ b/test/functional/core/server_spec.lua @@ -0,0 +1,278 @@ +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local eq, neq, eval = t.eq, t.neq, n.eval +local clear, fn, api = n.clear, n.fn, n.api +local matches = t.matches +local pcall_err = t.pcall_err +local check_close = n.check_close +local mkdir = t.mkdir +local rmdir = n.rmdir +local is_os = t.is_os + +local testlog = 'Xtest-server-log' + +local function clear_serverlist() + for _, server in pairs(fn.serverlist()) do + fn.serverstop(server) + end +end + +after_each(function() + check_close() + os.remove(testlog) +end) + +before_each(function() + os.remove(testlog) +end) + +describe('server', function() + it('serverstart() stores sockets in $XDG_RUNTIME_DIR', function() + local dir = 'Xtest_xdg_run' + mkdir(dir) + finally(function() + rmdir(dir) + end) + clear({ env = { XDG_RUNTIME_DIR = dir } }) + matches(dir, fn.stdpath('run')) + if not is_os('win') then + matches(dir, fn.serverstart()) + end + end) + + it('broken $XDG_RUNTIME_DIR is not fatal #30282', function() + clear { + args_rm = { '--listen' }, + env = { NVIM_LOG_FILE = testlog, XDG_RUNTIME_DIR = '/non-existent-dir/subdir//' }, + } + + if is_os('win') then + -- Windows pipes have a special namespace and thus aren't decided by $XDG_RUNTIME_DIR. + matches('nvim', api.nvim_get_vvar('servername')) + else + eq('', api.nvim_get_vvar('servername')) + t.assert_log('Failed to start server%: no such file or directory', testlog, 100) + end + end) + + it('serverstart(), serverstop() does not set $NVIM', function() + clear() + local s = eval('serverstart()') + assert(s ~= nil and s:len() > 0, 'serverstart() returned empty') + eq('', eval('$NVIM')) + eq('', eval('$NVIM_LISTEN_ADDRESS')) + eq(1, eval("serverstop('" .. s .. "')")) + eq('', eval('$NVIM_LISTEN_ADDRESS')) + end) + + it('sets v:servername at startup or if all servers were stopped', function() + clear() + local initial_server = api.nvim_get_vvar('servername') + assert(initial_server ~= nil and initial_server:len() > 0, '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 = fn.serverstart() + assert(s ~= nil and s:len() > 0, 'serverstart() returned empty') + neq(initial_server, s) + + -- serverstop() does _not_ modify v:servername... + eq(1, fn.serverstop(s)) + eq(initial_server, api.nvim_get_vvar('servername')) + + -- ...unless we stop _all_ servers. + eq(1, fn.serverstop(fn.serverlist()[1])) + eq('', api.nvim_get_vvar('servername')) + + -- v:servername and $NVIM take the next available server. + local servername = ( + is_os('win') and [[\\.\pipe\Xtest-functional-server-pipe]] + or './Xtest-functional-server-socket' + ) + fn.serverstart(servername) + eq(servername, api.nvim_get_vvar('servername')) + -- Not set in the current process, only in children. + eq('', eval('$NVIM')) + end) + + it('serverstop() returns false for invalid input', function() + clear { + args_rm = { '--listen' }, + env = { + NVIM_LOG_FILE = testlog, + NVIM_LISTEN_ADDRESS = '', + }, + } + eq(0, eval("serverstop('')")) + eq(0, eval("serverstop('bogus-socket-name')")) + t.assert_log('Not listening on bogus%-socket%-name', testlog, 10) + end) + + it('parses endpoints', function() + clear { + args_rm = { '--listen' }, + env = { + NVIM_LOG_FILE = testlog, + NVIM_LISTEN_ADDRESS = '', + }, + } + clear_serverlist() + eq({}, fn.serverlist()) + + local s = fn.serverstart('127.0.0.1:0') -- assign random port + if #s > 0 then + matches('127.0.0.1:%d+', s) + eq(s, fn.serverlist()[1]) + clear_serverlist() + end + + s = fn.serverstart('127.0.0.1:') -- assign random port + if #s > 0 then + matches('127.0.0.1:%d+', s) + eq(s, fn.serverlist()[1]) + clear_serverlist() + end + + local expected = {} + local v4 = '127.0.0.1:12345' + local status, _ = pcall(fn.serverstart, v4) + if status then + table.insert(expected, v4) + pcall(fn.serverstart, v4) -- exists already; ignore + t.assert_log('Failed to start server: address already in use: 127%.0%.0%.1', testlog, 10) + end + + local v6 = '::1:12345' + status, _ = pcall(fn.serverstart, v6) + if status then + table.insert(expected, v6) + pcall(fn.serverstart, v6) -- exists already; ignore + t.assert_log('Failed to start server: address already in use: ::1', testlog, 10) + end + eq(expected, fn.serverlist()) + clear_serverlist() + + -- Address without slashes is a "name" which is appended to a generated path. #8519 + matches([[[/\\]xtest1%.2%.3%.4[^/\\]*]], fn.serverstart('xtest1.2.3.4')) + clear_serverlist() + + eq('Vim:Failed to start server: invalid argument', pcall_err(fn.serverstart, '127.0.0.1:65536')) -- invalid port + eq({}, fn.serverlist()) + end) + + it('serverlist() returns the list of servers', function() + clear() + -- There should already be at least one server. + local _n = eval('len(serverlist())') + + -- Add some servers. + local servs = ( + is_os('win') and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] } + or { [[./Xtest-pipe0934]], [[./Xtest-pipe4324]] } + ) + for _, s in ipairs(servs) do + eq(s, eval("serverstart('" .. s .. "')")) + end + + local new_servs = eval('serverlist()') + + -- Exactly #servs servers should be added. + eq(_n + #servs, #new_servs) + -- The new servers should be at the end of the list. + for i = 1, #servs do + eq(servs[i], new_servs[i + _n]) + eq(1, eval("serverstop('" .. servs[i] .. "')")) + end + -- After serverstop() the servers should NOT be in the list. + eq(_n, eval('len(serverlist())')) + end) +end) + +describe('startup --listen', function() + -- Tests Nvim output when failing to start, with and without "--headless". + -- TODO(justinmk): clear() should have a way to get stdout if Nvim fails to start. + local function _test(args, env, expected) + local function run(cmd) + return n.exec_lua(function(cmd_, env_) + return vim + .system(cmd_, { + text = true, + env = vim.tbl_extend( + 'force', + -- Avoid noise in the logs; we expect failures for these tests. + { NVIM_LOG_FILE = testlog }, + env_ or {} + ), + }) + :wait() + end, cmd, env) --[[@as vim.SystemCompleted]] + end + + local cmd = vim.list_extend({ n.nvim_prog, '+qall!', '--headless' }, args) + local r = run(cmd) + eq(1, r.code) + matches(expected, (r.stderr .. r.stdout):gsub('\\n', ' ')) + + if is_os('win') then + return -- On Windows, output without --headless is garbage. + end + table.remove(cmd, 3) -- Remove '--headless'. + assert(not vim.tbl_contains(cmd, '--headless')) + r = run(cmd) + eq(1, r.code) + matches(expected, (r.stderr .. r.stdout):gsub('\\n', ' ')) + end + + it('validates', function() + clear { env = { NVIM_LOG_FILE = testlog } } + local in_use = n.eval('v:servername') ---@type string Address already used by another server. + + t.assert_nolog('Failed to start server', testlog, 100) + t.assert_nolog('Host lookup failed', testlog, 100) + + _test({ '--listen' }, nil, 'nvim.*: Argument missing after: "%-%-listen"') + _test({ '--listen2' }, nil, 'nvim.*: Garbage after option argument: "%-%-listen2"') + _test( + { '--listen', in_use }, + nil, + ('nvim.*: Failed to %%-%%-listen: [^:]+ already [^:]+: "%s"'):format(vim.pesc(in_use)) + ) + _test({ '--listen', '/' }, nil, 'nvim.*: Failed to %-%-listen: [^:]+: "/"') + _test( + { '--listen', 'https://example.com' }, + nil, + ('nvim.*: Failed to %%-%%-listen: %s: "https://example.com"'):format( + is_os('mac') and 'unknown node or service' or 'service not available for socket type' + ) + ) + + t.assert_log('Failed to start server', testlog, 100) + t.assert_log('Host lookup failed', testlog, 100) + + _test( + {}, + { NVIM_LISTEN_ADDRESS = in_use }, + ('nvim.*: Failed $NVIM_LISTEN_ADDRESS: [^:]+ already [^:]+: "%s"'):format(vim.pesc(in_use)) + ) + _test({}, { NVIM_LISTEN_ADDRESS = '/' }, 'nvim.*: Failed $NVIM_LISTEN_ADDRESS: [^:]+: "/"') + _test( + {}, + { NVIM_LISTEN_ADDRESS = 'https://example.com' }, + ('nvim.*: Failed $NVIM_LISTEN_ADDRESS: %s: "https://example.com"'):format( + is_os('mac') and 'unknown node or service' or 'service not available for socket type' + ) + ) + end) + + it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function() + local addr = (is_os('win') and [[\\.\pipe\Xtest-listen-pipe]] or './Xtest-listen-pipe') + clear({ env = { NVIM_LISTEN_ADDRESS = './Xtest-env-pipe' }, args = { '--listen', addr } }) + eq('', eval('$NVIM_LISTEN_ADDRESS')) -- Cleared on startup. + eq(addr, api.nvim_get_vvar('servername')) + + -- Address without slashes is a "name" which is appended to a generated path. #8519 + clear({ args = { '--listen', 'test-name' } }) + matches([[[/\\]test%-name[^/\\]*]], api.nvim_get_vvar('servername')) + end) +end) -- cgit From ed832b9ddf45705abe9d7f4a50cedc27072c8e16 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Sep 2024 21:29:20 +0200 Subject: refactor(test): rename alter_slashes, invert its behavior - `alter_slashes` belongs in `testutil.lua`, not `testnvim.lua`. - `alter_slashes` is an unusual name. Rename it to `fix_slashes`. - invert its behavior, to emphasize that `/` slashes are the preferred, pervasive convention, not `\` slashes. --- test/functional/core/startup_spec.lua | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 8d6ba9712a..f48bcb9360 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -27,7 +27,6 @@ local sleep = vim.uv.sleep local startswith = vim.startswith local write_file = t.write_file local api = n.api -local alter_slashes = n.alter_slashes local is_os = t.is_os local dedent = t.dedent local tbl_map = vim.tbl_map @@ -40,22 +39,15 @@ local testlog = 'Xtest-startupspec-log' describe('startup', function() it('--clean', function() clear() - ok( - string.find( - alter_slashes(api.nvim_get_option_value('runtimepath', {})), - fn.stdpath('config'), - 1, - true - ) ~= nil + matches( + vim.pesc(t.fix_slashes(fn.stdpath('config'))), + t.fix_slashes(api.nvim_get_option_value('runtimepath', {})) ) + clear('--clean') ok( - string.find( - alter_slashes(api.nvim_get_option_value('runtimepath', {})), - fn.stdpath('config'), - 1, - true - ) == nil + not t.fix_slashes(api.nvim_get_option_value('runtimepath', {})) + :match(vim.pesc(t.fix_slashes(fn.stdpath('config')))) ) end) -- cgit From 5931f780e0282ad486fa070bb05b3877cc1d44f0 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 11 Sep 2024 17:25:00 -0700 Subject: feat(log): use "ui" as default name for TUI client #30345 The default "session name" for the builtin TUI is "ui". before: INF 2024-09-10T14:57:35.385 hello.sock os_exit:692: Nvim exit: 1 INF 2024-09-10T14:57:35.388 ?.4543 os_exit:692: Nvim exit: 1 after: INF 2024-09-10T14:59:19.919 hello.sock os_exit:692: Nvim exit: 1 INF 2024-09-10T14:59:19.922 ui.5684 os_exit:692: Nvim exit: 1 --- test/functional/core/log_spec.lua | 57 ++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 6 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/log_spec.lua b/test/functional/core/log_spec.lua index cac61cda2d..03beedbfd3 100644 --- a/test/functional/core/log_spec.lua +++ b/test/functional/core/log_spec.lua @@ -1,5 +1,6 @@ local t = require('test.testutil') local n = require('test.functional.testnvim')() +local tt = require('test.functional.terminal.testutil') local assert_log = t.assert_log local clear = n.clear @@ -29,10 +30,54 @@ describe('log', function() assert(request('nvim__stats').log_skip <= 13) end) - it('messages are formatted with name or test id', function() + it('TUI client name is "ui"', function() + local function setup(env) + clear() + -- Start Nvim with builtin UI. + local screen = tt.setup_child_nvim({ + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + n.nvim_set, + }, { + env = env, + }) + screen:expect([[ + {1: } | + ~ |*4 + | + {3:-- TERMINAL --} | + ]]) + end + + -- Without $NVIM parent. + setup({ + NVIM = '', + NVIM_LISTEN_ADDRESS = '', + NVIM_LOG_FILE = testlog, + __NVIM_TEST_LOG = '1', + }) + -- Example: + -- ERR 2024-09-11T16:40:02.421 ui.47056 ui_client_run:165: test log message + assert_log(' ui%.%d+% +ui_client_run:%d+: test log message', testlog, 100) + + -- With $NVIM parent. + setup({ + NVIM_LOG_FILE = testlog, + __NVIM_TEST_LOG = '1', + }) + -- Example: + -- ERR 2024-09-11T16:41:17.539 ui/c/T2.47826.0 ui_client_run:165: test log message + local tid = _G._nvim_test_id + assert_log(' ui/c/' .. tid .. '%.%d+%.%d +ui_client_run:%d+: test log message', testlog, 100) + end) + + it('formats messages with session name or test id', function() -- Examples: - -- ERR 2022-05-29T12:30:03.800 T2 log_init:110: test log message - -- ERR 2022-05-29T12:30:03.814 T2/child log_init:110: test log message + -- ERR 2024-09-11T16:44:33.794 T3.49429.0 server_init:58: test log message + -- ERR 2024-09-11T16:44:33.823 c/T3.49429.0 server_init:58: test log message clear({ env = { @@ -47,10 +92,10 @@ describe('log', function() exec_lua([[ local j1 = vim.fn.jobstart({ vim.v.progpath, '-es', '-V1', '+foochild', '+qa!' }, vim.empty_dict()) - vim.fn.jobwait({ j1 }, 10000) + vim.fn.jobwait({ j1 }, 5000) ]]) - -- Child Nvim spawned by jobstart() appends "/c" to parent name. - assert_log('%.%d+%.%d/c +server_init:%d+: test log message', testlog, 100) + -- Child Nvim spawned by jobstart() prepends "c/" to parent name. + assert_log('c/' .. tid .. '%.%d+%.%d +server_init:%d+: test log message', testlog, 100) end) end) -- cgit From 5792546777332361a9ac49107e46149c703de90e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 15 Sep 2024 03:28:14 -0700 Subject: refactor(tests): rename terminal/testutil.lua => testterm.lua #30372 This module is generally used by any tests that need the full Nvim TUI instead of `screen.lua`. Thus it should live in `functional/` instead of in `functional/terminal/`. --- test/functional/core/job_spec.lua | 2 +- test/functional/core/log_spec.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index bf10033f53..68ac0a50f6 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -1,7 +1,7 @@ local t = require('test.testutil') local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local tt = require('test.functional.terminal.testutil') +local tt = require('test.functional.testterm') local clear = n.clear local eq = t.eq diff --git a/test/functional/core/log_spec.lua b/test/functional/core/log_spec.lua index 03beedbfd3..a952730779 100644 --- a/test/functional/core/log_spec.lua +++ b/test/functional/core/log_spec.lua @@ -1,6 +1,6 @@ local t = require('test.testutil') local n = require('test.functional.testnvim')() -local tt = require('test.functional.terminal.testutil') +local tt = require('test.functional.testterm') local assert_log = t.assert_log local clear = n.clear -- cgit From 80709882476206b8f1ab3c004c82a1efd039c684 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 26 Sep 2024 16:36:50 +0800 Subject: fix(channel): handle writing to file instead of pipe (#30519) --- test/functional/core/channels_spec.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index a98e190a60..dee13d19ae 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -288,6 +288,37 @@ describe('channels', function() eq({ 'notification', 'exit', { 3, 0 } }, next_msg()) end) + it('stdio channel works with stdout redirected to file #30509', function() + t.write_file( + 'Xstdio_write.vim', + [[ + let chan = stdioopen({}) + call chansend(chan, 'foo') + call chansend(chan, 'bar') + qall! + ]] + ) + local fd = assert(vim.uv.fs_open('Xstdio_redir', 'w', 420)) + local exit_code, exit_signal + local handle = vim.uv.spawn(nvim_prog, { + args = { '-u', 'NONE', '-i', 'NONE', '--headless', '-S', 'Xstdio_write.vim' }, + -- Simulate shell redirection: "nvim ... > Xstdio_redir". #30509 + stdio = { nil, fd, nil }, + }, function(code, signal) + vim.uv.stop() + exit_code, exit_signal = code, signal + end) + finally(function() + handle:close() + vim.uv.fs_close(fd) + os.remove('Xstdio_write.vim') + os.remove('Xstdio_redir') + end) + vim.uv.run('default') + eq({ 0, 0 }, { exit_code, exit_signal }) + eq('foobar', t.read_file('Xstdio_redir')) + end) + it('can use buffered output mode', function() skip(fn.executable('grep') == 0, 'missing "grep" command') source([[ -- cgit