autochdir_spec.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear, eq, matches = n.clear, t.eq, t.matches
  4. local eval, command, call, api = n.eval, n.command, n.call, n.api
  5. local source, exec_capture = n.source, n.exec_capture
  6. local mkdir = t.mkdir
  7. local function expected_empty()
  8. eq({}, api.nvim_get_vvar('errors'))
  9. end
  10. describe('autochdir behavior', function()
  11. local dir = 'Xtest_functional_legacy_autochdir'
  12. before_each(function()
  13. mkdir(dir)
  14. clear()
  15. command('set shellslash')
  16. end)
  17. after_each(function()
  18. n.rmdir(dir)
  19. end)
  20. -- Tests vim/vim#777 without test_autochdir().
  21. it('sets filename', function()
  22. command('set acd')
  23. command('new')
  24. command('w ' .. dir .. '/Xtest')
  25. eq('Xtest', eval("expand('%')"))
  26. eq(dir, eval([[substitute(getcwd(), '.*/\(\k*\)', '\1', '')]]))
  27. end)
  28. it(':file in win_execute() does not cause wrong directory', function()
  29. command('cd ' .. dir)
  30. source([[
  31. func Test_set_filename_other_window()
  32. let cwd = getcwd()
  33. call mkdir('Xa')
  34. call mkdir('Xb')
  35. call mkdir('Xc')
  36. try
  37. args Xa/aaa.txt Xb/bbb.txt
  38. set acd
  39. let winid = win_getid()
  40. snext
  41. call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
  42. call win_execute(winid, 'file ' .. cwd .. '/Xc/ccc.txt')
  43. call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
  44. finally
  45. set noacd
  46. call chdir(cwd)
  47. call delete('Xa', 'rf')
  48. call delete('Xb', 'rf')
  49. call delete('Xc', 'rf')
  50. bwipe! aaa.txt
  51. bwipe! bbb.txt
  52. bwipe! ccc.txt
  53. endtry
  54. endfunc
  55. ]])
  56. call('Test_set_filename_other_window')
  57. expected_empty()
  58. end)
  59. it('win_execute() does not change directory', function()
  60. local subdir = 'Xfile'
  61. command('cd ' .. dir)
  62. command('set acd')
  63. call('mkdir', subdir)
  64. local winid = eval('win_getid()')
  65. command('new ' .. subdir .. '/file')
  66. matches(dir .. '/' .. subdir .. '$', eval('getcwd()'))
  67. command('cd ..')
  68. matches(dir .. '$', eval('getcwd()'))
  69. call('win_execute', winid, 'echo')
  70. matches(dir .. '$', eval('getcwd()'))
  71. end)
  72. it(':verbose pwd shows whether autochdir is used', function()
  73. local subdir = 'Xautodir'
  74. command('cd ' .. dir)
  75. local cwd = eval('getcwd()')
  76. command('edit global.txt')
  77. matches('%[global%].*' .. dir .. '$', exec_capture('verbose pwd'))
  78. call('mkdir', subdir)
  79. command('split ' .. subdir .. '/local.txt')
  80. command('lcd ' .. subdir)
  81. matches('%[window%].*' .. dir .. '/' .. subdir .. '$', exec_capture('verbose pwd'))
  82. command('set acd')
  83. command('wincmd w')
  84. matches('%[autochdir%].*' .. dir .. '$', exec_capture('verbose pwd'))
  85. command('tcd ' .. cwd)
  86. matches('%[tabpage%].*' .. dir .. '$', exec_capture('verbose pwd'))
  87. command('cd ' .. cwd)
  88. matches('%[global%].*' .. dir .. '$', exec_capture('verbose pwd'))
  89. command('lcd ' .. cwd)
  90. matches('%[window%].*' .. dir .. '$', exec_capture('verbose pwd'))
  91. command('edit')
  92. matches('%[autochdir%].*' .. dir .. '$', exec_capture('verbose pwd'))
  93. command('enew')
  94. command('wincmd w')
  95. matches('%[autochdir%].*' .. dir .. '/' .. subdir .. '$', exec_capture('verbose pwd'))
  96. command('wincmd w')
  97. matches('%[window%].*' .. dir .. '$', exec_capture('verbose pwd'))
  98. command('wincmd w')
  99. matches('%[autochdir%].*' .. dir .. '/' .. subdir .. '$', exec_capture('verbose pwd'))
  100. command('set noacd')
  101. matches('%[autochdir%].*' .. dir .. '/' .. subdir .. '$', exec_capture('verbose pwd'))
  102. command('wincmd w')
  103. matches('%[window%].*' .. dir .. '$', exec_capture('verbose pwd'))
  104. command('cd ' .. cwd)
  105. matches('%[global%].*' .. dir .. '$', exec_capture('verbose pwd'))
  106. command('wincmd w')
  107. matches('%[window%].*' .. dir .. '/' .. subdir .. '$', exec_capture('verbose pwd'))
  108. end)
  109. end)