2016-07-01 11:27:56 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local clear = helpers.clear
|
|
|
|
local eq = helpers.eq
|
2024-01-12 10:59:57 -07:00
|
|
|
local fn = helpers.fn
|
2022-03-05 20:01:49 -07:00
|
|
|
local command = helpers.command
|
2023-04-04 12:59:06 -07:00
|
|
|
local mkdir = helpers.mkdir
|
2016-07-01 11:27:56 -07:00
|
|
|
|
|
|
|
describe("'autochdir'", function()
|
|
|
|
it('given on the shell gets processed properly', function()
|
|
|
|
local targetdir = 'test/functional/fixtures'
|
|
|
|
|
|
|
|
-- By default 'autochdir' is off, thus getcwd() returns the repo root.
|
2024-01-02 18:09:18 -07:00
|
|
|
clear(targetdir .. '/tty-test.c')
|
2024-01-12 10:59:57 -07:00
|
|
|
local rootdir = fn.getcwd()
|
2017-10-19 14:26:03 -07:00
|
|
|
local expected = rootdir .. '/' .. targetdir
|
2016-07-01 11:27:56 -07:00
|
|
|
|
|
|
|
-- With 'autochdir' on, we should get the directory of tty-test.c.
|
2024-01-02 18:09:18 -07:00
|
|
|
clear('--cmd', 'set autochdir', targetdir .. '/tty-test.c')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(helpers.is_os('win') and expected:gsub('/', '\\') or expected, fn.getcwd())
|
2022-03-05 20:01:49 -07:00
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it('is not overwritten by getwinvar() call #17609', function()
|
2024-01-12 05:03:25 -07:00
|
|
|
local curdir = vim.uv.cwd():gsub('\\', '/')
|
2024-01-02 18:09:18 -07:00
|
|
|
local dir_a = curdir .. '/Xtest-functional-options-autochdir.dir_a'
|
|
|
|
local dir_b = curdir .. '/Xtest-functional-options-autochdir.dir_b'
|
2023-04-04 12:59:06 -07:00
|
|
|
mkdir(dir_a)
|
|
|
|
mkdir(dir_b)
|
2022-03-05 20:01:49 -07:00
|
|
|
clear()
|
|
|
|
command('set shellslash')
|
|
|
|
command('set autochdir')
|
2024-01-02 18:09:18 -07:00
|
|
|
command('edit ' .. dir_a .. '/file1')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(dir_a, fn.getcwd())
|
2024-01-02 18:09:18 -07:00
|
|
|
command('lcd ' .. dir_b)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(dir_b, fn.getcwd())
|
2022-03-05 20:01:49 -07:00
|
|
|
command('botright vnew ../file2')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(curdir, fn.getcwd())
|
2022-03-05 20:01:49 -07:00
|
|
|
command('wincmd w')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(dir_a, fn.getcwd())
|
|
|
|
fn.getwinvar(2, 'foo')
|
|
|
|
eq(dir_a, fn.getcwd())
|
2022-03-05 20:01:49 -07:00
|
|
|
helpers.rmdir(dir_a)
|
|
|
|
helpers.rmdir(dir_b)
|
2016-07-01 11:27:56 -07:00
|
|
|
end)
|
|
|
|
end)
|