diff options
Diffstat (limited to 'test/functional/vimscript')
-rw-r--r-- | test/functional/vimscript/changedtick_spec.lua | 85 | ||||
-rw-r--r-- | test/functional/vimscript/ctx_functions_spec.lua | 38 | ||||
-rw-r--r-- | test/functional/vimscript/execute_spec.lua | 10 | ||||
-rw-r--r-- | test/functional/vimscript/json_functions_spec.lua | 7 | ||||
-rw-r--r-- | test/functional/vimscript/let_spec.lua | 10 | ||||
-rw-r--r-- | test/functional/vimscript/minmax_functions_spec.lua | 30 | ||||
-rw-r--r-- | test/functional/vimscript/null_spec.lua | 14 | ||||
-rw-r--r-- | test/functional/vimscript/sort_spec.lua | 7 | ||||
-rw-r--r-- | test/functional/vimscript/string_spec.lua | 44 | ||||
-rw-r--r-- | test/functional/vimscript/uniq_spec.lua | 8 | ||||
-rw-r--r-- | test/functional/vimscript/writefile_spec.lua | 59 |
11 files changed, 155 insertions, 157 deletions
diff --git a/test/functional/vimscript/changedtick_spec.lua b/test/functional/vimscript/changedtick_spec.lua index 99406d9d7a..8533fac9ec 100644 --- a/test/functional/vimscript/changedtick_spec.lua +++ b/test/functional/vimscript/changedtick_spec.lua @@ -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) diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua index f23adbc556..d92a81c55b 100644 --- a/test/functional/vimscript/ctx_functions_spec.lua +++ b/test/functional/vimscript/ctx_functions_spec.lua @@ -9,7 +9,7 @@ local feed = helpers.feed local map = helpers.tbl_map local nvim = helpers.nvim local parse_context = helpers.parse_context -local redir_exec = helpers.redir_exec +local exec_capture = helpers.exec_capture local source = helpers.source local trim = helpers.trim local write_file = helpers.write_file @@ -163,33 +163,29 @@ describe('context functions', function() endfunction ]]) - eq('\nHello, World!', redir_exec([[call Greet('World')]])) - eq('\nHello, World!'.. + eq('Hello, World!', exec_capture([[call Greet('World')]])) + eq('Hello, World!'.. '\nHello, One!'.. '\nHello, Two!'.. '\nHello, Three!', - redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]])) + exec_capture([[call GreetAll('World', 'One', 'Two', 'Three')]])) call('SaveSFuncs') call('DeleteSFuncs') - eq('\nError detected while processing function Greet:'.. - '\nline 1:'.. - '\nE117: Unknown function: s:greet', - redir_exec([[call Greet('World')]])) - eq('\nError detected while processing function GreetAll:'.. - '\nline 1:'.. - '\nE117: Unknown function: s:greet_all', - redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]])) + eq('Vim(call):E117: Unknown function: s:greet', + pcall_err(command, [[call Greet('World')]])) + eq('Vim(call):E117: Unknown function: s:greet_all', + pcall_err(command, [[call GreetAll('World', 'One', 'Two', 'Three')]])) call('RestoreFuncs') - eq('\nHello, World!', redir_exec([[call Greet('World')]])) - eq('\nHello, World!'.. + eq('Hello, World!', exec_capture([[call Greet('World')]])) + eq('Hello, World!'.. '\nHello, One!'.. '\nHello, Two!'.. '\nHello, Three!', - redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]])) + exec_capture([[call GreetAll('World', 'One', 'Two', 'Three')]])) end) it('saves and restores functions properly', function() @@ -206,12 +202,12 @@ describe('context functions', function() endfunction ]]) - eq('\nHello, World!', redir_exec([[call Greet('World')]])) - eq('\nHello, World!'.. + eq('Hello, World!', exec_capture([[call Greet('World')]])) + eq('Hello, World!'.. '\nHello, One!'.. '\nHello, Two!'.. '\nHello, Three!', - redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]])) + exec_capture([[call GreetAll('World', 'One', 'Two', 'Three')]])) call('ctxpush', {'funcs'}) command('delfunction Greet') @@ -223,12 +219,12 @@ describe('context functions', function() call('ctxpop') - eq('\nHello, World!', redir_exec([[call Greet('World')]])) - eq('\nHello, World!'.. + eq('Hello, World!', exec_capture([[call Greet('World')]])) + eq('Hello, World!'.. '\nHello, One!'.. '\nHello, Two!'.. '\nHello, Three!', - redir_exec([[call GreetAll('World', 'One', 'Two', 'Three')]])) + exec_capture([[call GreetAll('World', 'One', 'Two', 'Three')]])) end) it('errors out when context stack is empty', function() diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index fccf52935b..e21c71dc7f 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -3,7 +3,6 @@ local eq = helpers.eq local eval = helpers.eval local clear = helpers.clear local source = helpers.source -local redir_exec = helpers.redir_exec local exc_exec = helpers.exc_exec local funcs = helpers.funcs local Screen = require('test.functional.ui.screen') @@ -15,7 +14,14 @@ describe('execute()', function() before_each(clear) it('captures the same result as :redir', function() - eq(redir_exec('messages'), funcs.execute('messages')) + command([[ + echomsg 'foo 1' + echomsg 'foo 2' + redir => g:__redir_output + silent! messages + redir END + ]]) + eq(eval('g:__redir_output'), funcs.execute('messages')) end) it('captures the concatenated outputs of a List of commands', function() diff --git a/test/functional/vimscript/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua index 9b5e207c07..c3b607b544 100644 --- a/test/functional/vimscript/json_functions_spec.lua +++ b/test/functional/vimscript/json_functions_spec.lua @@ -6,7 +6,7 @@ local eq = helpers.eq local eval = helpers.eval local command = helpers.command local exc_exec = helpers.exc_exec -local redir_exec = helpers.redir_exec +local pcall_err = helpers.pcall_err local NIL = helpers.NIL local source = helpers.source @@ -517,9 +517,8 @@ describe('json_decode() function', function() it('does not overflow when writing error message about decoding ["", ""]', function() - eq('\nE474: Attempt to decode a blank string' - .. '\nE474: Failed to parse \n', - redir_exec('call json_decode(["", ""])')) + eq('Vim(call):E474: Attempt to decode a blank string', + pcall_err(command, 'call json_decode(["", ""])')) end) end) diff --git a/test/functional/vimscript/let_spec.lua b/test/functional/vimscript/let_spec.lua index 5bc703b567..4ff4090a18 100644 --- a/test/functional/vimscript/let_spec.lua +++ b/test/functional/vimscript/let_spec.lua @@ -5,7 +5,7 @@ local clear = helpers.clear local command = helpers.command local eval = helpers.eval local meths = helpers.meths -local redir_exec = helpers.redir_exec +local exec_capture = helpers.exec_capture local source = helpers.source local nvim_dir = helpers.nvim_dir @@ -14,14 +14,14 @@ before_each(clear) describe(':let', function() it('correctly lists variables with curly-braces', function() meths.set_var('v', {0}) - eq('\nv [0]', redir_exec('let {"v"}')) + eq('v [0]', exec_capture('let {"v"}')) end) it('correctly lists variables with subscript', function() meths.set_var('v', {0}) - eq('\nv[0] #0', redir_exec('let v[0]')) - eq('\ng:["v"][0] #0', redir_exec('let g:["v"][0]')) - eq('\n{"g:"}["v"][0] #0', redir_exec('let {"g:"}["v"][0]')) + eq('v[0] #0', exec_capture('let v[0]')) + eq('g:["v"][0] #0', exec_capture('let g:["v"][0]')) + eq('{"g:"}["v"][0] #0', exec_capture('let {"g:"}["v"][0]')) end) it(":unlet self-referencing node in a List graph #6070", function() diff --git a/test/functional/vimscript/minmax_functions_spec.lua b/test/functional/vimscript/minmax_functions_spec.lua index c6eb754f91..91106bef1e 100644 --- a/test/functional/vimscript/minmax_functions_spec.lua +++ b/test/functional/vimscript/minmax_functions_spec.lua @@ -2,29 +2,28 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local eval = helpers.eval +local command = helpers.command local clear = helpers.clear local funcs = helpers.funcs -local redir_exec = helpers.redir_exec +local pcall_err = helpers.pcall_err before_each(clear) for _, func in ipairs({'min', 'max'}) do describe(func .. '()', function() it('gives a single error message when multiple values failed conversions', function() - eq('\nE745: Using a List as a Number\n0', - redir_exec('echo ' .. func .. '([-5, [], [], [], 5])')) - eq('\nE745: Using a List as a Number\n0', - redir_exec('echo ' .. func .. '({1:-5, 2:[], 3:[], 4:[], 5:5})')) + eq('Vim(echo):E745: Using a List as a Number', + pcall_err(command, 'echo ' .. func .. '([-5, [], [], [], 5])')) + eq('Vim(echo):E745: Using a List as a Number', + pcall_err(command, 'echo ' .. func .. '({1:-5, 2:[], 3:[], 4:[], 5:5})')) for errmsg, errinput in pairs({ - ['E745: Using a List as a Number'] = '[]', - ['E805: Using a Float as a Number'] = '0.0', - ['E703: Using a Funcref as a Number'] = 'function("tr")', - ['E728: Using a Dictionary as a Number'] = '{}', + ['Vim(echo):E745: Using a List as a Number'] = '[]', + ['Vim(echo):E805: Using a Float as a Number'] = '0.0', + ['Vim(echo):E703: Using a Funcref as a Number'] = 'function("tr")', + ['Vim(echo):E728: Using a Dictionary as a Number'] = '{}', }) do - eq('\n' .. errmsg .. '\n0', - redir_exec('echo ' .. func .. '([' .. errinput .. '])')) - eq('\n' .. errmsg .. '\n0', - redir_exec('echo ' .. func .. '({1:' .. errinput .. '})')) + eq(errmsg, pcall_err(command, 'echo ' .. func .. '([' .. errinput .. '])')) + eq(errmsg, pcall_err(command, 'echo ' .. func .. '({1:' .. errinput .. '})')) end end) it('works with arrays/dictionaries with zero items', function() @@ -42,9 +41,8 @@ for _, func in ipairs({'min', 'max'}) do it('errors out for invalid types', function() for _, errinput in ipairs({'1', 'v:true', 'v:false', 'v:null', 'function("tr")', '""'}) do - eq(('\nE712: Argument of %s() must be a List or Dictionary\n0'):format( - func), - redir_exec('echo ' .. func .. '(' .. errinput .. ')')) + eq(('Vim(echo):E712: Argument of %s() must be a List or Dictionary'):format(func), + pcall_err(command, 'echo ' .. func .. '(' .. errinput .. ')')) end end) end) diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua index bc88e6c8b3..7ecbcd2fd6 100644 --- a/test/functional/vimscript/null_spec.lua +++ b/test/functional/vimscript/null_spec.lua @@ -1,7 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local curbufmeths = helpers.curbufmeths -local redir_exec = helpers.redir_exec local exc_exec = helpers.exc_exec local command = helpers.command local clear = helpers.clear @@ -9,6 +8,19 @@ local meths = helpers.meths local funcs = helpers.funcs local eq = helpers.eq +local function redir_exec(cmd) + meths.set_var('__redir_exec_cmd', cmd) + command([[ + redir => g:__redir_exec_output + silent! execute g:__redir_exec_cmd + redir END + ]]) + local ret = meths.get_var('__redir_exec_output') + meths.del_var('__redir_exec_output') + meths.del_var('__redir_exec_cmd') + return ret +end + describe('NULL', function() before_each(function() clear() diff --git a/test/functional/vimscript/sort_spec.lua b/test/functional/vimscript/sort_spec.lua index e1cc2c2924..e09949a0f2 100644 --- a/test/functional/vimscript/sort_spec.lua +++ b/test/functional/vimscript/sort_spec.lua @@ -8,7 +8,7 @@ local meths = helpers.meths local funcs = helpers.funcs local command = helpers.command local exc_exec = helpers.exc_exec -local redir_exec = helpers.redir_exec +local pcall_err = helpers.pcall_err before_each(clear) @@ -50,8 +50,7 @@ describe('sort()', function() return (a:a > a:b) - (a:a < a:b) endfunction ]]) - eq('\nE745: Using a List as a Number\nE702: Sort compare function failed', - redir_exec('let sl = sort([1, 0, [], 3, 2], "Cmp")')) - eq({1, 0, {}, 3, 2}, meths.get_var('sl')) + eq('Vim(let):E745: Using a List as a Number', + pcall_err(command, 'let sl = sort([1, 0, [], 3, 2], "Cmp")')) end) end) diff --git a/test/functional/vimscript/string_spec.lua b/test/functional/vimscript/string_spec.lua index adc1af9b8e..cb7e93f264 100644 --- a/test/functional/vimscript/string_spec.lua +++ b/test/functional/vimscript/string_spec.lua @@ -5,11 +5,10 @@ local command = helpers.command local meths = helpers.meths local eval = helpers.eval local exc_exec = helpers.exc_exec -local redir_exec = helpers.redir_exec +local pcall_err = helpers.pcall_err local funcs = helpers.funcs local NIL = helpers.NIL local source = helpers.source -local dedent = helpers.dedent describe('string() function', function() before_each(clear) @@ -140,8 +139,8 @@ describe('string() function', function() let TestDictRef = function('TestDict', d) let d.tdr = TestDictRef ]]) - eq("\nE724: unable to correctly dump variable with self-referencing container\nfunction('TestDict', {'tdr': function('TestDict', {E724@1})})", - redir_exec('echo string(d.tdr)')) + eq("Vim(echo):E724: unable to correctly dump variable with self-referencing container", + pcall_err(command, 'echo string(d.tdr)')) end) it('dumps automatically created partials', function() @@ -163,11 +162,8 @@ describe('string() function', function() it('does not crash or halt when dumping partials with reference cycles in self', function() meths.set_var('d', {v=true}) - eq(dedent([[ - - E724: unable to correctly dump variable with self-referencing container - {'p': function('<SNR>1_Test2', {E724@0}), 'f': function('<SNR>1_Test2'), 'v': v:true}]]), - redir_exec('echo string(extend(extend(g:d, {"f": g:Test2_f}), {"p": g:d.f}))')) + eq([[Vim(echo):E724: unable to correctly dump variable with self-referencing container]], + pcall_err(command, 'echo string(extend(extend(g:d, {"f": g:Test2_f}), {"p": g:d.f}))')) end) it('does not show errors when dumping partials referencing the same dictionary', @@ -190,11 +186,8 @@ describe('string() function', function() -- there was error in dumping partials). Tested explicitly in -- test/unit/api/private_helpers_spec.lua. eval('add(l, function("Test1", l))') - eq(dedent([=[ - - E724: unable to correctly dump variable with self-referencing container - function('Test1', [[{E724@2}, function('Test1', [{E724@2}])], function('Test1', [[{E724@4}, function('Test1', [{E724@4}])]])])]=]), - redir_exec('echo string(function("Test1", l))')) + eq([=[Vim(echo):E724: unable to correctly dump variable with self-referencing container]=], + pcall_err(command, 'echo string(function("Test1", l))')) end) it('does not crash or halt when dumping partials with reference cycles in self and arguments', @@ -204,11 +197,8 @@ describe('string() function', function() eval('add(l, l)') eval('add(l, function("Test1", l))') eval('add(l, function("Test1", d))') - eq(dedent([=[ - - E724: unable to correctly dump variable with self-referencing container - {'p': function('<SNR>1_Test2', [[{E724@3}, function('Test1', [{E724@3}]), function('Test1', {E724@0})], function('Test1', [[{E724@5}, function('Test1', [{E724@5}]), function('Test1', {E724@0})]]), function('Test1', {E724@0})], {E724@0}), 'f': function('<SNR>1_Test2'), 'v': v:true}]=]), - redir_exec('echo string(extend(extend(g:d, {"f": g:Test2_f}), {"p": function(g:d.f, l)}))')) + eq([=[Vim(echo):E724: unable to correctly dump variable with self-referencing container]=], + pcall_err(command, 'echo string(extend(extend(g:d, {"f": g:Test2_f}), {"p": function(g:d.f, l)}))')) end) end) @@ -235,10 +225,10 @@ describe('string() function', function() it('dumps recursive lists despite the error', function() meths.set_var('l', {}) eval('add(l, l)') - eq('\nE724: unable to correctly dump variable with self-referencing container\n[{E724@0}]', - redir_exec('echo string(l)')) - eq('\nE724: unable to correctly dump variable with self-referencing container\n[[{E724@1}]]', - redir_exec('echo string([l])')) + eq('Vim(echo):E724: unable to correctly dump variable with self-referencing container', + pcall_err(command, 'echo string(l)')) + eq('Vim(echo):E724: unable to correctly dump variable with self-referencing container', + pcall_err(command, 'echo string([l])')) end) end) @@ -268,10 +258,10 @@ describe('string() function', function() it('dumps recursive dictionaries despite the error', function() meths.set_var('d', {d=1}) eval('extend(d, {"d": d})') - eq('\nE724: unable to correctly dump variable with self-referencing container\n{\'d\': {E724@0}}', - redir_exec('echo string(d)')) - eq('\nE724: unable to correctly dump variable with self-referencing container\n{\'out\': {\'d\': {E724@1}}}', - redir_exec('echo string({"out": d})')) + eq('Vim(echo):E724: unable to correctly dump variable with self-referencing container', + pcall_err(command, 'echo string(d)')) + eq('Vim(echo):E724: unable to correctly dump variable with self-referencing container', + pcall_err(command, 'echo string({"out": d})')) end) end) end) diff --git a/test/functional/vimscript/uniq_spec.lua b/test/functional/vimscript/uniq_spec.lua index 5cdba0a0f6..43ad4a7640 100644 --- a/test/functional/vimscript/uniq_spec.lua +++ b/test/functional/vimscript/uniq_spec.lua @@ -2,10 +2,9 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local clear = helpers.clear -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 before_each(clear) @@ -24,8 +23,7 @@ describe('uniq()', function() return (a:a > a:b) - (a:a < a:b) endfunction ]]) - eq('\nE745: Using a List as a Number\nE882: Uniq compare function failed', - redir_exec('let fl = uniq([0, 0, [], 1, 1], "Cmp")')) - eq({0, {}, 1, 1}, meths.get_var('fl')) + eq('Vim(let):E745: Using a List as a Number', + pcall_err(command, 'let fl = uniq([0, 0, [], 1, 1], "Cmp")')) end) end) diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index 14be8c377c..5f693249a9 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -8,7 +8,8 @@ local meths = helpers.meths local exc_exec = helpers.exc_exec local read_file = helpers.read_file local write_file = helpers.write_file -local redir_exec = helpers.redir_exec +local pcall_err = helpers.pcall_err +local command = helpers.command local fname = 'Xtest-functional-eval-writefile' local dname = fname .. '.d' @@ -106,51 +107,51 @@ describe('writefile()', function() it('shows correct file name when supplied numbers', function() meths.set_current_dir(dname) - eq('\nE482: Can\'t open file 2 for writing: illegal operation on a directory', - redir_exec(('call writefile([42], %s)'):format(ddname_tail))) + eq('Vim(call):E482: Can\'t open file 2 for writing: illegal operation on a directory', + pcall_err(command, ('call writefile([42], %s)'):format(ddname_tail))) end) it('errors out with invalid arguments', function() write_file(fname, 'TEST') - eq('\nE119: Not enough arguments for function: writefile', - redir_exec('call writefile()')) - eq('\nE119: Not enough arguments for function: writefile', - redir_exec('call writefile([])')) - eq('\nE118: Too many arguments for function: writefile', - redir_exec(('call writefile([], "%s", "b", 1)'):format(fname))) + eq('Vim(call):E119: Not enough arguments for function: writefile', + pcall_err(command, 'call writefile()')) + eq('Vim(call):E119: Not enough arguments for function: writefile', + pcall_err(command, 'call writefile([])')) + eq('Vim(call):E118: Too many arguments for function: writefile', + pcall_err(command, ('call writefile([], "%s", "b", 1)'):format(fname))) for _, arg in ipairs({'0', '0.0', 'function("tr")', '{}', '"test"'}) do - eq('\nE475: Invalid argument: writefile() first argument must be a List or a Blob', - redir_exec(('call writefile(%s, "%s", "b")'):format(arg, fname))) + eq('Vim(call):E475: Invalid argument: writefile() first argument must be a List or a Blob', + pcall_err(command, ('call writefile(%s, "%s", "b")'):format(arg, fname))) end for _, args in ipairs({'[], %s, "b"', '[], "' .. fname .. '", %s'}) do - eq('\nE806: using Float as a String', - redir_exec(('call writefile(%s)'):format(args:format('0.0')))) - eq('\nE730: using List as a String', - redir_exec(('call writefile(%s)'):format(args:format('[]')))) - eq('\nE731: using Dictionary as a String', - redir_exec(('call writefile(%s)'):format(args:format('{}')))) - eq('\nE729: using Funcref as a String', - redir_exec(('call writefile(%s)'):format(args:format('function("tr")')))) + eq('Vim(call):E806: using Float as a String', + pcall_err(command, ('call writefile(%s)'):format(args:format('0.0')))) + eq('Vim(call):E730: using List as a String', + pcall_err(command, ('call writefile(%s)'):format(args:format('[]')))) + eq('Vim(call):E731: using Dictionary as a String', + pcall_err(command, ('call writefile(%s)'):format(args:format('{}')))) + eq('Vim(call):E729: using Funcref as a String', + pcall_err(command, ('call writefile(%s)'):format(args:format('function("tr")')))) end - eq('\nE5060: Unknown flag: «»', - redir_exec(('call writefile([], "%s", "bs«»")'):format(fname))) + eq('Vim(call):E5060: Unknown flag: «»', + pcall_err(command, ('call writefile([], "%s", "bs«»")'):format(fname))) eq('TEST', read_file(fname)) end) it('does not write to file if error in list', function() local args = '["tset"] + repeat([%s], 3), "' .. fname .. '"' - eq('\nE805: Expected a Number or a String, Float found', - redir_exec(('call writefile(%s)'):format(args:format('0.0')))) + eq('Vim(call):E805: Expected a Number or a String, Float found', + pcall_err(command, ('call writefile(%s)'):format(args:format('0.0')))) eq(nil, read_file(fname)) write_file(fname, 'TEST') - eq('\nE745: Expected a Number or a String, List found', - redir_exec(('call writefile(%s)'):format(args:format('[]')))) + eq('Vim(call):E745: Expected a Number or a String, List found', + pcall_err(command, ('call writefile(%s)'):format(args:format('[]')))) eq('TEST', read_file(fname)) - eq('\nE728: Expected a Number or a String, Dictionary found', - redir_exec(('call writefile(%s)'):format(args:format('{}')))) + eq('Vim(call):E728: Expected a Number or a String, Dictionary found', + pcall_err(command, ('call writefile(%s)'):format(args:format('{}')))) eq('TEST', read_file(fname)) - eq('\nE703: Expected a Number or a String, Funcref found', - redir_exec(('call writefile(%s)'):format(args:format('function("tr")')))) + eq('Vim(call):E703: Expected a Number or a String, Funcref found', + pcall_err(command, ('call writefile(%s)'):format(args:format('function("tr")')))) eq('TEST', read_file(fname)) end) end) |