Files
neovim/test/functional/ex_cmds/excmd_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

97 lines
3.1 KiB
Lua

local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local command = n.command
local eq = t.eq
local clear = n.clear
local fn = n.fn
local pcall_err = t.pcall_err
local assert_alive = n.assert_alive
describe('nlua_call_excmd excmds', function()
-- Exercise nlua_call_excmd by testing commands implemented with it (:log, :lsp).
before_each(function()
clear()
end)
it('error propagation, formatting', function()
t.eq('Vim(lsp):E5800: Invalid :lsp subcommand: bogus', pcall_err(command, 'lsp bogus'))
t.matches('Vim%(log%):E5200: No such log.*', pcall_err(command, 'log bogus'))
end)
end)
describe('excmds', function()
before_each(function()
clear()
end)
local function check_excmd_err(cmd, err)
eq(err .. ': ' .. cmd, pcall_err(command, cmd))
end
it('handle integer overflow from user-input #5555', function()
command(':9999999999999999999999999999999999999999')
command(':later 9999999999999999999999999999999999999999')
command(':echo expand("#<9999999999999999999999999999999999999999")')
command(':lockvar 9999999999999999999999999999999999999999')
command(
':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999'
)
check_excmd_err(
':tabnext 9999999999999999999999999999999999999999',
'Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999'
)
eq(
'Vim(Next):E163: There is only one file to edit',
pcall_err(command, ':N 9999999999999999999999999999999999999999')
)
check_excmd_err(
':bdelete 9999999999999999999999999999999999999999',
'Vim(bdelete):E516: No buffers were deleted'
)
eq(
'Vim(menu):E329: No menu "9999999999999999999999999999999999999999"',
pcall_err(command, ':menu 9999999999999999999999999999999999999999')
)
eq(
'Vim(substitute):E1510: Value too large: 9999999999999999999999999999999999999999',
pcall_err(command, ':%s/./b/9999999999999999999999999999999999999999')
)
assert_alive()
end)
it('listing long user command does not crash', function()
command('execute "command" repeat("T", 255) ":"')
command('command')
end)
it(':def is an unknown command #23149', function()
eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def'))
eq(1, fn.exists(':d'))
eq('delete', fn.fullcommand('d'))
eq(1, fn.exists(':de'))
eq('delete', fn.fullcommand('de'))
eq(0, fn.exists(':def'))
eq('', fn.fullcommand('def'))
eq(1, fn.exists(':defe'))
eq('defer', fn.fullcommand('defe'))
eq(2, fn.exists(':defer'))
eq('defer', fn.fullcommand('defer'))
end)
it('various command abbreviations', function()
-- :connect needs at least :conn
eq('change', fn.fullcommand('c'))
eq('copy', fn.fullcommand('co'))
eq('continue', fn.fullcommand('con'))
eq('connect', fn.fullcommand('conn'))
-- :restart needs at least :rest
eq('read', fn.fullcommand('r'))
eq('read', fn.fullcommand('re'))
eq('resize', fn.fullcommand('res'))
eq('restart', fn.fullcommand('rest'))
end)
end)