aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/man_spec.lua
diff options
context:
space:
mode:
authorMahmoud Al-Qudsi <mqudsi@neosmart.net>2022-10-17 04:37:44 -0500
committerGitHub <noreply@github.com>2022-10-17 10:37:44 +0100
commit39911d76be560c998cc7dee51c5d94f811164f66 (patch)
tree626cc4a1317cdae822887cbc8b21fc1174dc6516 /test/functional/plugin/man_spec.lua
parent190019dd79aa66d9be9003b0249473634dd854eb (diff)
downloadrneovim-39911d76be560c998cc7dee51c5d94f811164f66.tar.gz
rneovim-39911d76be560c998cc7dee51c5d94f811164f66.tar.bz2
rneovim-39911d76be560c998cc7dee51c5d94f811164f66.zip
fix(man): handle absolute paths as `:Man` targets (#20624)
* fix(man): handle absolute paths as :Man targets Previously, attempting to provide `:Man` with an absolute path as the name would cause neovim to return the following error: ``` Error detected while processing command line: /usr/local/share/nvim/runtime/lua/man.lua:690: /usr/local/share/nvim/runtime/lua/man.lua:683: Vim:E426: tag not found: nil(nil) Press ENTER or type command to continue ``` ..because it would try to validate the existence of a man page for the provided name by executing `man -w /some/path` which (on at least some Linux machines [0]) returns `/some/path` instead of the path to the nroff files that would be formatted to satisfy the man(1) lookup. While man pages are not normally named after absolute paths, users shouldn't be blamed for trying. Given such a name/path, neovim would **not** complain that the path didn't have a corresponding man file but would error out when trying to call the tag function for the null-propagated name-and-section `nil(nil)`. (The same underlying error existed before this function was ported to lua, but did not exhibit the lua-specific `nil(nil)` name; instead a tag lookup for `()` would fail and error out.) With this patch, we detect the case where `man -w ...` returns the same value as the provided name to not only prevent invoking the tag function for a non-existent/malformed name+sect but also to properly report the non-existence of a man page for the provided lookup (the absolute path). While man(1) can be used to directly read an nroff-formatted document via `man /path/to/nroff.doc`, `:Man /path/to/nroff.doc` never supported this behavior so no functionality is lost in case the provided path _was_ an nroff file. [0]: `man -w /absolute/path` returning `/absolute/path` observed on an Ubuntu 18.04 installation. * test: add regression test for #20624 Add a functional test to `man_spec.lua` to check for a regression for #20624 by first obtaining an absolute path to a random file and materializing it to disk, then attempting to query `:Man` for an entry by that same name/path. The test passes if nvim correctly reports that there is no man page correspending to the provided name/path and fails if any other error (or no error) is shown.
Diffstat (limited to 'test/functional/plugin/man_spec.lua')
-rw-r--r--test/functional/plugin/man_spec.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua
index 3e63c5df9a..203424c855 100644
--- a/test/functional/plugin/man_spec.lua
+++ b/test/functional/plugin/man_spec.lua
@@ -6,6 +6,8 @@ local exec_lua = helpers.exec_lua
local funcs = helpers.funcs
local nvim_prog = helpers.nvim_prog
local matches = helpers.matches
+local write_file = helpers.write_file
+local tmpname = helpers.tmpname
clear()
if funcs.executable('man') == 0 then
@@ -156,4 +158,16 @@ describe(':Man', function()
local args = {nvim_prog, '--headless', '+autocmd VimLeave * echo "quit works!!"', '+Man!', '+call nvim_input("q")'}
matches('quit works!!', funcs.system(args, {'manpage contents'}))
end)
+
+ it('reports non-existent man pages for absolute paths', function()
+ local actual_file = tmpname()
+ -- actual_file must be an absolute path to an existent file for us to test against it
+ matches('^/.+', actual_file)
+ write_file(actual_file, '')
+ local args = {nvim_prog, '--headless', '+:Man ' .. actual_file, '+q'}
+ matches(('Error detected while processing command line:\r\n' ..
+ 'man.lua: "no manual entry for %s"'):format(actual_file),
+ funcs.system(args, {''}))
+ os.remove(actual_file)
+ end)
end)