aboutsummaryrefslogtreecommitdiff
path: root/test/functional/options/defaults_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/options/defaults_spec.lua')
-rw-r--r--test/functional/options/defaults_spec.lua467
1 files changed, 430 insertions, 37 deletions
diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua
index f57fe5fa23..f452cafd22 100644
--- a/test/functional/options/defaults_spec.lua
+++ b/test/functional/options/defaults_spec.lua
@@ -3,86 +3,156 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local meths = helpers.meths
-local execute = helpers.execute
+local command = helpers.command
local clear = helpers.clear
+local exc_exec = helpers.exc_exec
local eval = helpers.eval
local eq = helpers.eq
+local funcs = helpers.funcs
+local insert = helpers.insert
local neq = helpers.neq
-
-local function init_session(...)
- local args = { helpers.nvim_prog, '-i', 'NONE', '--embed',
- '--cmd', helpers.nvim_set }
- for _, v in ipairs({...}) do
- table.insert(args, v)
- end
- helpers.set_session(helpers.spawn(args))
-end
+local mkdir = helpers.mkdir
+local rmdir = helpers.rmdir
+local alter_slashes = helpers.alter_slashes
describe('startup defaults', function()
describe(':filetype', function()
- if helpers.pending_win32(pending) then return end
-
local function expect_filetype(expected)
- local screen = Screen.new(48, 4)
+ local screen = Screen.new(50, 4)
screen:attach()
- execute('filetype')
+ command('filetype')
screen:expect([[
- ^ |
- ~ |
- ~ |
+ ^ |
+ ~ |
+ ~ |
]]..expected
)
end
- it('enabled by `-u NORC`', function()
- init_session('-u', 'NORC')
+ it('all ON after `-u NORC`', function()
+ clear('-u', 'NORC')
expect_filetype(
- 'filetype detection:ON plugin:ON indent:ON |')
+ 'filetype detection:ON plugin:ON indent:ON |')
end)
- it('disabled by `-u NONE`', function()
- init_session('-u', 'NONE')
+ 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:OFF plugin:OFF indent:OFF |')
+ 'filetype detection:ON plugin:ON indent:ON |')
end)
- it('overridden by early `filetype on`', function()
- init_session('-u', 'NORC', '--cmd', 'filetype on')
+ it('all OFF after `-u NONE`', function()
+ clear('-u', 'NONE')
expect_filetype(
- 'filetype detection:ON plugin:OFF indent:OFF |')
+ 'filetype detection:OFF plugin:OFF indent:OFF |')
end)
- it('overridden by early `filetype plugin on`', function()
- init_session('-u', 'NORC', '--cmd', 'filetype plugin on')
+ 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:ON indent:OFF |')
+ 'filetype detection:ON plugin:OFF indent:OFF |')
+ clear('-u', 'NORC', '--cmd', 'filetype indent off')
+ expect_filetype(
+ 'filetype detection:ON plugin:ON indent:OFF |')
+ 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) |')
end)
- it('overridden by early `filetype indent on`', function()
- init_session('-u', 'NORC', '--cmd', 'filetype indent on')
+ 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:OFF indent:ON |')
+ 'filetype detection:ON plugin:ON indent:ON |')
+ end)
+
+ it('late `:filetype … off` stays OFF', function()
+ clear('-u', 'NORC', '-c', 'filetype off')
+ expect_filetype(
+ 'filetype detection:OFF plugin:(on) indent:(on) |')
+ clear('-u', 'NORC', '-c', 'filetype plugin off')
+ expect_filetype(
+ 'filetype detection:ON plugin:OFF indent:ON |')
+ clear('-u', 'NORC', '-c', 'filetype indent off')
+ expect_filetype(
+ 'filetype detection:ON plugin:ON indent:OFF |')
end)
end)
describe('syntax', function()
it('enabled by `-u NORC`', function()
- init_session('-u', 'NORC')
+ clear('-u', 'NORC')
eq(1, eval('g:syntax_on'))
end)
it('disabled by `-u NONE`', function()
- init_session('-u', 'NONE')
+ clear('-u', 'NONE')
eq(0, eval('exists("g:syntax_on")'))
end)
- it('overridden by early `syntax off`', function()
- init_session('-u', 'NORC', '--cmd', 'syntax off')
+ it('`:syntax off` stays off', function()
+ -- early
+ clear('-u', 'NORC', '--cmd', 'syntax off')
+ eq(0, eval('exists("g:syntax_on")'))
+ -- late
+ clear('-u', 'NORC', '-c', 'syntax off')
eq(0, eval('exists("g:syntax_on")'))
end)
end)
- describe('packpath', function()
+ 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 |
+ ^+-- 2 lines: 2··········│+-- 2 lines: 2·········|
+ 4 │4 |
+ ~ │~ |
+ |
+ ]])
+
+ -- ambiwidth=double defaults to single-byte fillchars.
+ command('set ambiwidth=double')
+ screen:expect([[
+ 1 |1 |
+ ^+-- 2 lines: 2----------|+-- 2 lines: 2---------|
+ 4 |4 |
+ ~ |~ |
+ |
+ ]])
+ end)
+ end)
+
+ describe("'packpath'", function()
it('defaults to &runtimepath', function()
eq(meths.get_option('runtimepath'), meths.get_option('packpath'))
end)
@@ -98,6 +168,56 @@ describe('startup defaults', function()
it('v:progpath is set to the absolute path', function()
eq(eval("fnamemodify(v:progpath, ':p')"), eval('v:progpath'))
end)
+
+ describe('$NVIM_LOG_FILE', function()
+ -- TODO(jkeyes): use stdpath('data') instead.
+ local datasubdir = helpers.iswin() and 'nvim-data' or 'nvim'
+ local xdgdir = 'Xtest-startup-xdg-logpath'
+ local xdgdatadir = xdgdir..'/'..datasubdir
+ after_each(function()
+ os.remove('Xtest-logpath')
+ rmdir(xdgdir)
+ end)
+
+ it('is used if expansion succeeds', function()
+ clear({env={
+ NVIM_LOG_FILE='Xtest-logpath',
+ }})
+ eq('Xtest-logpath', eval('$NVIM_LOG_FILE'))
+ end)
+ it('defaults to stdpath("data")/log if empty', function()
+ eq(true, mkdir(xdgdir) and mkdir(xdgdatadir))
+ clear({env={
+ XDG_DATA_HOME=xdgdir,
+ NVIM_LOG_FILE='', -- Empty is invalid.
+ }})
+ -- server_start() calls ELOG, which tickles log_path_init().
+ pcall(command, 'call serverstart(serverlist()[0])')
+
+ eq(xdgdir..'/'..datasubdir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
+ end)
+ it('defaults to stdpath("data")/log if invalid', function()
+ eq(true, mkdir(xdgdir) and mkdir(xdgdatadir))
+ clear({env={
+ XDG_DATA_HOME=xdgdir,
+ NVIM_LOG_FILE='.', -- Any directory is invalid.
+ }})
+ -- server_start() calls ELOG, which tickles log_path_init().
+ pcall(command, 'call serverstart(serverlist()[0])')
+
+ eq(xdgdir..'/'..datasubdir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
+ end)
+ it('defaults to .nvimlog if stdpath("data") is invalid', function()
+ clear({env={
+ XDG_DATA_HOME='Xtest-missing-xdg-dir',
+ NVIM_LOG_FILE='.', -- Any directory is invalid.
+ }})
+ -- server_start() calls ELOG, which tickles log_path_init().
+ pcall(command, 'call serverstart(serverlist()[0])')
+
+ eq('.nvimlog', eval('$NVIM_LOG_FILE'))
+ end)
+ end)
end)
describe('XDG-based defaults', function()
@@ -305,3 +425,276 @@ describe('XDG-based defaults', function()
end)
end)
end)
+
+
+describe('stdpath()', function()
+ context('returns a String', function()
+ describe('with "config"' , function ()
+ it('knows XDG_CONFIG_HOME', function()
+ clear({env={
+ XDG_CONFIG_HOME=alter_slashes('/home/docwhat/.config'),
+ }})
+ eq(alter_slashes('/home/docwhat/.config/nvim'), funcs.stdpath('config'))
+ end)
+
+ it('handles changes during runtime', function()
+ clear({env={
+ XDG_CONFIG_HOME=alter_slashes('/home/original'),
+ }})
+ eq(alter_slashes('/home/original/nvim'), funcs.stdpath('config'))
+ command("let $XDG_CONFIG_HOME='"..alter_slashes('/home/new').."'")
+ eq(alter_slashes('/home/new/nvim'), funcs.stdpath('config'))
+ end)
+
+ it("doesn't expand $VARIABLES", function()
+ clear({env={
+ XDG_CONFIG_HOME='$VARIABLES',
+ VARIABLES='this-should-not-happen',
+ }})
+ eq(alter_slashes('$VARIABLES/nvim'), funcs.stdpath('config'))
+ end)
+
+ it("doesn't expand ~/", function()
+ clear({env={
+ XDG_CONFIG_HOME=alter_slashes('~/frobnitz'),
+ }})
+ eq(alter_slashes('~/frobnitz/nvim'), funcs.stdpath('config'))
+ end)
+ end)
+
+ describe('with "data"' , function ()
+ local appended_dir
+ setup(function()
+ -- Windows appends 'nvim-data' instead of just 'nvim' to
+ -- prevent collisions due to XDG_CONFIG_HOME and XDG_DATA_HOME
+ -- being the same.
+ if helpers.iswin() then
+ appended_dir = '/nvim-data'
+ else
+ appended_dir = '/nvim'
+ end
+ end)
+
+ it('knows XDG_DATA_HOME', function()
+ clear({env={
+ XDG_DATA_HOME=alter_slashes('/home/docwhat/.local'),
+ }})
+ eq(alter_slashes('/home/docwhat/.local' .. appended_dir), funcs.stdpath('data'))
+ end)
+
+ it('handles changes during runtime', function()
+ clear({env={
+ XDG_DATA_HOME=alter_slashes('/home/original'),
+ }})
+ eq(alter_slashes('/home/original' .. appended_dir), funcs.stdpath('data'))
+ command("let $XDG_DATA_HOME='"..alter_slashes('/home/new').."'")
+ eq(alter_slashes('/home/new' .. appended_dir), funcs.stdpath('data'))
+ end)
+
+ it("doesn't expand $VARIABLES", function()
+ clear({env={
+ XDG_DATA_HOME='$VARIABLES',
+ VARIABLES='this-should-not-happen',
+ }})
+ eq(alter_slashes('$VARIABLES' .. appended_dir), funcs.stdpath('data'))
+ end)
+
+ it("doesn't expand ~/", function()
+ clear({env={
+ XDG_DATA_HOME=alter_slashes('~/frobnitz'),
+ }})
+ eq(alter_slashes('~/frobnitz' .. appended_dir), funcs.stdpath('data'))
+ end)
+ end)
+
+ describe('with "cache"' , function ()
+ it('knows XDG_CACHE_HOME', function()
+ clear({env={
+ XDG_CACHE_HOME=alter_slashes('/home/docwhat/.cache'),
+ }})
+ eq(alter_slashes('/home/docwhat/.cache/nvim'), funcs.stdpath('cache'))
+ end)
+
+ it('handles changes during runtime', function()
+ clear({env={
+ XDG_CACHE_HOME=alter_slashes('/home/original'),
+ }})
+ eq(alter_slashes('/home/original/nvim'), funcs.stdpath('cache'))
+ command("let $XDG_CACHE_HOME='"..alter_slashes('/home/new').."'")
+ eq(alter_slashes('/home/new/nvim'), funcs.stdpath('cache'))
+ end)
+
+ it("doesn't expand $VARIABLES", function()
+ clear({env={
+ XDG_CACHE_HOME='$VARIABLES',
+ VARIABLES='this-should-not-happen',
+ }})
+ eq(alter_slashes('$VARIABLES/nvim'), funcs.stdpath('cache'))
+ end)
+
+ it("doesn't expand ~/", function()
+ clear({env={
+ XDG_CACHE_HOME=alter_slashes('~/frobnitz'),
+ }})
+ eq(alter_slashes('~/frobnitz/nvim'), funcs.stdpath('cache'))
+ end)
+ end)
+ end)
+
+ context('returns a List', function()
+ -- Some OS specific variables the system would have set.
+ local function base_env()
+ if helpers.iswin() then
+ 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()
+ env[var_name] = table.concat(paths, ':')
+ clear({env=env})
+ end
+
+ local function set_paths_at_runtime(var_name, paths)
+ clear({env=base_env()})
+ meths.set_var('env_val', table.concat(paths, ':'))
+ 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)
+ eq(expected_paths, funcs.stdpath(stdpath_arg))
+ end)
+
+ it('set at runtime', function()
+ set_paths_at_runtime(env_var_name, paths)
+ eq(expected_paths, funcs.stdpath(stdpath_arg))
+ 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' },
+ {
+ alter_slashes('$HOME/nvim'),
+ alter_slashes('$TMP/nvim')
+ })
+
+
+ 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' },
+ {
+ alter_slashes('$HOME/nvim'),
+ alter_slashes('$TMP/nvim')
+ })
+
+ 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()
+ 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()
+ eq('Vim(call):E731: using Dictionary as a String', exc_exec('call stdpath({"eris": 23})'))
+ eq('Vim(call):E730: using List as a String', exc_exec('call stdpath([23])'))
+ end)
+ end)
+end)