exepath_spec.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local eq, clear, call = t.eq, n.clear, n.call
  4. local command = n.command
  5. local exc_exec = n.exc_exec
  6. local matches = t.matches
  7. local is_os = t.is_os
  8. local set_shell_powershell = n.set_shell_powershell
  9. local eval = n.eval
  10. local find_dummies = function(ext_pat)
  11. local tmp_path = eval('$PATH')
  12. command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
  13. matches('null' .. ext_pat, call('exepath', 'null'))
  14. matches('true' .. ext_pat, call('exepath', 'true'))
  15. matches('false' .. ext_pat, call('exepath', 'false'))
  16. command("let $PATH = '" .. tmp_path .. "'")
  17. end
  18. describe('exepath()', function()
  19. before_each(clear)
  20. it('fails for invalid values', function()
  21. for _, input in ipairs({ 'v:null', 'v:true', 'v:false', '{}', '[]' }) do
  22. eq(
  23. 'Vim(call):E1174: String required for argument 1',
  24. exc_exec('call exepath(' .. input .. ')')
  25. )
  26. end
  27. eq('Vim(call):E1175: Non-empty string required for argument 1', exc_exec('call exepath("")'))
  28. command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
  29. for _, input in ipairs({ 'v:null', 'v:true', 'v:false' }) do
  30. eq(
  31. 'Vim(call):E1174: String required for argument 1',
  32. exc_exec('call exepath(' .. input .. ')')
  33. )
  34. end
  35. end)
  36. if is_os('win') then
  37. it('returns 1 for commands in $PATH (Windows)', function()
  38. local exe = 'ping'
  39. matches(exe .. '%.EXE$', call('exepath', exe))
  40. end)
  41. it('append extension if omitted', function()
  42. local filename = 'cmd'
  43. local pathext = '.exe'
  44. clear({ env = { PATHEXT = pathext } })
  45. eq(call('exepath', filename .. pathext), call('exepath', filename))
  46. end)
  47. it(
  48. 'returns file WITH extension if files both with and without extension exist in $PATH',
  49. function()
  50. local ext_pat = '%.CMD$'
  51. find_dummies(ext_pat)
  52. set_shell_powershell()
  53. find_dummies(ext_pat)
  54. end
  55. )
  56. else
  57. it('returns 1 for commands in $PATH (not Windows)', function()
  58. local exe = 'ls'
  59. matches(exe .. '$', call('exepath', exe))
  60. end)
  61. it(
  62. 'returns file WITHOUT extension if files both with and without extension exist in $PATH',
  63. function()
  64. find_dummies('$')
  65. end
  66. )
  67. end
  68. end)