test: reduce some clear() calls

Use only a single clear() call in some test/functional/vimscript/ test
files whose test cases have very little side effect.

A downside of using a single clear() is that if a crash happens in one
test case, all following test cases in the same file will also fail, but
these functionalities and tests don't change very often.
This commit is contained in:
zeertzjq
2025-09-22 10:28:26 +08:00
parent 4adfc4b7bc
commit 777dafdc46
12 changed files with 22 additions and 23 deletions

View File

@@ -27,7 +27,7 @@ describe(':echo :echon :echomsg :echoerr', function()
end end
end end
before_each(function() setup(function()
clear() clear()
source([[ source([[
function String(s) function String(s)
@@ -149,7 +149,7 @@ describe(':echo :echon :echomsg :echoerr', function()
end) end)
describe('used to represent funcrefs', function() describe('used to represent funcrefs', function()
before_each(function() setup(function()
source([[ source([[
function Test1() function Test1()
endfunction endfunction

View File

@@ -11,7 +11,7 @@ local ok = t.ok
local NIL = vim.NIL local NIL = vim.NIL
describe('autoload/msgpack.vim', function() describe('autoload/msgpack.vim', function()
before_each(function() setup(function()
clear { args = { '-u', 'NORC' } } clear { args = { '-u', 'NORC' } }
end) end)

View File

@@ -47,7 +47,7 @@ local wshada_tmp, _, fname_tmp = get_shada_rw('Xtest-functional-plugin-shada.sha
describe('autoload/shada.vim', function() describe('autoload/shada.vim', function()
local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0) local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0)
before_each(function() setup(function()
reset() reset()
nvim_command([[ nvim_command([[
function ModifyVal(val) function ModifyVal(val)

View File

@@ -13,8 +13,8 @@ local NIL = vim.NIL
local source = n.source local source = n.source
describe('json_decode() function', function() describe('json_decode() function', function()
local restart = function(...) setup(function()
clear(...) clear()
source([[ source([[
language C language C
function Eq(exp, act) function Eq(exp, act)
@@ -57,8 +57,7 @@ describe('json_decode() function', function()
endif endif
endfunction endfunction
]]) ]])
end end)
before_each(restart)
local speq = function(expected, actual_expr) local speq = function(expected, actual_expr)
eq(1, fn.EvalEq(expected, actual_expr)) eq(1, fn.EvalEq(expected, actual_expr))
@@ -627,7 +626,7 @@ describe('json_decode() function', function()
end) end)
describe('json_encode() function', function() describe('json_encode() function', function()
before_each(function() setup(function()
clear() clear()
command('language C') command('language C')
end) end)

View File

@@ -8,7 +8,7 @@ local clear = n.clear
local fn = n.fn local fn = n.fn
local pcall_err = t.pcall_err local pcall_err = t.pcall_err
before_each(clear) setup(clear)
for _, func in ipairs({ 'min', 'max' }) do for _, func in ipairs({ 'min', 'max' }) do
describe(func .. '()', function() describe(func .. '()', function()
it('gives a single error message when multiple values failed conversions', function() it('gives a single error message when multiple values failed conversions', function()

View File

@@ -10,7 +10,7 @@ local exc_exec = n.exc_exec
local is_os = t.is_os local is_os = t.is_os
describe('msgpack*() functions', function() describe('msgpack*() functions', function()
before_each(clear) setup(clear)
local obj_test = function(msg, obj) local obj_test = function(msg, obj)
it(msg, function() it(msg, function()
@@ -415,7 +415,7 @@ local parse_eq = function(expect, list_arg)
end end
describe('msgpackparse() function', function() describe('msgpackparse() function', function()
before_each(clear) setup(clear)
it('restores nil as v:null', function() it('restores nil as v:null', function()
parse_eq(eval('[v:null]'), { '\192' }) parse_eq(eval('[v:null]'), { '\192' })
@@ -525,7 +525,7 @@ describe('msgpackparse() function', function()
end) end)
it('fails to parse a partial', function() it('fails to parse a partial', function()
command('function T() dict\nendfunction') command('function! T() dict\nendfunction')
eq( eq(
'Vim(call):E899: Argument of msgpackparse() must be a List or Blob', 'Vim(call):E899: Argument of msgpackparse() must be a List or Blob',
exc_exec('call msgpackparse(function("T", [1, 2], {}))') exc_exec('call msgpackparse(function("T", [1, 2], {}))')
@@ -555,7 +555,7 @@ describe('msgpackparse() function', function()
end) end)
describe('msgpackdump() function', function() describe('msgpackdump() function', function()
before_each(clear) setup(clear)
local dump_eq = function(exp_list, arg_expr) local dump_eq = function(exp_list, arg_expr)
eq(exp_list, eval('msgpackdump(' .. arg_expr .. ')')) eq(exp_list, eval('msgpackdump(' .. arg_expr .. ')'))
@@ -636,7 +636,7 @@ describe('msgpackdump() function', function()
end) end)
it('fails to dump a partial', function() it('fails to dump a partial', function()
command('function T() dict\nendfunction') command('function! T() dict\nendfunction')
command('let Todump = function("T", [1, 2], {})') command('let Todump = function("T", [1, 2], {})')
eq( eq(
'Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference', 'Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference',
@@ -776,7 +776,7 @@ describe('msgpackdump() function', function()
end) end)
it('fails to dump a partial', function() it('fails to dump a partial', function()
command('function T() dict\nendfunction') command('function! T() dict\nendfunction')
eq( eq(
'Vim(call):E686: Argument of msgpackdump() must be a List', 'Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(function("T", [1, 2], {}))') exc_exec('call msgpackdump(function("T", [1, 2], {}))')

View File

@@ -6,7 +6,7 @@ local eval = n.eval
local clear = n.clear local clear = n.clear
describe('Division operator', function() describe('Division operator', function()
before_each(clear) setup(clear)
it('returns infinity on {positive}/0.0', function() it('returns infinity on {positive}/0.0', function()
eq("str2float('inf')", eval('string(1.0/0.0)')) eq("str2float('inf')", eval('string(1.0/0.0)'))

View File

@@ -9,7 +9,7 @@ local api = n.api
local exc_exec = n.exc_exec local exc_exec = n.exc_exec
describe('printf()', function() describe('printf()', function()
before_each(clear) setup(clear)
it('works with zero and %b', function() it('works with zero and %b', function()
eq('0', fn.printf('%lb', 0)) eq('0', fn.printf('%lb', 0))

View File

@@ -32,7 +32,7 @@ end
describe('screenchar() and family respect floating windows', function() describe('screenchar() and family respect floating windows', function()
local function with_ext_multigrid(multigrid) local function with_ext_multigrid(multigrid)
before_each(function() setup(function()
clear() clear()
Screen.new(40, 7, { ext_multigrid = multigrid }) Screen.new(40, 7, { ext_multigrid = multigrid })
-- These commands result into visible text `aabc`. -- These commands result into visible text `aabc`.

View File

@@ -11,7 +11,7 @@ local command = n.command
local exc_exec = n.exc_exec local exc_exec = n.exc_exec
local pcall_err = t.pcall_err local pcall_err = t.pcall_err
before_each(clear) setup(clear)
describe('sort()', function() describe('sort()', function()
it('errors out when sorting special values', function() it('errors out when sorting special values', function()

View File

@@ -13,7 +13,7 @@ local NIL = vim.NIL
local source = n.source local source = n.source
describe('string() function', function() describe('string() function', function()
before_each(clear) setup(clear)
describe('used to represent floating-point values', function() describe('used to represent floating-point values', function()
it('dumps NaN values', function() it('dumps NaN values', function()
@@ -103,7 +103,7 @@ describe('string() function', function()
end) end)
describe('used to represent funcrefs', function() describe('used to represent funcrefs', function()
before_each(function() setup(function()
source([[ source([[
function Test1() function Test1()
endfunction endfunction

View File

@@ -7,7 +7,7 @@ local command = n.command
local exc_exec = n.exc_exec local exc_exec = n.exc_exec
local pcall_err = t.pcall_err local pcall_err = t.pcall_err
before_each(clear) setup(clear)
describe('uniq()', function() describe('uniq()', function()
it('errors out when processing special values', function() it('errors out when processing special values', function()