Files
neovim/test/functional/vimscript/vvars_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

60 lines
1.6 KiB
Lua

local t = require('test.testutil')
local describe, it, before_each = t.describe, t.it, t.before_each
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()
local clear, eval, eq = n.clear, n.eval, t.eq
local command = n.command
describe('v:event', function()
before_each(clear)
it('is empty before any autocommand', function()
eq({}, eval('v:event'))
end)
it('is immutable', function()
eq(false, pcall(command, 'let v:event = {}'))
eq(false, pcall(command, 'let v:event.mykey = {}'))
end)
end)
describe('v:argf', function()
it('is read-only', function()
n.clear()
t.matches('E46', t.pcall_err(command, "let v:argf = ['foo']"))
end)
it('gets file args, ignores :argadd, handles "--"', function()
local file1, file2, file3 = 'Xargf_sep1', 'Xargf_sep2', 'Xargf_sep3'
n.clear {
args_rm = { '--cmd', '-c' },
args = {
'--clean',
'--cmd',
'argadd extrafile.txt', -- :argadd should not affect v:argf.
file1,
file2,
'-c',
'let a = 1 + 3',
'--',
file3,
},
}
local abs1 = n.fn.fnamemodify(file1, ':p')
local abs2 = n.fn.fnamemodify(file2, ':p')
local abs3 = n.fn.fnamemodify(file3, ':p')
eq({ abs1, abs2, abs3 }, n.eval('v:argf'))
end)
end)
describe('v:startreason', function()
it('is read-only and starts as "normal"', function()
n.clear { args = { '--cmd', 'let g:early_startreason = v:startreason' } }
eq('normal', eval('g:early_startreason'))
t.matches('E46', t.pcall_err(command, "let v:startreason = 'restart'"))
end)
end)