autochdir_spec.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear = n.clear
  4. local eq = t.eq
  5. local fn = n.fn
  6. local command = n.command
  7. local mkdir = t.mkdir
  8. describe("'autochdir'", function()
  9. it('given on the shell gets processed properly', function()
  10. local targetdir = 'test/functional/fixtures'
  11. -- By default 'autochdir' is off, thus getcwd() returns the repo root.
  12. clear(targetdir .. '/tty-test.c')
  13. local rootdir = fn.getcwd()
  14. local expected = rootdir .. '/' .. targetdir
  15. -- With 'autochdir' on, we should get the directory of tty-test.c.
  16. clear('--cmd', 'set autochdir', targetdir .. '/tty-test.c')
  17. eq(t.is_os('win') and expected:gsub('/', '\\') or expected, fn.getcwd())
  18. end)
  19. it('is not overwritten by getwinvar() call #17609', function()
  20. local curdir = t.fix_slashes(vim.uv.cwd())
  21. local dir_a = curdir .. '/Xtest-functional-options-autochdir.dir_a'
  22. local dir_b = curdir .. '/Xtest-functional-options-autochdir.dir_b'
  23. mkdir(dir_a)
  24. mkdir(dir_b)
  25. clear()
  26. command('set shellslash')
  27. command('set autochdir')
  28. command('edit ' .. dir_a .. '/file1')
  29. eq(dir_a, fn.getcwd())
  30. command('lcd ' .. dir_b)
  31. eq(dir_b, fn.getcwd())
  32. command('botright vnew ../file2')
  33. eq(curdir, fn.getcwd())
  34. command('wincmd w')
  35. eq(dir_a, fn.getcwd())
  36. fn.getwinvar(2, 'foo')
  37. eq(dir_a, fn.getcwd())
  38. n.rmdir(dir_a)
  39. n.rmdir(dir_b)
  40. end)
  41. end)