From 698ec9eb6e97ce9038e5f95a3208b7a0ac8da805 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 30 May 2017 01:25:25 +0200 Subject: loop_close: Avoid infinite loop, and log it. Avoids a hang, and also helps diagnose issues like: https://github.com/neovim/neovim/pull/6594#issuecomment-298321826 --- test/README.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/README.md b/test/README.md index 2857cc0ecf..01db5960cd 100644 --- a/test/README.md +++ b/test/README.md @@ -2,6 +2,8 @@ Tests are run by `/cmake/RunTests.cmake` file, using busted. +For some failures, `.nvimlog` (or `$NVIM_LOG_FILE`) may provide insight. + ## Directory structure Directories with tests: `/test/benchmark` for benchmarks, `/test/functional` for -- cgit From bb96b8219dc6a776bf0e765cfbc16a833e98b351 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 31 May 2017 02:04:03 +0200 Subject: log: set $NVIM_LOG_FILE; fallback to $XDG_DATA_HOME/nvim/log --- test/functional/options/defaults_spec.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index dc73679bb4..34921df6d4 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -121,6 +121,36 @@ 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() + after_each(function() + os.remove('Xtest-logpath') + 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', function() + clear({env={ + XDG_DATA_HOME='Xtest-startup-logpath', + NVIM_LOG_FILE='', -- Empty value is considered invalid. + }}) + -- TODO(jkeyes): use stdpath('data') instead. + local dir = helpers.iswin() and 'nvim-data' or 'nvim' + eq('Xtest-startup-logpath/'..dir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/')) + end) + it('if invalid, falls back to default', function() + clear({env={ + XDG_DATA_HOME='Xtest-startup-logpath', + NVIM_LOG_FILE='.', -- Directory is considered invalid. + }}) + -- TODO(jkeyes): use stdpath('data') instead. + local dir = helpers.iswin() and 'nvim-data' or 'nvim' + eq('Xtest-startup-logpath/'..dir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/')) + end) + end) end) describe('XDG-based defaults', function() -- cgit From d07661b9a38225e1a29465bbbe54c99ca4038392 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 31 May 2017 18:12:26 +0200 Subject: log: Fall back to CWD-relative .nvimlog If if the resolved $NVIM_LOG_FILE *and* stdpath("data")/log cannot be created (e.g. because the XDG data directory does not exist), fall back to .nvimlog in the current direcrtory. --- test/functional/options/defaults_spec.lua | 46 +++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 34921df6d4..b83b7b8eee 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -8,6 +8,8 @@ local clear = helpers.clear local eval = helpers.eval local eq = helpers.eq local neq = helpers.neq +local mkdir = helpers.mkdir +local rmdir = helpers.rmdir local function init_session(...) local args = { helpers.nvim_prog, '-i', 'NONE', '--embed', @@ -123,32 +125,52 @@ describe('startup defaults', function() 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', function() + it('defaults to stdpath("data")/log if empty', function() + eq(true, mkdir(xdgdir) and mkdir(xdgdatadir)) clear({env={ - XDG_DATA_HOME='Xtest-startup-logpath', - NVIM_LOG_FILE='', -- Empty value is considered invalid. + XDG_DATA_HOME=xdgdir, + NVIM_LOG_FILE='', -- Empty is invalid. }}) - -- TODO(jkeyes): use stdpath('data') instead. - local dir = helpers.iswin() and 'nvim-data' or 'nvim' - eq('Xtest-startup-logpath/'..dir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/')) + -- 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('if invalid, falls back to default', function() + it('defaults to stdpath("data")/log if invalid', function() + eq(true, mkdir(xdgdir) and mkdir(xdgdatadir)) clear({env={ - XDG_DATA_HOME='Xtest-startup-logpath', - NVIM_LOG_FILE='.', -- Directory is considered invalid. + XDG_DATA_HOME=xdgdir, + NVIM_LOG_FILE='.', -- Any directory is invalid. }}) - -- TODO(jkeyes): use stdpath('data') instead. - local dir = helpers.iswin() and 'nvim-data' or 'nvim' - eq('Xtest-startup-logpath/'..dir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/')) + -- 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) -- cgit From b4b09afabd2e25c078881433a6229a9e051384ca Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 31 May 2017 18:16:03 +0200 Subject: test: iswin(): detect without nvim session --- test/functional/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 62b0ce1200..b8512c0ad6 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -174,7 +174,7 @@ local os_name = (function() end)() local function iswin() - return os_name() == 'windows' + return package.config:sub(1,1) == '\\' end -- Executes a VimL function. -- cgit