autochdir_spec.lua 1.5 KB

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