aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/os/fs.c2
-rw-r--r--src/nvim/testdir/test_functions.vim4
-rw-r--r--test/functional/eval/executable_spec.lua61
-rw-r--r--test/functional/eval/exepath_spec.lua14
4 files changed, 68 insertions, 13 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 9a96241178..b75607b7b1 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -276,7 +276,7 @@ bool os_can_exe(const char_u *name, char_u **abspath, bool use_path)
}
#ifdef WIN32
-/// Returns true if extension of `name` is executalbe file exteinsion.
+/// Returns true if extension of `name` is executable file exteinsion.
static bool is_extension_executable(const char *name)
FUNC_ATTR_NONNULL_ALL
{
diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim
index 13e2dcf804..46c2d0f4cd 100644
--- a/src/nvim/testdir/test_functions.vim
+++ b/src/nvim/testdir/test_functions.vim
@@ -881,8 +881,8 @@ func Test_Executable()
call assert_equal(1, executable('notepad'))
call assert_equal(1, executable('notepad.exe'))
call assert_equal(0, executable('notepad.exe.exe'))
- call assert_equal(1, executable('shell32.dll'))
- call assert_equal(1, executable('win.ini'))
+ call assert_equal(0, executable('shell32.dll'))
+ call assert_equal(0, executable('win.ini'))
elseif has('unix')
call assert_equal(1, executable('cat'))
call assert_equal(0, executable('nodogshere'))
diff --git a/test/functional/eval/executable_spec.lua b/test/functional/eval/executable_spec.lua
index c931b47221..1055675c26 100644
--- a/test/functional/eval/executable_spec.lua
+++ b/test/functional/eval/executable_spec.lua
@@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
-local eq, clear, call, iswin, write_file =
- helpers.eq, helpers.clear, helpers.call, helpers.iswin, helpers.write_file
+local eq, clear, call, iswin, write_file, command =
+ helpers.eq, helpers.clear, helpers.call, helpers.iswin, helpers.write_file,
+ helpers.command
describe('executable()', function()
before_each(clear)
@@ -48,18 +49,17 @@ describe('executable()', function()
end)
it('not set', function()
- local expected = iswin() and 1 or 0
- eq(expected, call('executable', 'Xtest_not_executable'))
- eq(expected, call('executable', './Xtest_not_executable'))
+ eq(0, call('executable', 'Xtest_not_executable'))
+ eq(0, call('executable', './Xtest_not_executable'))
end)
it('set, unqualified and not in $PATH', function()
- local expected = iswin() and 1 or 0
- eq(expected, call('executable', 'Xtest_executable'))
+ eq(0, call('executable', 'Xtest_executable'))
end)
it('set, qualified as a path', function()
- eq(1, call('executable', './Xtest_executable'))
+ local expected = iswin() and 0 or 1
+ eq(expected, call('executable', './Xtest_executable'))
end)
end)
end)
@@ -136,16 +136,18 @@ describe('executable() (Windows)', function()
eq(1, call('executable', '.\\test_executable_zzz'))
end)
- it('returns 1 for any existing filename', function()
+ it('returns 1 for any existing filename, when a Unix-shell like \'shell\'', function()
clear({env={PATHEXT=''}})
+ command('set shell=sh')
for _,ext in ipairs(exts) do
eq(1, call('executable', 'test_executable_'..ext..'.'..ext))
end
eq(1, call('executable', 'test_executable_zzz.zzz'))
end)
- it('returns 1 for any existing path (backslashes)', function()
+ it('returns 1 for any existing path, when a Unix-shell like \'shell\' (backslashes)', function()
clear({env={PATHEXT=''}})
+ command('set shell=bash.exe')
for _,ext in ipairs(exts) do
eq(1, call('executable', '.\\test_executable_'..ext..'.'..ext))
eq(1, call('executable', './test_executable_'..ext..'.'..ext))
@@ -153,4 +155,43 @@ describe('executable() (Windows)', function()
eq(1, call('executable', '.\\test_executable_zzz.zzz'))
eq(1, call('executable', './test_executable_zzz.zzz'))
end)
+
+ it('returns 1 for any existing filename, when $PATHEXT contain dot itself', function()
+ clear({env={PATHEXT='.;.zzz'}})
+ command('set shell=sh')
+ for _,ext in ipairs(exts) do
+ eq(1, call('executable', 'test_executable_'..ext..'.'..ext))
+ end
+ eq(1, call('executable', 'test_executable_zzz.zzz'))
+ clear({env={PATHEXT='.zzz;.'}})
+ command('set shell=sh')
+ for _,ext in ipairs(exts) do
+ eq(1, call('executable', 'test_executable_'..ext..'.'..ext))
+ end
+ eq(1, call('executable', 'test_executable_zzz.zzz'))
+ end)
+
+ it('returns 1 for any existing path, when $PATHEXT contain dot itself (backslashes)', function()
+ clear({env={PATHEXT='.;.zzz'}})
+ command('set shell=bash.exe')
+ for _,ext in ipairs(exts) do
+ eq(1, call('executable', '.\\test_executable_'..ext..'.'..ext))
+ eq(1, call('executable', './test_executable_'..ext..'.'..ext))
+ end
+ eq(1, call('executable', '.\\test_executable_zzz.zzz'))
+ eq(1, call('executable', './test_executable_zzz.zzz'))
+ end)
+
+ it('ignore case of extension', function()
+ clear({env={PATHEXT='.ZZZ'}})
+ eq(1, call('executable', 'test_executable_zzz.zzz'))
+ end)
+
+ it('file is not found by relative path from $PATH', function()
+ clear({env={PATHEXT=''}})
+ eq(0, call('executable', './System32/notepad.exe'))
+ eq(0, call('executable', '.\\System32\\notepad.exe'))
+ eq(0, call('executable', '../notepad.exe'))
+ eq(0, call('executable', '..\\notepad.exe'))
+ end)
end)
diff --git a/test/functional/eval/exepath_spec.lua b/test/functional/eval/exepath_spec.lua
new file mode 100644
index 0000000000..50aa412867
--- /dev/null
+++ b/test/functional/eval/exepath_spec.lua
@@ -0,0 +1,14 @@
+local helpers = require('test.functional.helpers')(after_each)
+local eq, clear, call, iswin =
+ helpers.eq, helpers.clear, helpers.call, helpers.iswin
+
+describe('exepath() (Windows)', function()
+ if not iswin() then return end -- N/A for Unix.
+
+ it('append extension, even if omit extension', function()
+ local filename = 'cmd'
+ local pathext = '.exe'
+ clear({env={PATHEXT=pathext}})
+ eq(call('exepath', filename..pathext), call('exepath', filename))
+ end)
+end)