mirror of
https://github.com/neovim/neovim.git
synced 2025-11-22 18:16:32 +00:00
@@ -16,20 +16,29 @@ static const char *xdg_env_vars[] = {
|
|||||||
[kXDGDataDirs] = "XDG_DATA_DIRS",
|
[kXDGDataDirs] = "XDG_DATA_DIRS",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
static const char *const xdg_defaults_env_vars[] = {
|
||||||
|
[kXDGConfigHome] = "LOCALAPPDATA",
|
||||||
|
[kXDGDataHome] = "LOCALAPPDATA",
|
||||||
|
[kXDGCacheHome] = "TEMP",
|
||||||
|
[kXDGRuntimeDir] = NULL,
|
||||||
|
[kXDGConfigDirs] = NULL,
|
||||||
|
[kXDGDataDirs] = NULL,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Defaults for XDGVarType values
|
/// Defaults for XDGVarType values
|
||||||
///
|
///
|
||||||
/// Used in case environment variables contain nothing. Need to be expanded.
|
/// Used in case environment variables contain nothing. Need to be expanded.
|
||||||
static const char *const xdg_defaults[] = {
|
static const char *const xdg_defaults[] = {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// Windows
|
[kXDGConfigHome] = "~\\AppData\\Local",
|
||||||
[kXDGConfigHome] = "$LOCALAPPDATA",
|
[kXDGDataHome] = "~\\AppData\\Local",
|
||||||
[kXDGDataHome] = "$LOCALAPPDATA",
|
[kXDGCacheHome] = "~\\AppData\\Local\\Temp",
|
||||||
[kXDGCacheHome] = "$TEMP",
|
|
||||||
[kXDGRuntimeDir] = NULL,
|
[kXDGRuntimeDir] = NULL,
|
||||||
[kXDGConfigDirs] = NULL,
|
[kXDGConfigDirs] = NULL,
|
||||||
[kXDGDataDirs] = NULL,
|
[kXDGDataDirs] = NULL,
|
||||||
#else
|
#else
|
||||||
// Linux, BSD, CYGWIN, Apple
|
|
||||||
[kXDGConfigHome] = "~/.config",
|
[kXDGConfigHome] = "~/.config",
|
||||||
[kXDGDataHome] = "~/.local/share",
|
[kXDGDataHome] = "~/.local/share",
|
||||||
[kXDGCacheHome] = "~/.cache",
|
[kXDGCacheHome] = "~/.cache",
|
||||||
@@ -50,7 +59,14 @@ char *stdpaths_get_xdg_var(const XDGVarType idx)
|
|||||||
const char *const env = xdg_env_vars[idx];
|
const char *const env = xdg_env_vars[idx];
|
||||||
const char *const fallback = xdg_defaults[idx];
|
const char *const fallback = xdg_defaults[idx];
|
||||||
|
|
||||||
const char *const env_val = os_getenv(env);
|
const char *env_val = os_getenv(env);
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
if (env_val == NULL) {
|
||||||
|
env_val = os_getenv(xdg_defaults_env_vars[idx]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
if (env_val != NULL) {
|
if (env_val != NULL) {
|
||||||
ret = xstrdup(env_val);
|
ret = xstrdup(env_val);
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ local eval = helpers.eval
|
|||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
local neq = helpers.neq
|
local neq = helpers.neq
|
||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
|
||||||
|
|
||||||
local function init_session(...)
|
local function init_session(...)
|
||||||
local args = { helpers.nvim_prog, '-i', 'NONE', '--embed',
|
local args = { helpers.nvim_prog, '-i', 'NONE', '--embed',
|
||||||
'--cmd', 'set shortmess+=I background=light noswapfile noautoindent',
|
'--cmd', 'set shortmess+=I background=light noswapfile noautoindent',
|
||||||
@@ -24,6 +22,8 @@ end
|
|||||||
|
|
||||||
describe('startup defaults', function()
|
describe('startup defaults', function()
|
||||||
describe(':filetype', function()
|
describe(':filetype', function()
|
||||||
|
if helpers.pending_win32(pending) then return end
|
||||||
|
|
||||||
local function expect_filetype(expected)
|
local function expect_filetype(expected)
|
||||||
local screen = Screen.new(48, 4)
|
local screen = Screen.new(48, 4)
|
||||||
screen:attach()
|
screen:attach()
|
||||||
@@ -99,8 +99,37 @@ describe('startup defaults', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe('XDG-based defaults', function()
|
describe('XDG-based defaults', function()
|
||||||
-- Need to be in separate describe() block to not run clear() twice.
|
-- Need separate describe() blocks to not run clear() twice.
|
||||||
-- Do not put before_each() here for the same reasons.
|
-- Do not put before_each() here for the same reasons.
|
||||||
|
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
}})
|
||||||
|
|
||||||
|
eq('.', meths.get_option('backupdir'))
|
||||||
|
eq('.', meths.get_option('viewdir'))
|
||||||
|
eq('.', meths.get_option('directory'))
|
||||||
|
eq('.', meths.get_option('undodir'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- TODO(jkeyes): tests below fail on win32 because of path separator.
|
||||||
|
if helpers.pending_win32(pending) then return end
|
||||||
|
|
||||||
describe('with too long XDG variables', function()
|
describe('with too long XDG variables', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
clear({env={
|
clear({env={
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ local reset, set_additional_cmd, clear =
|
|||||||
shada_helpers.reset, shada_helpers.set_additional_cmd,
|
shada_helpers.reset, shada_helpers.set_additional_cmd,
|
||||||
shada_helpers.clear
|
shada_helpers.clear
|
||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
|
||||||
|
|
||||||
describe('ShaDa support code', function()
|
describe('ShaDa support code', function()
|
||||||
local testfilename = 'Xtestfile-functional-shada-buffers'
|
local testfilename = 'Xtestfile-functional-shada-buffers'
|
||||||
local testfilename_2 = 'Xtestfile-functional-shada-buffers-2'
|
local testfilename_2 = 'Xtestfile-functional-shada-buffers-2'
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ local nvim_current_line = function()
|
|||||||
return curwinmeths.get_cursor()[1]
|
return curwinmeths.get_cursor()[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
|
||||||
|
|
||||||
describe('ShaDa support code', function()
|
describe('ShaDa support code', function()
|
||||||
local testfilename = 'Xtestfile-functional-shada-marks'
|
local testfilename = 'Xtestfile-functional-shada-marks'
|
||||||
local testfilename_2 = 'Xtestfile-functional-shada-marks-2'
|
local testfilename_2 = 'Xtestfile-functional-shada-marks-2'
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ local wshada, _, shada_fname, clean =
|
|||||||
local dirname = 'Xtest-functional-shada-shada.d'
|
local dirname = 'Xtest-functional-shada-shada.d'
|
||||||
local dirshada = dirname .. '/main.shada'
|
local dirshada = dirname .. '/main.shada'
|
||||||
|
|
||||||
if helpers.pending_win32(pending) then return end
|
|
||||||
|
|
||||||
describe('ShaDa support code', function()
|
describe('ShaDa support code', function()
|
||||||
before_each(reset)
|
before_each(reset)
|
||||||
after_each(function()
|
after_each(function()
|
||||||
@@ -173,6 +171,7 @@ describe('ShaDa support code', function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
it('correctly uses shada-r option', function()
|
it('correctly uses shada-r option', function()
|
||||||
|
nvim_command('set shellslash')
|
||||||
meths.set_var('__home', paths.test_source_path)
|
meths.set_var('__home', paths.test_source_path)
|
||||||
nvim_command('let $HOME = __home')
|
nvim_command('let $HOME = __home')
|
||||||
nvim_command('unlet __home')
|
nvim_command('unlet __home')
|
||||||
@@ -196,6 +195,7 @@ describe('ShaDa support code', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('correctly ignores case with shada-r option', function()
|
it('correctly ignores case with shada-r option', function()
|
||||||
|
nvim_command('set shellslash')
|
||||||
local pwd = funcs.getcwd()
|
local pwd = funcs.getcwd()
|
||||||
local relfname = 'абв/test'
|
local relfname = 'абв/test'
|
||||||
local fname = pwd .. '/' .. relfname
|
local fname = pwd .. '/' .. relfname
|
||||||
@@ -240,6 +240,8 @@ describe('ShaDa support code', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('does not crash when ShaDa file directory is not writable', function()
|
it('does not crash when ShaDa file directory is not writable', function()
|
||||||
|
if helpers.pending_win32(pending) then return end
|
||||||
|
|
||||||
funcs.mkdir(dirname, '', 0)
|
funcs.mkdir(dirname, '', 0)
|
||||||
eq(0, funcs.filewritable(dirname))
|
eq(0, funcs.filewritable(dirname))
|
||||||
set_additional_cmd('set shada=')
|
set_additional_cmd('set shada=')
|
||||||
|
|||||||
Reference in New Issue
Block a user