From 137f98cf6428a55b1b7687c151d8481c1deb9347 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 2 Sep 2024 19:14:09 +0200 Subject: test: tmpname() can skip file creation --- test/testutil.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'test/testutil.lua') diff --git a/test/testutil.lua b/test/testutil.lua index 439f13cf49..0118f6b9e9 100644 --- a/test/testutil.lua +++ b/test/testutil.lua @@ -402,14 +402,18 @@ end local tmpname_id = 0 local tmpdir = tmpdir_get() ---- Creates a new temporary file for use by tests. -function M.tmpname() +--- Generates a unique file path for use by tests, and writes the file unless `create=false`. +--- +---@param create? boolean (default true) Write the file. +function M.tmpname(create) if tmpdir_is_local(tmpdir) then -- Cannot control os.tmpname() dir, so hack our own tmpname() impl. tmpname_id = tmpname_id + 1 -- "…/Xtest_tmpdir/T42.7" local fname = ('%s/%s.%d'):format(tmpdir, (_G._nvim_test_id or 'nvim-test'), tmpname_id) - io.open(fname, 'w'):close() + if create ~= false then + io.open(fname, 'w'):close() + end return fname end -- 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/testutil.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test/testutil.lua') diff --git a/test/testutil.lua b/test/testutil.lua index 0118f6b9e9..01eaf25406 100644 --- a/test/testutil.lua +++ b/test/testutil.lua @@ -402,7 +402,8 @@ end local tmpname_id = 0 local tmpdir = tmpdir_get() ---- Generates a unique file path for use by tests, and writes the file unless `create=false`. +--- Generates a unique filepath for use by tests, in a test-specific "…/Xtest_tmpdir/T42.7" +--- directory (which is cleaned up by the test runner), and writes the file unless `create=false`. --- ---@param create? boolean (default true) Write the file. function M.tmpname(create) @@ -418,6 +419,10 @@ function M.tmpname(create) end local fname = os.tmpname() + if create == false then + os.remove(fname) + end + if M.is_os('win') and fname:sub(1, 2) == '\\s' then -- In Windows tmpname() returns a filename starting with -- special sequence \s, prepend $TEMP path -- cgit From 975aeee537375a14c0e16916e1ef312aae90b85f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 5 Sep 2024 02:39:58 -0700 Subject: test: avoid noise in CI logs #30264 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Since 96128a5076b7 the test logs have noise from tests that *expect* failures: $NVIM_LOG_FILE: /tmp/cirrus-ci-build/build/.nvimlog (last 100 lines) ERR 2024-09-04T13:38:45.181 T949.28335.0/c terminfo_start:486: uv_pipe_open failed: no such device or address ERR 2024-09-04T13:38:45.181 T949.28335.0/c flush_buf:2527: uv_write failed: bad file descriptor ERR 2024-09-04T13:38:45.181 T949.28335.0/c flush_buf:2527: uv_write failed: bad file descriptor WRN 2024-09-04T13:43:43.294 ?.35904 server_start:173: Failed to start server: address already in use: /…/Xtest_tmpdir/…/T7159.35895.0 WRN 2024-09-04T13:43:43.314 ?.35907 server_start:173: Failed to start server: illegal operation on a directory: / ERR 2024-09-04T13:43:43.332 ?.35909 socket_watcher_init:60: Host lookup failed: https://example.com Solution: Rewrite the test to use `vim.system()`. Set NVIM_LOG_FILE in the child process to a "throwaway" logfile. --- test/testutil.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/testutil.lua') diff --git a/test/testutil.lua b/test/testutil.lua index 01eaf25406..abfc10e806 100644 --- a/test/testutil.lua +++ b/test/testutil.lua @@ -143,7 +143,7 @@ end --- ---@param pat (string) Lua pattern to match lines in the log file ---@param logfile? (string) Full path to log file (default=$NVIM_LOG_FILE) ----@param nrlines? (number) Search up to this many log lines +---@param nrlines? (number) Search up to this many log lines (default 10) ---@param inverse? (boolean) Assert that the pattern does NOT match. function M.assert_log(pat, logfile, nrlines, inverse) logfile = logfile or os.getenv('NVIM_LOG_FILE') or '.nvimlog' -- 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/testutil.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/testutil.lua') diff --git a/test/testutil.lua b/test/testutil.lua index abfc10e806..19e297c503 100644 --- a/test/testutil.lua +++ b/test/testutil.lua @@ -16,7 +16,7 @@ local function shell_quote(str) return str end ---- This module uses functions from the context of the test runner. +--- Functions executing in the context of the test runner (not the current nvim test session). --- @class test.testutil local M = { paths = Paths, -- 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/testutil.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/testutil.lua') diff --git a/test/testutil.lua b/test/testutil.lua index 19e297c503..02f343891d 100644 --- a/test/testutil.lua +++ b/test/testutil.lua @@ -42,6 +42,29 @@ function M.isdir(path) return stat.type == 'directory' end +--- (Only on Windows) Replaces yucky "\\" slashes with delicious "/" slashes in a string, or all +--- string values in a table (recursively). +--- +--- @param obj string|table +--- @return any +function M.fix_slashes(obj) + if not M.is_os('win') then + return obj + end + if type(obj) == 'string' then + local ret = obj:gsub('\\', '/') + return ret + elseif type(obj) == 'table' then + --- @cast obj table + local ret = {} --- @type table + for k, v in pairs(obj) do + ret[k] = M.fix_slashes(v) + end + return ret + end + assert(false, 'expected string or table of strings, got ' .. type(obj)) +end + --- @param ... string|string[] --- @return string function M.argss_to_cmd(...) -- cgit From 47e6b2233feffc6e9d94f6086fb904eb5688fa25 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 23 Sep 2024 06:05:58 -0700 Subject: fix(vim.fs): dirname() returns "." on mingw/msys2 #30480 Problem: `vim.fs.dirname([[C:\User\XXX\AppData\Local]])` returns "." on mingw/msys2. Solution: - Check for "mingw" when deciding `iswin`. - Use `has("win32")` where possible, it works in "fast" contexts since b02eeb6a7281df0561a021d7ae595c84be9a01be. --- test/testutil.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/testutil.lua') diff --git a/test/testutil.lua b/test/testutil.lua index 02f343891d..a920f658a1 100644 --- a/test/testutil.lua +++ b/test/testutil.lua @@ -392,7 +392,7 @@ function M.check_logs() ) end -function M.sysname() +local function sysname() return uv.os_uname().sysname:lower() end @@ -403,11 +403,11 @@ function M.is_os(s) error('unknown platform: ' .. tostring(s)) end return not not ( - (s == 'win' and (M.sysname():find('windows') or M.sysname():find('mingw'))) - or (s == 'mac' and M.sysname() == 'darwin') - or (s == 'freebsd' and M.sysname() == 'freebsd') - or (s == 'openbsd' and M.sysname() == 'openbsd') - or (s == 'bsd' and M.sysname():find('bsd')) + (s == 'win' and (sysname():find('windows') or sysname():find('mingw'))) + or (s == 'mac' and sysname() == 'darwin') + or (s == 'freebsd' and sysname() == 'freebsd') + or (s == 'openbsd' and sysname() == 'openbsd') + or (s == 'bsd' and sysname():find('bsd')) ) end -- cgit