diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/unit/os/env_spec.lua | 2 | ||||
| -rw-r--r-- | test/unit/path_spec.lua | 55 | 
2 files changed, 55 insertions, 2 deletions
| diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua index 575787a25e..cefd0315b7 100644 --- a/test/unit/os/env_spec.lua +++ b/test/unit/os/env_spec.lua @@ -13,7 +13,7 @@ require('lfs')  local cimp = cimport('./src/nvim/os/os.h') -describe('env function', function() +describe('env.c', function()    local function os_setenv(name, value, override)      return cimp.os_setenv(to_cstr(name), to_cstr(value), override)    end diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 6b9e2c8695..a9cba7df84 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -18,7 +18,7 @@ local cimp = cimport('./src/nvim/os/os.h', './src/nvim/path.h')  local length = 0  local buffer = nil -describe('path function', function() +describe('path.c', function()    describe('path_full_dir_name', function()      setup(function()        lfs.mkdir('unit-test-directory') @@ -293,6 +293,59 @@ describe('path_shorten_fname_if_possible', function()    end)  end) +describe('path.c path_guess_exepath', function() +  local cwd = lfs.currentdir() + +  for _,name in ipairs({'./nvim', '.nvim', 'foo/nvim'}) do +    itp('"'..name..'" returns name catenated with CWD', function() +      local bufsize = 255 +      local buf = cstr(bufsize, '') +      cimp.path_guess_exepath(name, buf, bufsize) +      eq(cwd..'/'..name, ffi.string(buf)) +    end) +  end + +  itp('absolute path returns the name unmodified', function() +    local name = '/foo/bar/baz' +    local bufsize = 255 +    local buf = cstr(bufsize, '') +    cimp.path_guess_exepath(name, buf, bufsize) +    eq(name, ffi.string(buf)) +  end) + +  itp('returns the name unmodified if not found in $PATH', function() +    local name = '23u0293_not_in_path' +    local bufsize = 255 +    local buf = cstr(bufsize, '') +    cimp.path_guess_exepath(name, buf, bufsize) +    eq(name, ffi.string(buf)) +  end) + +  itp('does not crash if $PATH item exceeds MAXPATHL', function() +    local orig_path_env = os.getenv('PATH') +    local name = 'cat'  -- Some executable in $PATH. +    local bufsize = 255 +    local buf = cstr(bufsize, '') +    local insane_path = orig_path_env..':'..(("x/"):rep(4097)) + +    cimp.os_setenv('PATH', insane_path, true) +    cimp.path_guess_exepath(name, buf, bufsize) +    eq('bin/' .. name, ffi.string(buf):sub(-#('bin/' .. name), -1)) + +    -- Restore $PATH. +    cimp.os_setenv('PATH', orig_path_env, true) +  end) + +  itp('returns full path found in $PATH', function() +    local name = 'cat'  -- Some executable in $PATH. +    local bufsize = 255 +    local buf = cstr(bufsize, '') +    cimp.path_guess_exepath(name, buf, bufsize) +    -- Usually "/bin/cat" on unix, "/path/to/nvim/cat" on Windows. +    eq('bin/' .. name, ffi.string(buf):sub(-#('bin/' .. name), -1)) +  end) +end) +  describe('path.c', function()    setup(function()      lfs.mkdir('unit-test-directory'); | 
