mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
refactor(tests): remove redir_exec #15718
Problem - `redir_exec` is obsolete, but it keeps getting used in new tests because people copy existing tests. - Disadvantages of `redir_exec`: - Captures extra junk before the actual error/message that we _want_ to test. - Does not fail on error, unlike e.g. `command()`. Solution - Use new functions like `nvim_exec` and `pcall_err`.
This commit is contained in:
@@ -8,8 +8,8 @@ local funcs = helpers.funcs
|
||||
local meths = helpers.meths
|
||||
local command = helpers.command
|
||||
local exc_exec = helpers.exc_exec
|
||||
local redir_exec = helpers.redir_exec
|
||||
local pcall_err = helpers.pcall_err
|
||||
local exec_capture = helpers.exec_capture
|
||||
local curbufmeths = helpers.curbufmeths
|
||||
|
||||
before_each(clear)
|
||||
@@ -56,35 +56,35 @@ describe('b:changedtick', function()
|
||||
local ct = changedtick()
|
||||
local ctn = ct + 100500
|
||||
eq(0, exc_exec('let d = b:'))
|
||||
eq('\nE46: Cannot change read-only variable "b:changedtick"',
|
||||
redir_exec('let b:changedtick = ' .. ctn))
|
||||
eq('\nE46: Cannot change read-only variable "b:["changedtick"]"',
|
||||
redir_exec('let b:["changedtick"] = ' .. ctn))
|
||||
eq('\nE46: Cannot change read-only variable "b:.changedtick"',
|
||||
redir_exec('let b:.changedtick = ' .. ctn))
|
||||
eq('\nE46: Cannot change read-only variable "d.changedtick"',
|
||||
redir_exec('let d.changedtick = ' .. ctn))
|
||||
eq('Vim(let):E46: Cannot change read-only variable "b:changedtick"',
|
||||
pcall_err(command, 'let b:changedtick = ' .. ctn))
|
||||
eq('Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"',
|
||||
pcall_err(command, 'let b:["changedtick"] = ' .. ctn))
|
||||
eq('Vim(let):E46: Cannot change read-only variable "b:.changedtick"',
|
||||
pcall_err(command, 'let b:.changedtick = ' .. ctn))
|
||||
eq('Vim(let):E46: Cannot change read-only variable "d.changedtick"',
|
||||
pcall_err(command, 'let d.changedtick = ' .. ctn))
|
||||
eq('Key is read-only: changedtick',
|
||||
pcall_err(curbufmeths.set_var, 'changedtick', ctn))
|
||||
|
||||
eq('\nE795: Cannot delete variable b:changedtick',
|
||||
redir_exec('unlet b:changedtick'))
|
||||
eq('\nE46: Cannot change read-only variable "b:.changedtick"',
|
||||
redir_exec('unlet b:.changedtick'))
|
||||
eq('\nE46: Cannot change read-only variable "b:["changedtick"]"',
|
||||
redir_exec('unlet b:["changedtick"]'))
|
||||
eq('\nE46: Cannot change read-only variable "d.changedtick"',
|
||||
redir_exec('unlet d.changedtick'))
|
||||
eq('Vim(unlet):E795: Cannot delete variable b:changedtick',
|
||||
pcall_err(command, 'unlet b:changedtick'))
|
||||
eq('Vim(unlet):E46: Cannot change read-only variable "b:.changedtick"',
|
||||
pcall_err(command, 'unlet b:.changedtick'))
|
||||
eq('Vim(unlet):E46: Cannot change read-only variable "b:["changedtick"]"',
|
||||
pcall_err(command, 'unlet b:["changedtick"]'))
|
||||
eq('Vim(unlet):E46: Cannot change read-only variable "d.changedtick"',
|
||||
pcall_err(command, 'unlet d.changedtick'))
|
||||
eq('Key is read-only: changedtick',
|
||||
pcall_err(curbufmeths.del_var, 'changedtick'))
|
||||
eq(ct, changedtick())
|
||||
|
||||
eq('\nE46: Cannot change read-only variable "b:["changedtick"]"',
|
||||
redir_exec('let b:["changedtick"] += ' .. ctn))
|
||||
eq('\nE46: Cannot change read-only variable "b:["changedtick"]"',
|
||||
redir_exec('let b:["changedtick"] -= ' .. ctn))
|
||||
eq('\nE46: Cannot change read-only variable "b:["changedtick"]"',
|
||||
redir_exec('let b:["changedtick"] .= ' .. ctn))
|
||||
eq('Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"',
|
||||
pcall_err(command, 'let b:["changedtick"] += ' .. ctn))
|
||||
eq('Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"',
|
||||
pcall_err(command, 'let b:["changedtick"] -= ' .. ctn))
|
||||
eq('Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"',
|
||||
pcall_err(command, 'let b:["changedtick"] .= ' .. ctn))
|
||||
|
||||
eq(ct, changedtick())
|
||||
|
||||
@@ -93,23 +93,22 @@ describe('b:changedtick', function()
|
||||
eq(ct + 1, changedtick())
|
||||
end)
|
||||
it('is listed in :let output', function()
|
||||
eq('\nb:changedtick #2',
|
||||
redir_exec(':let b:'))
|
||||
eq('b:changedtick #2', exec_capture(':let b:'))
|
||||
end)
|
||||
it('fails to unlock b:changedtick', function()
|
||||
eq(0, exc_exec('let d = b:'))
|
||||
eq(0, funcs.islocked('b:changedtick'))
|
||||
eq(0, funcs.islocked('d.changedtick'))
|
||||
eq('\nE940: Cannot lock or unlock variable b:changedtick',
|
||||
redir_exec('unlockvar b:changedtick'))
|
||||
eq('\nE46: Cannot change read-only variable "d.changedtick"',
|
||||
redir_exec('unlockvar d.changedtick'))
|
||||
eq('Vim(unlockvar):E940: Cannot lock or unlock variable b:changedtick',
|
||||
pcall_err(command, 'unlockvar b:changedtick'))
|
||||
eq('Vim(unlockvar):E46: Cannot change read-only variable "d.changedtick"',
|
||||
pcall_err(command, 'unlockvar d.changedtick'))
|
||||
eq(0, funcs.islocked('b:changedtick'))
|
||||
eq(0, funcs.islocked('d.changedtick'))
|
||||
eq('\nE940: Cannot lock or unlock variable b:changedtick',
|
||||
redir_exec('lockvar b:changedtick'))
|
||||
eq('\nE46: Cannot change read-only variable "d.changedtick"',
|
||||
redir_exec('lockvar d.changedtick'))
|
||||
eq('Vim(lockvar):E940: Cannot lock or unlock variable b:changedtick',
|
||||
pcall_err(command, 'lockvar b:changedtick'))
|
||||
eq('Vim(lockvar):E46: Cannot change read-only variable "d.changedtick"',
|
||||
pcall_err(command, 'lockvar d.changedtick'))
|
||||
eq(0, funcs.islocked('b:changedtick'))
|
||||
eq(0, funcs.islocked('d.changedtick'))
|
||||
end)
|
||||
@@ -119,24 +118,24 @@ describe('b:changedtick', function()
|
||||
end)
|
||||
it('cannot be changed by filter() or map()', function()
|
||||
eq(2, changedtick())
|
||||
eq('\nE795: Cannot delete variable filter() argument',
|
||||
redir_exec('call filter(b:, 0)'))
|
||||
eq('\nE742: Cannot change value of map() argument',
|
||||
redir_exec('call map(b:, 0)'))
|
||||
eq('\nE742: Cannot change value of map() argument',
|
||||
redir_exec('call map(b:, "v:val")'))
|
||||
eq('Vim(call):E795: Cannot delete variable filter() argument',
|
||||
pcall_err(command, 'call filter(b:, 0)'))
|
||||
eq('Vim(call):E742: Cannot change value of map() argument',
|
||||
pcall_err(command, 'call map(b:, 0)'))
|
||||
eq('Vim(call):E742: Cannot change value of map() argument',
|
||||
pcall_err(command, 'call map(b:, "v:val")'))
|
||||
eq(2, changedtick())
|
||||
end)
|
||||
it('cannot be remove()d', function()
|
||||
eq(2, changedtick())
|
||||
eq('\nE795: Cannot delete variable remove() argument',
|
||||
redir_exec('call remove(b:, "changedtick")'))
|
||||
eq('Vim(call):E795: Cannot delete variable remove() argument',
|
||||
pcall_err(command, 'call remove(b:, "changedtick")'))
|
||||
eq(2, changedtick())
|
||||
end)
|
||||
it('does not inherit VAR_FIXED when copying dictionary over', function()
|
||||
eq(2, changedtick())
|
||||
eq('', redir_exec('let d1 = copy(b:)|let d1.changedtick = 42'))
|
||||
eq('', redir_exec('let d2 = copy(b:)|unlet d2.changedtick'))
|
||||
eq('', exec_capture('let d1 = copy(b:)|let d1.changedtick = 42'))
|
||||
eq('', exec_capture('let d2 = copy(b:)|unlet d2.changedtick'))
|
||||
eq(2, changedtick())
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user