diff options
author | Rory Nesbitt <ranesbitt@live.co.uk> | 2023-09-27 18:09:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-27 10:09:55 -0700 |
commit | a66b0fdfaa35715c832b98b8941cc5673505e0c2 (patch) | |
tree | c61ba5de9fcbcccb9209657cbe3013a0881a385d /test | |
parent | bfdec5b0e71991ebc0a8ad7c12d39f7a9cc56f07 (diff) | |
download | rneovim-a66b0fdfaa35715c832b98b8941cc5673505e0c2.tar.gz rneovim-a66b0fdfaa35715c832b98b8941cc5673505e0c2.tar.bz2 rneovim-a66b0fdfaa35715c832b98b8941cc5673505e0c2.zip |
feat: NVIM_APPNAME supports relative paths #25233
Problem:
NVIM_APPNAME does not allow path separators in the name, so relative
paths can't be used:
NVIM_APPNAME="neovim-configs/first-config" nvim
NVIM_APPNAME="neovim-configs/second-config" nvim
Solution:
Let NVIM_APPNAME be a relative path. Absolute paths are not supported.
fix #23056
fix #24966
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/core/fileio_spec.lua | 10 | ||||
-rw-r--r-- | test/functional/options/defaults_spec.lua | 25 |
2 files changed, 29 insertions, 6 deletions
diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 8de78234ce..f2b360f0d8 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -377,4 +377,14 @@ describe('tmpdir', function() rm_tmpdir() eq('E5431: tempdir disappeared (3 times)', meths.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%.[^/\\]+]=], funcs.tempname()) + end) + end) diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 9b531bcafc..7858b626de 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -598,8 +598,7 @@ describe('stdpath()', function() end) it('reacts to $NVIM_APPNAME', function() - local appname = "NVIM_APPNAME_TEST____________________________________" .. - "______________________________________________________________________" + local appname = 'NVIM_APPNAME_TEST' .. ('_'):rep(106) clear({env={ NVIM_APPNAME=appname }}) eq(appname, funcs.fnamemodify(funcs.stdpath('config'), ':t')) eq(appname, funcs.fnamemodify(funcs.stdpath('cache'), ':t')) @@ -616,10 +615,24 @@ describe('stdpath()', function() -- Check that Nvim rejects invalid APPNAMEs -- Call jobstart() and jobwait() in the same RPC request to reduce flakiness. - eq(1, exec_lua([[ - local child = vim.fn.jobstart({ vim.v.progpath }, { env = { NVIM_APPNAME = 'a/b\\c' } }) - return vim.fn.jobwait({ child }, 3000)[1] - ]])) + local function test_appname(testAppname, expected_exitcode) + local lua_code = string.format([[ + local child = vim.fn.jobstart({ vim.v.progpath, '--clean', '--headless', '+qall!' }, { env = { NVIM_APPNAME = %q } }) + return vim.fn.jobwait({ child }, %d)[1] + ]], alter_slashes(testAppname), 3000) + eq(expected_exitcode, exec_lua(lua_code)) + end + -- Invalid appnames: + test_appname('a/../b', 1) + test_appname('../a', 1) + test_appname('a/..', 1) + test_appname('..', 1) + test_appname('.', 1) + test_appname('/', 1) + test_appname(is_os('win') and 'C:/a/b' or '/a/b', 1) + -- Valid appnames: + test_appname('a/b', 0) + test_appname('a/b\\c', 0) end) describe('returns a String', function() |