Files
neovim/test/functional/ex_cmds/mkview_spec.lua
Justin M. Keyes 6d8c8b18d5 test(harness): migrate away from magic globals
Problem:
The magic globals `it`, `describe`, etc., are more trouble than they are
worth.

- Hooking into `after_each` requires `getfenv()` hacks.
- They confuse luals/emmylua, because the top-level `.luarc.json` isn't
  merged with `test/.luarc.json` (apparently a luals limitation?)
- They totally defeat discoverability because the user just has to
  "know" about the various magic symbols.

So they harm DX, which means they serve no purpose at all.

Solution:
- Expose the test API from `testutil`, so tests can call `t.it()`,
  `t.describe()`, etc., in the conventional way.
- Drop `getfenv()` hacks.
- Drop the `setfenv()` injection in `load_chunk`.
- Drop `test/_meta.lua`.
2026-07-21 13:22:39 +02:00

68 lines
2.0 KiB
Lua

local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
local clear = n.clear
local command = n.command
local get_pathsep = n.get_pathsep
local eq = t.eq
local fn = n.fn
local rmdir = n.rmdir
local mkdir = t.mkdir
local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec'
describe(':mkview', function()
local tmp_file_base = file_prefix .. '-tmpfile'
local local_dir = file_prefix .. '.d'
local view_dir = file_prefix .. '.view.d'
before_each(function()
clear()
mkdir(view_dir)
mkdir(local_dir)
end)
after_each(function()
-- Remove any views created in the view directory
rmdir(view_dir)
rmdir(local_dir)
end)
it('viewoption curdir restores local current directory', function()
local cwd_dir = fn.getcwd()
local set_view_dir_command = 'set viewdir=' .. cwd_dir .. get_pathsep() .. view_dir
-- By default the local current directory should save
command(set_view_dir_command)
command('edit ' .. tmp_file_base .. '1')
command('lcd ' .. local_dir)
command('mkview')
-- Create a new instance of Nvim to remove the 'lcd'
clear()
-- Disable saving the local current directory for the second view
command(set_view_dir_command)
command('set viewoptions-=curdir')
command('edit ' .. tmp_file_base .. '2')
command('lcd ' .. local_dir)
command('mkview')
-- Create a new instance of Nvim to test saved 'lcd' option
clear()
command(set_view_dir_command)
-- Load the view without a saved local current directory
command('edit ' .. tmp_file_base .. '2')
command('loadview')
-- The view's current directory should not have changed
eq(cwd_dir, fn.getcwd())
-- Load the view with a saved local current directory
command('edit ' .. tmp_file_base .. '1')
command('loadview')
-- The view's local directory should have been saved
eq(cwd_dir .. get_pathsep() .. local_dir, fn.getcwd())
end)
end)