2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2016-04-10 22:59:32 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2016-06-26 08:16:54 -07:00
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local assert_alive = n.assert_alive
|
2024-04-08 02:03:20 -07:00
|
|
|
local assert_log = t.assert_log
|
2024-04-20 08:44:13 -07:00
|
|
|
local api = n.api
|
|
|
|
local command = n.command
|
|
|
|
local clear = n.clear
|
|
|
|
local exc_exec = n.exc_exec
|
|
|
|
local exec_lua = n.exec_lua
|
|
|
|
local eval = n.eval
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
|
|
|
local ok = t.ok
|
2024-04-20 08:44:13 -07:00
|
|
|
local fn = n.fn
|
|
|
|
local insert = n.insert
|
2024-04-08 02:03:20 -07:00
|
|
|
local neq = t.neq
|
|
|
|
local mkdir = t.mkdir
|
2024-04-20 08:44:13 -07:00
|
|
|
local rmdir = n.rmdir
|
|
|
|
local alter_slashes = n.alter_slashes
|
2024-01-12 04:28:20 -07:00
|
|
|
local tbl_contains = vim.tbl_contains
|
2024-04-20 08:44:13 -07:00
|
|
|
local expect_exit = n.expect_exit
|
|
|
|
local check_close = n.check_close
|
2024-04-08 02:03:20 -07:00
|
|
|
local is_os = t.is_os
|
2016-04-10 22:59:32 -07:00
|
|
|
|
2023-01-16 12:43:13 -07:00
|
|
|
local testlog = 'Xtest-defaults-log'
|
|
|
|
|
2016-04-10 22:59:32 -07:00
|
|
|
describe('startup defaults', function()
|
|
|
|
describe(':filetype', function()
|
|
|
|
local function expect_filetype(expected)
|
2017-04-26 13:50:36 -07:00
|
|
|
local screen = Screen.new(50, 4)
|
2016-04-10 22:59:32 -07:00
|
|
|
screen:attach()
|
2017-04-08 14:12:26 -07:00
|
|
|
command('filetype')
|
2016-04-10 22:59:32 -07:00
|
|
|
screen:expect([[
|
2017-04-26 13:50:36 -07:00
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*2
|
2016-04-10 22:59:32 -07:00
|
|
|
]] .. expected)
|
|
|
|
end
|
|
|
|
|
2018-01-03 11:57:22 -07:00
|
|
|
it('all ON after `-u NORC`', function()
|
|
|
|
clear('-u', 'NORC')
|
2017-04-26 13:50:36 -07:00
|
|
|
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
|
2016-04-10 22:59:32 -07:00
|
|
|
end)
|
|
|
|
|
2018-01-03 11:57:22 -07:00
|
|
|
it('all ON after `:syntax …` #7765', function()
|
|
|
|
clear('-u', 'NORC', '--cmd', 'syntax on')
|
|
|
|
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
|
|
|
|
clear('-u', 'NORC', '--cmd', 'syntax off')
|
|
|
|
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
|
2016-04-10 22:59:32 -07:00
|
|
|
end)
|
|
|
|
|
2018-01-03 11:57:22 -07:00
|
|
|
it('all OFF after `-u NONE`', function()
|
|
|
|
clear('-u', 'NONE')
|
|
|
|
expect_filetype('filetype detection:OFF plugin:OFF indent:OFF |')
|
2016-04-10 22:59:32 -07:00
|
|
|
end)
|
|
|
|
|
2018-01-03 11:57:22 -07:00
|
|
|
it('explicit OFF stays OFF', function()
|
|
|
|
clear('-u', 'NORC', '--cmd', 'syntax off | filetype off | filetype plugin indent off')
|
|
|
|
expect_filetype('filetype detection:OFF plugin:OFF indent:OFF |')
|
|
|
|
clear('-u', 'NORC', '--cmd', 'syntax off | filetype plugin indent off')
|
|
|
|
expect_filetype('filetype detection:ON plugin:OFF indent:OFF |')
|
|
|
|
clear('-u', 'NORC', '--cmd', 'filetype indent off')
|
2017-04-26 13:50:36 -07:00
|
|
|
expect_filetype('filetype detection:ON plugin:ON indent:OFF |')
|
2018-01-03 11:57:22 -07:00
|
|
|
clear('-u', 'NORC', '--cmd', 'syntax off | filetype off')
|
|
|
|
expect_filetype('filetype detection:OFF plugin:(on) indent:(on) |')
|
|
|
|
-- Swap the order.
|
|
|
|
clear('-u', 'NORC', '--cmd', 'filetype off | syntax off')
|
|
|
|
expect_filetype('filetype detection:OFF plugin:(on) indent:(on) |')
|
2016-04-10 22:59:32 -07:00
|
|
|
end)
|
|
|
|
|
2018-01-03 11:57:22 -07:00
|
|
|
it('all ON after early `:filetype … on`', function()
|
|
|
|
-- `:filetype … on` should not change the defaults. #7765
|
|
|
|
-- Only an explicit `:filetype … off` sets OFF.
|
|
|
|
|
|
|
|
clear('-u', 'NORC', '--cmd', 'filetype on')
|
|
|
|
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
|
|
|
|
clear('-u', 'NORC', '--cmd', 'filetype plugin on')
|
|
|
|
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
|
|
|
|
clear('-u', 'NORC', '--cmd', 'filetype indent on')
|
|
|
|
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
|
2017-04-26 13:50:36 -07:00
|
|
|
end)
|
|
|
|
|
2018-01-03 11:57:22 -07:00
|
|
|
it('late `:filetype … off` stays OFF', function()
|
|
|
|
clear('-u', 'NORC', '-c', 'filetype off')
|
2017-04-26 13:50:36 -07:00
|
|
|
expect_filetype('filetype detection:OFF plugin:(on) indent:(on) |')
|
2018-01-03 11:57:22 -07:00
|
|
|
clear('-u', 'NORC', '-c', 'filetype plugin off')
|
2017-04-26 13:50:36 -07:00
|
|
|
expect_filetype('filetype detection:ON plugin:OFF indent:ON |')
|
2018-01-03 11:57:22 -07:00
|
|
|
clear('-u', 'NORC', '-c', 'filetype indent off')
|
2017-04-26 13:50:36 -07:00
|
|
|
expect_filetype('filetype detection:ON plugin:ON indent:OFF |')
|
2016-04-10 22:59:32 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('syntax', function()
|
|
|
|
it('enabled by `-u NORC`', function()
|
2018-01-03 11:57:22 -07:00
|
|
|
clear('-u', 'NORC')
|
2016-04-10 22:59:32 -07:00
|
|
|
eq(1, eval('g:syntax_on'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('disabled by `-u NONE`', function()
|
2018-01-03 11:57:22 -07:00
|
|
|
clear('-u', 'NONE')
|
2016-04-10 22:59:32 -07:00
|
|
|
eq(0, eval('exists("g:syntax_on")'))
|
|
|
|
end)
|
|
|
|
|
2018-01-03 11:57:22 -07:00
|
|
|
it('`:syntax off` stays off', function()
|
|
|
|
-- early
|
|
|
|
clear('-u', 'NORC', '--cmd', 'syntax off')
|
2016-04-10 22:59:32 -07:00
|
|
|
eq(0, eval('exists("g:syntax_on")'))
|
2018-01-03 11:57:22 -07:00
|
|
|
-- late
|
|
|
|
clear('-u', 'NORC', '-c', 'syntax off')
|
2017-04-26 13:50:36 -07:00
|
|
|
eq(0, eval('exists("g:syntax_on")'))
|
|
|
|
end)
|
2018-07-18 05:30:11 -07:00
|
|
|
|
|
|
|
it('":if 0|syntax on|endif" does not affect default #8728', function()
|
|
|
|
clear('-u', 'NORC', '--cmd', ':if 0|syntax on|endif')
|
|
|
|
eq(1, eval('exists("g:syntax_on")'))
|
|
|
|
clear('-u', 'NORC', '--cmd', ':if 0|syntax off|endif')
|
|
|
|
eq(1, eval('exists("g:syntax_on")'))
|
|
|
|
end)
|
2016-04-10 22:59:32 -07:00
|
|
|
end)
|
2016-08-08 15:19:26 -07:00
|
|
|
|
2018-02-08 16:44:24 -07:00
|
|
|
describe("'fillchars'", function()
|
|
|
|
it('vert/fold flags', function()
|
|
|
|
clear()
|
|
|
|
local screen = Screen.new(50, 5)
|
|
|
|
screen:attach()
|
|
|
|
command('set laststatus=0')
|
|
|
|
insert([[
|
|
|
|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4]])
|
|
|
|
command('normal! ggjzfj')
|
|
|
|
command('vsp')
|
|
|
|
screen:expect([[
|
|
|
|
1 │1 |
|
2024-03-22 03:02:52 -07:00
|
|
|
{13:^+-- 2 lines: 2··········}│{13:+-- 2 lines: 2·········}|
|
2018-02-08 16:44:24 -07:00
|
|
|
4 │4 |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }│{1:~ }|
|
2018-02-08 16:44:24 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- ambiwidth=double defaults to single-byte fillchars.
|
|
|
|
command('set ambiwidth=double')
|
|
|
|
screen:expect([[
|
|
|
|
1 |1 |
|
2024-03-22 03:02:52 -07:00
|
|
|
{13:^+-- 2 lines: 2----------}|{13:+-- 2 lines: 2---------}|
|
2018-02-08 16:44:24 -07:00
|
|
|
4 |4 |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|{1:~ }|
|
2018-02-08 16:44:24 -07:00
|
|
|
|
|
|
|
|
]])
|
2022-08-07 23:59:07 -07:00
|
|
|
|
|
|
|
-- change "vert" character to single-cell
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setcellwidths({ { 0x2502, 0x2502, 1 } })
|
2022-08-07 23:59:07 -07:00
|
|
|
screen:expect([[
|
|
|
|
1 │1 |
|
2024-03-22 03:02:52 -07:00
|
|
|
{13:^+-- 2 lines: 2----------}│{13:+-- 2 lines: 2---------}|
|
2022-08-07 23:59:07 -07:00
|
|
|
4 │4 |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }│{1:~ }|
|
2022-08-07 23:59:07 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- change "vert" character to double-cell
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setcellwidths({ { 0x2502, 0x2502, 2 } })
|
2022-08-07 23:59:07 -07:00
|
|
|
screen:expect([[
|
|
|
|
1 |1 |
|
2024-03-22 03:02:52 -07:00
|
|
|
{13:^+-- 2 lines: 2----------}|{13:+-- 2 lines: 2---------}|
|
2022-08-07 23:59:07 -07:00
|
|
|
4 |4 |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|{1:~ }|
|
2022-08-07 23:59:07 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- "vert" character should still default to single-byte fillchars because of setcellwidths().
|
|
|
|
command('set ambiwidth=single')
|
|
|
|
screen:expect([[
|
|
|
|
1 |1 |
|
2024-03-22 03:02:52 -07:00
|
|
|
{13:^+-- 2 lines: 2··········}|{13:+-- 2 lines: 2·········}|
|
2022-08-07 23:59:07 -07:00
|
|
|
4 |4 |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|{1:~ }|
|
2022-08-07 23:59:07 -07:00
|
|
|
|
|
|
|
|
]])
|
2018-02-08 16:44:24 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2019-04-16 12:33:40 -07:00
|
|
|
it("'shadafile' ('viminfofile')", function()
|
2021-09-06 10:35:34 -07:00
|
|
|
local env = {
|
|
|
|
XDG_DATA_HOME = 'Xtest-userdata',
|
|
|
|
XDG_STATE_HOME = 'Xtest-userstate',
|
|
|
|
XDG_CONFIG_HOME = 'Xtest-userconfig',
|
|
|
|
}
|
2023-08-03 19:37:47 -07:00
|
|
|
finally(function()
|
|
|
|
command('set shadafile=NONE') -- Avoid writing shada file on exit
|
|
|
|
rmdir('Xtest-userstate')
|
|
|
|
os.remove('Xtest-foo')
|
|
|
|
end)
|
|
|
|
|
2019-04-16 16:08:48 -07:00
|
|
|
clear { args = {}, args_rm = { '-i' }, env = env }
|
2019-04-16 12:33:40 -07:00
|
|
|
-- Default 'shadafile' is empty.
|
|
|
|
-- This means use the default location. :help shada-file-name
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('', api.nvim_get_option_value('shadafile', {}))
|
|
|
|
eq('', api.nvim_get_option_value('viminfofile', {}))
|
2023-08-03 19:37:47 -07:00
|
|
|
-- Handles viminfo/viminfofile as alias for shada/shadafile.
|
|
|
|
eq('\n shadafile=', eval('execute("set shadafile?")'))
|
|
|
|
eq('\n shadafile=', eval('execute("set viminfofile?")'))
|
|
|
|
eq("\n shada=!,'100,<50,s10,h", eval('execute("set shada?")'))
|
|
|
|
eq("\n shada=!,'100,<50,s10,h", eval('execute("set viminfo?")'))
|
|
|
|
|
2019-04-16 12:33:40 -07:00
|
|
|
-- Check that shada data (such as v:oldfiles) is saved/restored.
|
2019-04-16 16:08:48 -07:00
|
|
|
command('edit Xtest-foo')
|
2019-04-16 12:33:40 -07:00
|
|
|
command('write')
|
|
|
|
local f = eval('fnamemodify(@%,":p")')
|
|
|
|
assert(string.len(f) > 3)
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(command, 'qall')
|
2019-04-16 16:08:48 -07:00
|
|
|
clear { args = {}, args_rm = { '-i' }, env = env }
|
2019-04-16 12:33:40 -07:00
|
|
|
eq({ f }, eval('v:oldfiles'))
|
|
|
|
end)
|
2016-08-08 15:19:26 -07:00
|
|
|
|
2019-04-16 12:33:40 -07:00
|
|
|
it("'packpath'", function()
|
2022-09-24 17:20:47 -07:00
|
|
|
clear {
|
|
|
|
args_rm = { 'runtimepath' },
|
|
|
|
}
|
2019-04-16 12:33:40 -07:00
|
|
|
-- Defaults to &runtimepath.
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(api.nvim_get_option_value('runtimepath', {}), api.nvim_get_option_value('packpath', {}))
|
2019-04-16 12:33:40 -07:00
|
|
|
|
|
|
|
-- Does not follow modifications to runtimepath.
|
2024-01-12 06:11:28 -07:00
|
|
|
command('set runtimepath+=foo')
|
2024-01-12 10:59:57 -07:00
|
|
|
neq(api.nvim_get_option_value('runtimepath', {}), api.nvim_get_option_value('packpath', {}))
|
2024-01-12 06:11:28 -07:00
|
|
|
command('set packpath+=foo')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(api.nvim_get_option_value('runtimepath', {}), api.nvim_get_option_value('packpath', {}))
|
2016-08-08 15:19:26 -07:00
|
|
|
end)
|
2017-02-02 05:16:15 -07:00
|
|
|
|
|
|
|
it('v:progpath is set to the absolute path', function()
|
2019-04-16 12:33:40 -07:00
|
|
|
clear()
|
2017-02-02 05:16:15 -07:00
|
|
|
eq(eval("fnamemodify(v:progpath, ':p')"), eval('v:progpath'))
|
|
|
|
end)
|
2017-05-30 17:04:03 -07:00
|
|
|
|
|
|
|
describe('$NVIM_LOG_FILE', function()
|
2017-05-31 09:12:26 -07:00
|
|
|
local xdgdir = 'Xtest-startup-xdg-logpath'
|
2022-11-21 17:13:30 -07:00
|
|
|
local xdgstatedir = is_os('win') and xdgdir .. '/nvim-data' or xdgdir .. '/nvim'
|
2017-05-30 17:04:03 -07:00
|
|
|
after_each(function()
|
|
|
|
os.remove('Xtest-logpath')
|
2017-05-31 09:12:26 -07:00
|
|
|
rmdir(xdgdir)
|
2017-05-30 17:04:03 -07:00
|
|
|
end)
|
2017-05-31 09:12:26 -07:00
|
|
|
|
2017-05-30 17:04:03 -07:00
|
|
|
it('is used if expansion succeeds', function()
|
|
|
|
clear({ env = {
|
|
|
|
NVIM_LOG_FILE = 'Xtest-logpath',
|
|
|
|
} })
|
|
|
|
eq('Xtest-logpath', eval('$NVIM_LOG_FILE'))
|
|
|
|
end)
|
2021-09-06 10:35:34 -07:00
|
|
|
it('defaults to stdpath("log")/log if empty', function()
|
|
|
|
eq(true, mkdir(xdgdir) and mkdir(xdgstatedir))
|
2017-05-30 17:04:03 -07:00
|
|
|
clear({
|
|
|
|
env = {
|
2021-09-06 10:35:34 -07:00
|
|
|
XDG_STATE_HOME = xdgdir,
|
2017-05-31 09:12:26 -07:00
|
|
|
NVIM_LOG_FILE = '', -- Empty is invalid.
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2017-05-30 17:04:03 -07:00
|
|
|
})
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(xdgstatedir .. '/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
|
2017-05-30 17:04:03 -07:00
|
|
|
end)
|
2021-09-06 10:35:34 -07:00
|
|
|
it('defaults to stdpath("log")/log if invalid', function()
|
|
|
|
eq(true, mkdir(xdgdir) and mkdir(xdgstatedir))
|
2017-05-30 17:04:03 -07:00
|
|
|
clear({
|
|
|
|
env = {
|
2021-09-06 10:35:34 -07:00
|
|
|
XDG_STATE_HOME = xdgdir,
|
2017-05-31 09:12:26 -07:00
|
|
|
NVIM_LOG_FILE = '.', -- Any directory is invalid.
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2017-05-30 17:04:03 -07:00
|
|
|
})
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(xdgstatedir .. '/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
|
2017-05-31 09:12:26 -07:00
|
|
|
end)
|
2017-05-30 17:04:03 -07:00
|
|
|
end)
|
2016-04-10 22:59:32 -07:00
|
|
|
end)
|
2016-06-26 08:16:54 -07:00
|
|
|
|
2022-06-30 04:16:46 -07:00
|
|
|
describe('XDG defaults', function()
|
2016-08-31 04:04:47 -07:00
|
|
|
-- Need separate describe() blocks to not run clear() twice.
|
2016-06-26 08:16:54 -07:00
|
|
|
-- Do not put before_each() here for the same reasons.
|
2016-08-31 04:04:47 -07:00
|
|
|
|
2023-01-16 12:43:13 -07:00
|
|
|
after_each(function()
|
2024-04-05 20:18:43 -07:00
|
|
|
check_close()
|
2023-01-16 12:43:13 -07:00
|
|
|
os.remove(testlog)
|
|
|
|
end)
|
|
|
|
|
2019-04-15 14:44:10 -07:00
|
|
|
it("&runtimepath data-dir matches stdpath('data') #9910", function()
|
|
|
|
clear()
|
|
|
|
local rtp = eval('split(&runtimepath, ",")')
|
|
|
|
local rv = {}
|
2022-11-21 17:13:30 -07:00
|
|
|
local expected = (
|
2019-04-15 14:44:10 -07:00
|
|
|
is_os('win') and { [[\nvim-data\site]], [[\nvim-data\site\after]] }
|
|
|
|
or { '/nvim/site', '/nvim/site/after' }
|
|
|
|
)
|
|
|
|
|
|
|
|
for _, v in ipairs(rtp) do
|
|
|
|
local m = string.match(v, [=[[/\]nvim[^/\]*[/\]site.*$]=])
|
2019-05-18 07:00:06 -07:00
|
|
|
if m and not tbl_contains(rv, m) then
|
2019-04-15 14:44:10 -07:00
|
|
|
table.insert(rv, m)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
eq(expected, rv)
|
|
|
|
end)
|
|
|
|
|
2016-08-31 04:04:47 -07:00
|
|
|
describe('with empty/broken environment', function()
|
|
|
|
it('sets correct defaults', function()
|
|
|
|
clear({
|
|
|
|
env = {
|
|
|
|
XDG_CONFIG_HOME = nil,
|
|
|
|
XDG_DATA_HOME = nil,
|
|
|
|
XDG_CACHE_HOME = nil,
|
2021-09-06 10:35:34 -07:00
|
|
|
XDG_STATE_HOME = nil,
|
2016-08-31 04:04:47 -07:00
|
|
|
XDG_RUNTIME_DIR = nil,
|
|
|
|
XDG_CONFIG_DIRS = nil,
|
|
|
|
XDG_DATA_DIRS = nil,
|
|
|
|
LOCALAPPDATA = nil,
|
|
|
|
HOMEPATH = nil,
|
|
|
|
HOMEDRIVE = nil,
|
|
|
|
HOME = nil,
|
|
|
|
TEMP = nil,
|
|
|
|
VIMRUNTIME = nil,
|
|
|
|
USER = nil,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2016-08-31 04:04:47 -07:00
|
|
|
})
|
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('.', api.nvim_get_option_value('backupdir', {}))
|
|
|
|
eq('.', api.nvim_get_option_value('viewdir', {}))
|
|
|
|
eq('.', api.nvim_get_option_value('directory', {}))
|
|
|
|
eq('.', api.nvim_get_option_value('undodir', {}))
|
|
|
|
ok((fn.tempname()):len() > 4)
|
2016-08-31 04:04:47 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2020-02-02 15:29:33 -07:00
|
|
|
local function vimruntime_and_libdir()
|
|
|
|
local vimruntime = eval('$VIMRUNTIME')
|
2020-02-06 05:41:57 -07:00
|
|
|
-- libdir is hard to calculate reliably across various ci platforms
|
|
|
|
-- local libdir = string.gsub(vimruntime, "share/nvim/runtime$", "lib/nvim")
|
2024-01-12 10:59:57 -07:00
|
|
|
local libdir = api.nvim__get_lib_dir()
|
2020-02-02 15:29:33 -07:00
|
|
|
return vimruntime, libdir
|
|
|
|
end
|
|
|
|
|
2022-11-21 17:13:30 -07:00
|
|
|
local env_sep = is_os('win') and ';' or ':'
|
|
|
|
local data_dir = is_os('win') and 'nvim-data' or 'nvim'
|
|
|
|
local state_dir = is_os('win') and 'nvim-data' or 'nvim'
|
|
|
|
local root_path = is_os('win') and 'C:' or ''
|
2020-09-07 22:40:12 -07:00
|
|
|
|
2016-06-26 08:16:54 -07:00
|
|
|
describe('with too long XDG variables', function()
|
|
|
|
before_each(function()
|
2022-09-24 17:20:47 -07:00
|
|
|
clear({
|
|
|
|
args_rm = { 'runtimepath' },
|
|
|
|
env = {
|
2023-01-16 12:43:13 -07:00
|
|
|
NVIM_LOG_FILE = testlog,
|
2022-09-24 17:20:47 -07:00
|
|
|
XDG_CONFIG_HOME = (root_path .. ('/x'):rep(4096)),
|
|
|
|
XDG_CONFIG_DIRS = (root_path .. ('/a'):rep(2048) .. env_sep .. root_path .. ('/b'):rep(
|
|
|
|
2048
|
|
|
|
) .. (env_sep .. root_path .. '/c'):rep(512)),
|
|
|
|
XDG_DATA_HOME = (root_path .. ('/X'):rep(4096)),
|
|
|
|
XDG_RUNTIME_DIR = (root_path .. ('/X'):rep(4096)),
|
|
|
|
XDG_STATE_HOME = (root_path .. ('/X'):rep(4096)),
|
|
|
|
XDG_DATA_DIRS = (root_path .. ('/A'):rep(2048) .. env_sep .. root_path .. ('/B'):rep(
|
2024-01-02 18:09:18 -07:00
|
|
|
2048
|
2022-09-24 17:20:47 -07:00
|
|
|
) .. (env_sep .. root_path .. '/C'):rep(512)),
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2016-06-26 08:16:54 -07:00
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('are correctly set', function()
|
2023-01-16 17:54:35 -07:00
|
|
|
if not is_os('win') then
|
|
|
|
assert_log('Failed to start server: no such file or directory: /X/X/X', testlog, 10)
|
|
|
|
end
|
2023-01-16 12:43:13 -07:00
|
|
|
|
2020-02-02 15:29:33 -07:00
|
|
|
local vimruntime, libdir = vimruntime_and_libdir()
|
|
|
|
|
2020-09-07 22:40:12 -07:00
|
|
|
eq(
|
2024-01-02 18:09:18 -07:00
|
|
|
(
|
|
|
|
(
|
2020-09-07 22:40:12 -07:00
|
|
|
root_path
|
|
|
|
.. ('/x'):rep(4096)
|
|
|
|
.. '/nvim'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/a'):rep(2048)
|
|
|
|
.. '/nvim'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/b'):rep(2048)
|
|
|
|
.. '/nvim'
|
2024-04-03 03:44:57 -07:00
|
|
|
.. (',' .. root_path .. '/c/nvim')
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/X'):rep(4096)
|
|
|
|
.. '/'
|
|
|
|
.. data_dir
|
|
|
|
.. '/site'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/A'):rep(2048)
|
|
|
|
.. '/nvim/site'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/B'):rep(2048)
|
|
|
|
.. '/nvim/site'
|
2024-04-03 03:44:57 -07:00
|
|
|
.. (',' .. root_path .. '/C/nvim/site')
|
2020-02-02 15:29:33 -07:00
|
|
|
.. ','
|
|
|
|
.. vimruntime
|
|
|
|
.. ','
|
|
|
|
.. libdir
|
2024-04-03 03:44:57 -07:00
|
|
|
.. (',' .. root_path .. '/C/nvim/site/after')
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/B'):rep(2048)
|
|
|
|
.. '/nvim/site/after'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/A'):rep(2048)
|
|
|
|
.. '/nvim/site/after'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/X'):rep(4096)
|
|
|
|
.. '/'
|
|
|
|
.. data_dir
|
|
|
|
.. '/site/after'
|
2024-04-03 03:44:57 -07:00
|
|
|
.. (',' .. root_path .. '/c/nvim/after')
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/b'):rep(2048)
|
|
|
|
.. '/nvim/after'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/a'):rep(2048)
|
|
|
|
.. '/nvim/after'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/x'):rep(4096)
|
|
|
|
.. '/nvim/after'
|
2022-12-19 09:37:45 -07:00
|
|
|
):gsub('\\', '/')
|
|
|
|
),
|
2024-01-12 10:59:57 -07:00
|
|
|
(api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 06:11:28 -07:00
|
|
|
command('set runtimepath&')
|
|
|
|
command('set backupdir&')
|
|
|
|
command('set directory&')
|
|
|
|
command('set undodir&')
|
|
|
|
command('set viewdir&')
|
2020-09-07 22:40:12 -07:00
|
|
|
eq(
|
2024-01-02 18:09:18 -07:00
|
|
|
(
|
|
|
|
(
|
2020-09-07 22:40:12 -07:00
|
|
|
root_path
|
|
|
|
.. ('/x'):rep(4096)
|
|
|
|
.. '/nvim'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/a'):rep(2048)
|
|
|
|
.. '/nvim'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/b'):rep(2048)
|
|
|
|
.. '/nvim'
|
2024-04-03 03:44:57 -07:00
|
|
|
.. (',' .. root_path .. '/c/nvim')
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/X'):rep(4096)
|
|
|
|
.. '/'
|
|
|
|
.. data_dir
|
|
|
|
.. '/site'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/A'):rep(2048)
|
|
|
|
.. '/nvim/site'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/B'):rep(2048)
|
2016-06-26 08:16:54 -07:00
|
|
|
.. '/nvim/site'
|
2024-04-03 03:44:57 -07:00
|
|
|
.. (',' .. root_path .. '/C/nvim/site')
|
2020-02-02 15:29:33 -07:00
|
|
|
.. ','
|
|
|
|
.. vimruntime
|
|
|
|
.. ','
|
|
|
|
.. libdir
|
2024-04-03 03:44:57 -07:00
|
|
|
.. (',' .. root_path .. '/C/nvim/site/after')
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/B'):rep(2048)
|
|
|
|
.. '/nvim/site/after'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/A'):rep(2048)
|
|
|
|
.. '/nvim/site/after'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/X'):rep(4096)
|
|
|
|
.. '/'
|
|
|
|
.. data_dir
|
|
|
|
.. '/site/after'
|
2024-04-03 03:44:57 -07:00
|
|
|
.. (',' .. root_path .. '/c/nvim/after')
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/b'):rep(2048)
|
|
|
|
.. '/nvim/after'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/a'):rep(2048)
|
|
|
|
.. '/nvim/after'
|
|
|
|
.. ','
|
|
|
|
.. root_path
|
|
|
|
.. ('/x'):rep(4096)
|
|
|
|
.. '/nvim/after'
|
2022-12-19 09:37:45 -07:00
|
|
|
):gsub('\\', '/')
|
|
|
|
),
|
2024-01-12 10:59:57 -07:00
|
|
|
(api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
'.,' .. root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/backup//',
|
2024-01-12 10:59:57 -07:00
|
|
|
(api.nvim_get_option_value('backupdir', {}):gsub('\\', '/'))
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/swap//',
|
2024-01-12 10:59:57 -07:00
|
|
|
(api.nvim_get_option_value('directory', {})):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/undo//',
|
2024-01-12 10:59:57 -07:00
|
|
|
(api.nvim_get_option_value('undodir', {})):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/view//',
|
2024-01-12 10:59:57 -07:00
|
|
|
(api.nvim_get_option_value('viewdir', {})):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2016-06-26 08:16:54 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('with XDG variables that can be expanded', function()
|
|
|
|
before_each(function()
|
2022-09-24 17:20:47 -07:00
|
|
|
clear({
|
|
|
|
args_rm = { 'runtimepath' },
|
|
|
|
env = {
|
2023-01-16 12:43:13 -07:00
|
|
|
NVIM_LOG_FILE = testlog,
|
2022-09-24 17:20:47 -07:00
|
|
|
XDG_CONFIG_HOME = '$XDG_DATA_HOME',
|
|
|
|
XDG_CONFIG_DIRS = '$XDG_DATA_DIRS',
|
|
|
|
XDG_DATA_HOME = '$XDG_CONFIG_HOME',
|
|
|
|
XDG_RUNTIME_DIR = '$XDG_RUNTIME_DIR',
|
|
|
|
XDG_STATE_HOME = '$XDG_CONFIG_HOME',
|
|
|
|
XDG_DATA_DIRS = '$XDG_CONFIG_DIRS',
|
2023-08-03 19:37:47 -07:00
|
|
|
},
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
command('set shadafile=NONE') -- Avoid writing shada file on exit
|
2016-06-26 08:16:54 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('are not expanded', function()
|
2023-01-16 17:54:35 -07:00
|
|
|
if not is_os('win') then
|
|
|
|
assert_log(
|
|
|
|
'Failed to start server: no such file or directory: %$XDG_RUNTIME_DIR%/',
|
|
|
|
testlog,
|
|
|
|
10
|
|
|
|
)
|
|
|
|
end
|
2023-01-16 16:12:59 -07:00
|
|
|
|
2020-02-02 15:29:33 -07:00
|
|
|
local vimruntime, libdir = vimruntime_and_libdir()
|
2020-09-07 22:40:12 -07:00
|
|
|
eq(
|
2024-01-02 18:09:18 -07:00
|
|
|
(
|
|
|
|
(
|
2020-09-07 22:40:12 -07:00
|
|
|
'$XDG_DATA_HOME/nvim'
|
2016-06-26 08:16:54 -07:00
|
|
|
.. ',$XDG_DATA_DIRS/nvim'
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ',$XDG_CONFIG_HOME/'
|
|
|
|
.. data_dir
|
|
|
|
.. '/site'
|
2016-06-26 08:16:54 -07:00
|
|
|
.. ',$XDG_CONFIG_DIRS/nvim/site'
|
2020-02-02 15:29:33 -07:00
|
|
|
.. ','
|
|
|
|
.. vimruntime
|
|
|
|
.. ','
|
|
|
|
.. libdir
|
2016-06-26 08:16:54 -07:00
|
|
|
.. ',$XDG_CONFIG_DIRS/nvim/site/after'
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ',$XDG_CONFIG_HOME/'
|
|
|
|
.. data_dir
|
|
|
|
.. '/site/after'
|
2016-06-26 08:16:54 -07:00
|
|
|
.. ',$XDG_DATA_DIRS/nvim/after'
|
|
|
|
.. ',$XDG_DATA_HOME/nvim/after'
|
2022-12-19 09:37:45 -07:00
|
|
|
):gsub('\\', '/')
|
|
|
|
),
|
2024-01-12 10:59:57 -07:00
|
|
|
(api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 06:11:28 -07:00
|
|
|
command('set runtimepath&')
|
|
|
|
command('set backupdir&')
|
|
|
|
command('set directory&')
|
|
|
|
command('set undodir&')
|
|
|
|
command('set viewdir&')
|
2020-09-07 22:40:12 -07:00
|
|
|
eq(
|
2024-01-02 18:09:18 -07:00
|
|
|
(
|
|
|
|
(
|
2020-09-07 22:40:12 -07:00
|
|
|
'$XDG_DATA_HOME/nvim'
|
2016-06-26 08:16:54 -07:00
|
|
|
.. ',$XDG_DATA_DIRS/nvim'
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ',$XDG_CONFIG_HOME/'
|
|
|
|
.. data_dir
|
|
|
|
.. '/site'
|
2016-06-26 08:16:54 -07:00
|
|
|
.. ',$XDG_CONFIG_DIRS/nvim/site'
|
2020-02-02 15:29:33 -07:00
|
|
|
.. ','
|
|
|
|
.. vimruntime
|
|
|
|
.. ','
|
|
|
|
.. libdir
|
2016-06-26 08:16:54 -07:00
|
|
|
.. ',$XDG_CONFIG_DIRS/nvim/site/after'
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ',$XDG_CONFIG_HOME/'
|
|
|
|
.. data_dir
|
|
|
|
.. '/site/after'
|
2016-06-26 08:16:54 -07:00
|
|
|
.. ',$XDG_DATA_DIRS/nvim/after'
|
|
|
|
.. ',$XDG_DATA_HOME/nvim/after'
|
2022-12-19 09:37:45 -07:00
|
|
|
):gsub('\\', '/')
|
|
|
|
),
|
2024-01-12 10:59:57 -07:00
|
|
|
(api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('backupdir', {}):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('directory', {}):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('undodir', {}):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('viewdir', {}):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 06:11:28 -07:00
|
|
|
command('set all&')
|
2016-06-26 08:22:11 -07:00
|
|
|
eq(
|
2024-01-02 18:09:18 -07:00
|
|
|
(
|
2016-06-26 08:22:11 -07:00
|
|
|
'$XDG_DATA_HOME/nvim'
|
|
|
|
.. ',$XDG_DATA_DIRS/nvim'
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ',$XDG_CONFIG_HOME/'
|
|
|
|
.. data_dir
|
|
|
|
.. '/site'
|
2016-06-26 08:22:11 -07:00
|
|
|
.. ',$XDG_CONFIG_DIRS/nvim/site'
|
2020-02-02 15:29:33 -07:00
|
|
|
.. ','
|
|
|
|
.. vimruntime
|
|
|
|
.. ','
|
|
|
|
.. libdir
|
2016-06-26 08:22:11 -07:00
|
|
|
.. ',$XDG_CONFIG_DIRS/nvim/site/after'
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ',$XDG_CONFIG_HOME/'
|
|
|
|
.. data_dir
|
|
|
|
.. '/site/after'
|
2016-06-26 08:22:11 -07:00
|
|
|
.. ',$XDG_DATA_DIRS/nvim/after'
|
|
|
|
.. ',$XDG_DATA_HOME/nvim/after'
|
2022-12-19 09:37:45 -07:00
|
|
|
):gsub('\\', '/'),
|
2024-01-12 10:59:57 -07:00
|
|
|
(api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('backupdir', {}):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('directory', {}):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('undodir', {}):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('viewdir', {}):gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(nil, (fn.tempname()):match('XDG_RUNTIME_DIR'))
|
2016-06-26 08:16:54 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('with commas', function()
|
|
|
|
before_each(function()
|
2022-09-24 17:20:47 -07:00
|
|
|
clear({
|
|
|
|
args_rm = { 'runtimepath' },
|
|
|
|
env = {
|
|
|
|
XDG_CONFIG_HOME = ', , ,',
|
|
|
|
XDG_CONFIG_DIRS = ',-,-,' .. env_sep .. '-,-,-',
|
|
|
|
XDG_DATA_HOME = ',=,=,',
|
|
|
|
XDG_STATE_HOME = ',=,=,',
|
|
|
|
XDG_DATA_DIRS = ',≡,≡,' .. env_sep .. '≡,≡,≡',
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2016-06-26 08:16:54 -07:00
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('are escaped properly', function()
|
2020-02-02 15:29:33 -07:00
|
|
|
local vimruntime, libdir = vimruntime_and_libdir()
|
2022-11-21 17:13:30 -07:00
|
|
|
local path_sep = is_os('win') and '\\' or '/'
|
2020-09-07 22:40:12 -07:00
|
|
|
eq(
|
2024-01-02 18:09:18 -07:00
|
|
|
(
|
2020-09-07 22:40:12 -07:00
|
|
|
'\\, \\, \\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. ',\\,-\\,-\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. ',-\\,-\\,-'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. ',\\,=\\,=\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. data_dir
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
|
|
|
.. ',\\,≡\\,≡\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
|
|
|
.. ',≡\\,≡\\,≡'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
2020-02-02 15:29:33 -07:00
|
|
|
.. ','
|
|
|
|
.. vimruntime
|
|
|
|
.. ','
|
|
|
|
.. libdir
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ',≡\\,≡\\,≡'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
|
|
|
.. ',\\,≡\\,≡\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
|
|
|
.. ',\\,=\\,=\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. data_dir
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
|
|
|
.. ',-\\,-\\,-'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
|
|
|
.. ',\\,-\\,-\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
|
|
|
.. ',\\, \\, \\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
2021-09-06 10:35:34 -07:00
|
|
|
.. path_sep
|
2020-09-07 22:40:12 -07:00
|
|
|
.. 'after'
|
2022-12-19 09:37:45 -07:00
|
|
|
),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('runtimepath', {})
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 06:11:28 -07:00
|
|
|
command('set runtimepath&')
|
|
|
|
command('set backupdir&')
|
|
|
|
command('set directory&')
|
|
|
|
command('set undodir&')
|
|
|
|
command('set viewdir&')
|
2020-09-07 22:40:12 -07:00
|
|
|
eq(
|
2024-01-02 18:09:18 -07:00
|
|
|
(
|
2020-09-07 22:40:12 -07:00
|
|
|
'\\, \\, \\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. ',\\,-\\,-\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. ',-\\,-\\,-'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. ',\\,=\\,=\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. ''
|
|
|
|
.. data_dir
|
|
|
|
.. ''
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
|
|
|
.. ',\\,≡\\,≡\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
|
|
|
.. ',≡\\,≡\\,≡'
|
|
|
|
.. path_sep
|
2024-01-02 18:09:18 -07:00
|
|
|
.. 'nvim'
|
2020-09-07 22:40:12 -07:00
|
|
|
.. path_sep
|
2024-01-02 18:09:18 -07:00
|
|
|
.. 'site'
|
2020-02-02 15:29:33 -07:00
|
|
|
.. ','
|
|
|
|
.. vimruntime
|
|
|
|
.. ','
|
|
|
|
.. libdir
|
2020-09-07 22:40:12 -07:00
|
|
|
.. ',≡\\,≡\\,≡'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
|
|
|
.. ',\\,≡\\,≡\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
|
|
|
.. ',\\,=\\,=\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. ''
|
|
|
|
.. data_dir
|
|
|
|
.. ''
|
|
|
|
.. path_sep
|
|
|
|
.. 'site'
|
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
|
|
|
.. ',-\\,-\\,-'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
|
|
|
.. ',\\,-\\,-\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. 'nvim'
|
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
|
|
|
.. ',\\, \\, \\,'
|
|
|
|
.. path_sep
|
2024-01-02 18:09:18 -07:00
|
|
|
.. 'nvim'
|
2020-09-07 22:40:12 -07:00
|
|
|
.. path_sep
|
|
|
|
.. 'after'
|
2022-12-19 09:37:45 -07:00
|
|
|
),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('runtimepath', {})
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
'.,\\,=\\,=\\,' .. path_sep .. state_dir .. '' .. path_sep .. 'backup' .. (path_sep):rep(2),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('backupdir', {})
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
'\\,=\\,=\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. ''
|
|
|
|
.. state_dir
|
|
|
|
.. ''
|
|
|
|
.. path_sep
|
|
|
|
.. 'swap'
|
|
|
|
.. (path_sep):rep(2),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('directory', {})
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
'\\,=\\,=\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. ''
|
|
|
|
.. state_dir
|
|
|
|
.. ''
|
|
|
|
.. path_sep
|
|
|
|
.. 'undo'
|
|
|
|
.. (path_sep):rep(2),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('undodir', {})
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-09-06 10:35:34 -07:00
|
|
|
eq(
|
|
|
|
'\\,=\\,=\\,'
|
|
|
|
.. path_sep
|
|
|
|
.. ''
|
|
|
|
.. state_dir
|
|
|
|
.. ''
|
|
|
|
.. path_sep
|
|
|
|
.. 'view'
|
|
|
|
.. (path_sep):rep(2),
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_option_value('viewdir', {})
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2016-06-26 08:16:54 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
2017-03-13 22:00:12 -07:00
|
|
|
|
|
|
|
describe('stdpath()', function()
|
2023-09-24 12:19:01 -07:00
|
|
|
after_each(function()
|
2024-04-05 20:18:43 -07:00
|
|
|
check_close()
|
2023-09-24 12:19:01 -07:00
|
|
|
os.remove(testlog)
|
|
|
|
end)
|
|
|
|
|
2018-05-18 00:07:42 -07:00
|
|
|
-- Windows appends 'nvim-data' instead of just 'nvim' to prevent collisions
|
2021-09-06 10:35:34 -07:00
|
|
|
-- due to XDG_CONFIG_HOME, XDG_DATA_HOME and XDG_STATE_HOME being the same.
|
2023-02-16 05:15:02 -07:00
|
|
|
local function maybe_data(name)
|
|
|
|
return is_os('win') and name .. '-data' or name
|
|
|
|
end
|
|
|
|
|
|
|
|
local datadir = maybe_data('nvim')
|
|
|
|
local statedir = maybe_data('nvim')
|
2022-11-21 17:13:30 -07:00
|
|
|
local env_sep = is_os('win') and ';' or ':'
|
2018-05-18 00:07:42 -07:00
|
|
|
|
|
|
|
it('acceptance', function()
|
|
|
|
clear() -- Do not explicitly set any env vars.
|
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('nvim', fn.fnamemodify(fn.stdpath('cache'), ':t'))
|
|
|
|
eq('nvim', fn.fnamemodify(fn.stdpath('config'), ':t'))
|
|
|
|
eq(datadir, fn.fnamemodify(fn.stdpath('data'), ':t'))
|
|
|
|
eq(statedir, fn.fnamemodify(fn.stdpath('state'), ':t'))
|
|
|
|
eq('table', type(fn.stdpath('config_dirs')))
|
|
|
|
eq('table', type(fn.stdpath('data_dirs')))
|
|
|
|
eq('string', type(fn.stdpath('run')))
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive() -- Check for crash. #8393
|
2018-05-18 00:07:42 -07:00
|
|
|
end)
|
|
|
|
|
2023-08-03 19:37:47 -07:00
|
|
|
it('reacts to $NVIM_APPNAME', function()
|
2023-09-27 10:09:55 -07:00
|
|
|
local appname = 'NVIM_APPNAME_TEST' .. ('_'):rep(106)
|
2023-09-24 12:19:01 -07:00
|
|
|
clear({ env = { NVIM_APPNAME = appname, NVIM_LOG_FILE = testlog } })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(appname, fn.fnamemodify(fn.stdpath('config'), ':t'))
|
|
|
|
eq(appname, fn.fnamemodify(fn.stdpath('cache'), ':t'))
|
|
|
|
eq(maybe_data(appname), fn.fnamemodify(fn.stdpath('log'), ':t'))
|
|
|
|
eq(maybe_data(appname), fn.fnamemodify(fn.stdpath('data'), ':t'))
|
|
|
|
eq(maybe_data(appname), fn.fnamemodify(fn.stdpath('state'), ':t'))
|
2023-02-16 05:15:02 -07:00
|
|
|
-- config_dirs and data_dirs are empty on windows, so don't check them on
|
|
|
|
-- that platform
|
|
|
|
if not is_os('win') then
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(appname, fn.fnamemodify(fn.stdpath('config_dirs')[1], ':t'))
|
|
|
|
eq(appname, fn.fnamemodify(fn.stdpath('data_dirs')[1], ':t'))
|
2023-02-16 05:15:02 -07:00
|
|
|
end
|
|
|
|
assert_alive() -- Check for crash. #8393
|
2023-05-28 07:04:54 -07:00
|
|
|
|
2023-08-03 19:37:47 -07:00
|
|
|
-- Check that Nvim rejects invalid APPNAMEs
|
|
|
|
-- Call jobstart() and jobwait() in the same RPC request to reduce flakiness.
|
2023-09-27 10:09:55 -07:00
|
|
|
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)
|
2023-09-24 12:19:01 -07:00
|
|
|
if not is_os('win') then
|
|
|
|
assert_log('Failed to start server: no such file or directory:', testlog)
|
|
|
|
end
|
2023-02-16 05:15:02 -07:00
|
|
|
end)
|
|
|
|
|
2023-08-03 19:37:47 -07:00
|
|
|
describe('returns a String', function()
|
2017-03-13 22:00:12 -07:00
|
|
|
describe('with "config"', function()
|
|
|
|
it('knows XDG_CONFIG_HOME', function()
|
|
|
|
clear({
|
|
|
|
env = {
|
|
|
|
XDG_CONFIG_HOME = alter_slashes('/home/docwhat/.config'),
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2017-03-13 22:00:12 -07:00
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/docwhat/.config/nvim'), fn.stdpath('config'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('handles changes during runtime', function()
|
|
|
|
clear({ env = {
|
|
|
|
XDG_CONFIG_HOME = alter_slashes('/home/original'),
|
|
|
|
} })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/original/nvim'), fn.stdpath('config'))
|
2018-04-01 11:26:36 -07:00
|
|
|
command("let $XDG_CONFIG_HOME='" .. alter_slashes('/home/new') .. "'")
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/new/nvim'), fn.stdpath('config'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("doesn't expand $VARIABLES", function()
|
|
|
|
clear({
|
|
|
|
env = {
|
|
|
|
XDG_CONFIG_HOME = '$VARIABLES',
|
|
|
|
VARIABLES = 'this-should-not-happen',
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2017-03-13 22:00:12 -07:00
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('$VARIABLES/nvim'), fn.stdpath('config'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("doesn't expand ~/", function()
|
|
|
|
clear({ env = {
|
2018-04-01 11:26:36 -07:00
|
|
|
XDG_CONFIG_HOME = alter_slashes('~/frobnitz'),
|
2017-03-13 22:00:12 -07:00
|
|
|
} })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('~/frobnitz/nvim'), fn.stdpath('config'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('with "data"', function()
|
|
|
|
it('knows XDG_DATA_HOME', function()
|
|
|
|
clear({ env = {
|
|
|
|
XDG_DATA_HOME = alter_slashes('/home/docwhat/.local'),
|
|
|
|
} })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/docwhat/.local/' .. datadir), fn.stdpath('data'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('handles changes during runtime', function()
|
|
|
|
clear({ env = {
|
|
|
|
XDG_DATA_HOME = alter_slashes('/home/original'),
|
|
|
|
} })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/original/' .. datadir), fn.stdpath('data'))
|
2018-04-01 11:26:36 -07:00
|
|
|
command("let $XDG_DATA_HOME='" .. alter_slashes('/home/new') .. "'")
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/new/' .. datadir), fn.stdpath('data'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("doesn't expand $VARIABLES", function()
|
|
|
|
clear({
|
|
|
|
env = {
|
|
|
|
XDG_DATA_HOME = '$VARIABLES',
|
|
|
|
VARIABLES = 'this-should-not-happen',
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2017-03-13 22:00:12 -07:00
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('$VARIABLES/' .. datadir), fn.stdpath('data'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("doesn't expand ~/", function()
|
|
|
|
clear({ env = {
|
2018-04-01 11:26:36 -07:00
|
|
|
XDG_DATA_HOME = alter_slashes('~/frobnitz'),
|
2017-03-13 22:00:12 -07:00
|
|
|
} })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('~/frobnitz/' .. datadir), fn.stdpath('data'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2021-09-06 10:35:34 -07:00
|
|
|
describe('with "state"', function()
|
|
|
|
it('knows XDG_STATE_HOME', function()
|
|
|
|
clear({
|
|
|
|
env = {
|
|
|
|
XDG_STATE_HOME = alter_slashes('/home/docwhat/.local'),
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2021-09-06 10:35:34 -07:00
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/docwhat/.local/' .. statedir), fn.stdpath('state'))
|
2021-09-06 10:35:34 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('handles changes during runtime', function()
|
|
|
|
clear({ env = {
|
|
|
|
XDG_STATE_HOME = alter_slashes('/home/original'),
|
|
|
|
} })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/original/' .. statedir), fn.stdpath('state'))
|
2021-09-06 10:35:34 -07:00
|
|
|
command("let $XDG_STATE_HOME='" .. alter_slashes('/home/new') .. "'")
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/new/' .. statedir), fn.stdpath('state'))
|
2021-09-06 10:35:34 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("doesn't expand $VARIABLES", function()
|
|
|
|
clear({
|
|
|
|
env = {
|
|
|
|
XDG_STATE_HOME = '$VARIABLES',
|
|
|
|
VARIABLES = 'this-should-not-happen',
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2021-09-06 10:35:34 -07:00
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('$VARIABLES/' .. statedir), fn.stdpath('state'))
|
2021-09-06 10:35:34 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("doesn't expand ~/", function()
|
|
|
|
clear({ env = {
|
|
|
|
XDG_STATE_HOME = alter_slashes('~/frobnitz'),
|
|
|
|
} })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('~/frobnitz/' .. statedir), fn.stdpath('state'))
|
2021-09-06 10:35:34 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2017-03-13 22:00:12 -07:00
|
|
|
describe('with "cache"', function()
|
|
|
|
it('knows XDG_CACHE_HOME', function()
|
|
|
|
clear({
|
|
|
|
env = {
|
|
|
|
XDG_CACHE_HOME = alter_slashes('/home/docwhat/.cache'),
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2017-03-13 22:00:12 -07:00
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/docwhat/.cache/nvim'), fn.stdpath('cache'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('handles changes during runtime', function()
|
|
|
|
clear({ env = {
|
|
|
|
XDG_CACHE_HOME = alter_slashes('/home/original'),
|
|
|
|
} })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/original/nvim'), fn.stdpath('cache'))
|
2018-04-01 11:26:36 -07:00
|
|
|
command("let $XDG_CACHE_HOME='" .. alter_slashes('/home/new') .. "'")
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('/home/new/nvim'), fn.stdpath('cache'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("doesn't expand $VARIABLES", function()
|
|
|
|
clear({
|
|
|
|
env = {
|
|
|
|
XDG_CACHE_HOME = '$VARIABLES',
|
|
|
|
VARIABLES = 'this-should-not-happen',
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2017-03-13 22:00:12 -07:00
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('$VARIABLES/nvim'), fn.stdpath('cache'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("doesn't expand ~/", function()
|
|
|
|
clear({ env = {
|
2018-04-01 11:26:36 -07:00
|
|
|
XDG_CACHE_HOME = alter_slashes('~/frobnitz'),
|
2017-03-13 22:00:12 -07:00
|
|
|
} })
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(alter_slashes('~/frobnitz/nvim'), fn.stdpath('cache'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2023-08-03 19:37:47 -07:00
|
|
|
describe('returns a List', function()
|
2017-03-13 22:00:12 -07:00
|
|
|
-- Some OS specific variables the system would have set.
|
|
|
|
local function base_env()
|
2022-11-21 17:13:30 -07:00
|
|
|
if is_os('win') then
|
2017-03-13 22:00:12 -07:00
|
|
|
return {
|
|
|
|
HOME = 'C:\\Users\\docwhat', -- technically, is not a usual PATH
|
|
|
|
HOMEDRIVE = 'C:',
|
|
|
|
HOMEPATH = '\\Users\\docwhat',
|
|
|
|
LOCALAPPDATA = 'C:\\Users\\docwhat\\AppData\\Local',
|
|
|
|
TEMP = 'C:\\Users\\docwhat\\AppData\\Local\\Temp',
|
|
|
|
TMPDIR = 'C:\\Users\\docwhat\\AppData\\Local\\Temp',
|
|
|
|
TMP = 'C:\\Users\\docwhat\\AppData\\Local\\Temp',
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return {
|
|
|
|
HOME = '/home/docwhat',
|
|
|
|
HOMEDRIVE = 'HOMEDRIVE-should-be-ignored',
|
|
|
|
HOMEPATH = 'HOMEPATH-should-be-ignored',
|
|
|
|
LOCALAPPDATA = 'LOCALAPPDATA-should-be-ignored',
|
|
|
|
TEMP = 'TEMP-should-be-ignored',
|
|
|
|
TMPDIR = 'TMPDIR-should-be-ignored',
|
|
|
|
TMP = 'TMP-should-be-ignored',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function set_paths_via_system(var_name, paths)
|
|
|
|
local env = base_env()
|
2020-09-07 22:40:12 -07:00
|
|
|
env[var_name] = table.concat(paths, env_sep)
|
2017-03-13 22:00:12 -07:00
|
|
|
clear({ env = env })
|
|
|
|
end
|
|
|
|
|
|
|
|
local function set_paths_at_runtime(var_name, paths)
|
|
|
|
clear({ env = base_env() })
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('env_val', table.concat(paths, env_sep))
|
2017-03-13 22:00:12 -07:00
|
|
|
command(('let $%s=g:env_val'):format(var_name))
|
|
|
|
end
|
|
|
|
|
|
|
|
local function behaves_like_dir_list_env(msg, stdpath_arg, env_var_name, paths, expected_paths)
|
|
|
|
describe(msg, function()
|
|
|
|
it('set via system', function()
|
|
|
|
set_paths_via_system(env_var_name, paths)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(expected_paths, fn.stdpath(stdpath_arg))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('set at runtime', function()
|
|
|
|
set_paths_at_runtime(env_var_name, paths)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(expected_paths, fn.stdpath(stdpath_arg))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe('with "config_dirs"', function()
|
|
|
|
behaves_like_dir_list_env(
|
|
|
|
'handles XDG_CONFIG_DIRS with one path',
|
|
|
|
'config_dirs',
|
|
|
|
'XDG_CONFIG_DIRS',
|
|
|
|
{
|
|
|
|
alter_slashes('/home/docwhat/.config'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
alter_slashes('/home/docwhat/.config/nvim'),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
behaves_like_dir_list_env(
|
|
|
|
'handles XDG_CONFIG_DIRS with two paths',
|
|
|
|
'config_dirs',
|
|
|
|
'XDG_CONFIG_DIRS',
|
|
|
|
{
|
|
|
|
alter_slashes('/home/docwhat/.config'),
|
|
|
|
alter_slashes('/etc/config'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
alter_slashes('/home/docwhat/.config/nvim'),
|
|
|
|
alter_slashes('/etc/config/nvim'),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
behaves_like_dir_list_env(
|
|
|
|
"doesn't expand $VAR and $IBLES",
|
|
|
|
'config_dirs',
|
|
|
|
'XDG_CONFIG_DIRS',
|
|
|
|
{ '$HOME', '$TMP' },
|
2018-04-01 11:26:36 -07:00
|
|
|
{
|
|
|
|
alter_slashes('$HOME/nvim'),
|
|
|
|
alter_slashes('$TMP/nvim'),
|
|
|
|
}
|
|
|
|
)
|
2017-03-13 22:00:12 -07:00
|
|
|
|
|
|
|
behaves_like_dir_list_env("doesn't expand ~/", 'config_dirs', 'XDG_CONFIG_DIRS', {
|
|
|
|
alter_slashes('~/.oldconfig'),
|
|
|
|
alter_slashes('~/.olderconfig'),
|
|
|
|
}, {
|
|
|
|
alter_slashes('~/.oldconfig/nvim'),
|
|
|
|
alter_slashes('~/.olderconfig/nvim'),
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('with "data_dirs"', function()
|
|
|
|
behaves_like_dir_list_env('knows XDG_DATA_DIRS with one path', 'data_dirs', 'XDG_DATA_DIRS', {
|
|
|
|
alter_slashes('/home/docwhat/.data'),
|
|
|
|
}, {
|
|
|
|
alter_slashes('/home/docwhat/.data/nvim'),
|
|
|
|
})
|
|
|
|
|
|
|
|
behaves_like_dir_list_env(
|
|
|
|
'knows XDG_DATA_DIRS with two paths',
|
|
|
|
'data_dirs',
|
|
|
|
'XDG_DATA_DIRS',
|
|
|
|
{
|
|
|
|
alter_slashes('/home/docwhat/.data'),
|
|
|
|
alter_slashes('/etc/local'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
alter_slashes('/home/docwhat/.data/nvim'),
|
|
|
|
alter_slashes('/etc/local/nvim'),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
behaves_like_dir_list_env(
|
|
|
|
"doesn't expand $VAR and $IBLES",
|
|
|
|
'data_dirs',
|
|
|
|
'XDG_DATA_DIRS',
|
|
|
|
{ '$HOME', '$TMP' },
|
2018-04-01 11:26:36 -07:00
|
|
|
{
|
|
|
|
alter_slashes('$HOME/nvim'),
|
|
|
|
alter_slashes('$TMP/nvim'),
|
|
|
|
}
|
|
|
|
)
|
2017-03-13 22:00:12 -07:00
|
|
|
|
|
|
|
behaves_like_dir_list_env("doesn't expand ~/", 'data_dirs', 'XDG_DATA_DIRS', {
|
|
|
|
alter_slashes('~/.oldconfig'),
|
|
|
|
alter_slashes('~/.olderconfig'),
|
|
|
|
}, {
|
|
|
|
alter_slashes('~/.oldconfig/nvim'),
|
|
|
|
alter_slashes('~/.olderconfig/nvim'),
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('errors', function()
|
2024-04-05 20:18:43 -07:00
|
|
|
before_each(clear)
|
|
|
|
|
2017-03-13 22:00:12 -07:00
|
|
|
it('on unknown strings', function()
|
|
|
|
eq('Vim(call):E6100: "capybara" is not a valid stdpath', exc_exec('call stdpath("capybara")'))
|
|
|
|
eq('Vim(call):E6100: "" is not a valid stdpath', exc_exec('call stdpath("")'))
|
|
|
|
eq('Vim(call):E6100: "23" is not a valid stdpath', exc_exec('call stdpath(23)'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('on non-strings', function()
|
2023-05-04 16:02:43 -07:00
|
|
|
eq('Vim(call):E731: Using a Dictionary as a String', exc_exec('call stdpath({"eris": 23})'))
|
|
|
|
eq('Vim(call):E730: Using a List as a String', exc_exec('call stdpath([23])'))
|
2017-03-13 22:00:12 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
2024-02-22 12:54:21 -07:00
|
|
|
|
|
|
|
describe('autocommands', function()
|
|
|
|
it('closes terminal with default shell on success', function()
|
2024-04-05 20:18:43 -07:00
|
|
|
clear()
|
2024-04-20 08:44:13 -07:00
|
|
|
api.nvim_set_option_value('shell', n.testprg('shell-test'), {})
|
2024-02-22 12:54:21 -07:00
|
|
|
command('set shellcmdflag=EXIT shellredir= shellpipe= shellquote= shellxquote=')
|
|
|
|
|
|
|
|
-- Should not block other events
|
|
|
|
command('let g:n=0')
|
|
|
|
command('au BufEnter * let g:n = g:n + 1')
|
|
|
|
|
|
|
|
command('terminal')
|
2024-03-11 07:23:14 -07:00
|
|
|
eq(1, eval('get(g:, "n", 0)'))
|
2024-02-22 12:54:21 -07:00
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
t.retry(nil, 1000, function()
|
2024-03-11 07:23:14 -07:00
|
|
|
neq('terminal', api.nvim_get_option_value('buftype', { buf = 0 }))
|
|
|
|
eq(2, eval('get(g:, "n", 0)'))
|
2024-02-22 12:54:21 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|