mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 14:28:18 +00:00
vim-patch:8.1.0460: assert_fails() message argument #11051
Problem: assert_fails() does not take a message argument
Solution: Add the argument.
1307d1c003
This commit is contained in:

committed by
Justin M. Keyes

parent
d6f658e38f
commit
b3e56957f8
@@ -7076,7 +7076,7 @@ static void f_assert_exception(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
rettv->vval.v_number = assert_exception(argvars);
|
rettv->vval.v_number = assert_exception(argvars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// "assert_fails(cmd [, error])" function
|
/// "assert_fails(cmd [, error [, msg]])" function
|
||||||
static void f_assert_fails(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
static void f_assert_fails(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||||
{
|
{
|
||||||
const char *const cmd = tv_get_string_chk(&argvars[0]);
|
const char *const cmd = tv_get_string_chk(&argvars[0]);
|
||||||
@@ -7094,7 +7094,14 @@ static void f_assert_fails(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
if (!called_emsg) {
|
if (!called_emsg) {
|
||||||
prepare_assert_error(&ga);
|
prepare_assert_error(&ga);
|
||||||
ga_concat(&ga, (const char_u *)"command did not fail: ");
|
ga_concat(&ga, (const char_u *)"command did not fail: ");
|
||||||
ga_concat(&ga, (const char_u *)cmd);
|
if (argvars[1].v_type != VAR_UNKNOWN
|
||||||
|
&& argvars[2].v_type != VAR_UNKNOWN) {
|
||||||
|
char *const tofree = encode_tv2echo(&argvars[2], NULL);
|
||||||
|
ga_concat(&ga, (char_u *)tofree);
|
||||||
|
xfree(tofree);
|
||||||
|
} else {
|
||||||
|
ga_concat(&ga, (const char_u *)cmd);
|
||||||
|
}
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
@@ -30,7 +30,7 @@ return {
|
|||||||
assert_equal={args={2, 3}},
|
assert_equal={args={2, 3}},
|
||||||
assert_equalfile={args=2},
|
assert_equalfile={args=2},
|
||||||
assert_exception={args={1, 2}},
|
assert_exception={args={1, 2}},
|
||||||
assert_fails={args={1, 2}},
|
assert_fails={args={1, 3}},
|
||||||
assert_false={args={1, 2}},
|
assert_false={args={1, 2}},
|
||||||
assert_inrange={args={3, 4}},
|
assert_inrange={args={3, 4}},
|
||||||
assert_match={args={2, 3}},
|
assert_match={args={2, 3}},
|
||||||
|
@@ -3,6 +3,7 @@ local nvim, call = helpers.meths, helpers.call
|
|||||||
local clear, eq = helpers.clear, helpers.eq
|
local clear, eq = helpers.clear, helpers.eq
|
||||||
local source, command = helpers.source, helpers.command
|
local source, command = helpers.source, helpers.command
|
||||||
local exc_exec = helpers.exc_exec
|
local exc_exec = helpers.exc_exec
|
||||||
|
local eval = helpers.eval
|
||||||
|
|
||||||
local function expected_errors(errors)
|
local function expected_errors(errors)
|
||||||
eq(errors, nvim.get_vvar('errors'))
|
eq(errors, nvim.get_vvar('errors'))
|
||||||
@@ -233,20 +234,31 @@ describe('assert function:', function()
|
|||||||
-- assert_fails({cmd}, [, {error}])
|
-- assert_fails({cmd}, [, {error}])
|
||||||
describe('assert_fails', function()
|
describe('assert_fails', function()
|
||||||
it('should change v:errors when error does not match v:errmsg', function()
|
it('should change v:errors when error does not match v:errmsg', function()
|
||||||
command([[call assert_fails('xxx', {})]])
|
eq(1, eval([[assert_fails('xxx', {})]]))
|
||||||
command([[call assert_match("Expected {} but got 'E731:", v:errors[0])]])
|
command([[call assert_match("Expected {} but got 'E731:", v:errors[0])]])
|
||||||
expected_errors({"Expected {} but got 'E731: using Dictionary as a String'"})
|
expected_errors({"Expected {} but got 'E731: using Dictionary as a String'"})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('should not change v:errors when cmd errors', function()
|
it('should not change v:errors when cmd errors', function()
|
||||||
call('assert_fails', 'NonexistentCmd')
|
eq(0, eval([[assert_fails('NonexistentCmd')]]))
|
||||||
expected_empty()
|
expected_empty()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('should change v:errors when cmd succeeds', function()
|
it('should change v:errors when cmd succeeds', function()
|
||||||
call('assert_fails', 'call empty("")')
|
eq(1, eval([[assert_fails('call empty("")', '')]]))
|
||||||
expected_errors({'command did not fail: call empty("")'})
|
expected_errors({'command did not fail: call empty("")'})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('can specify and get a message about what failed', function()
|
||||||
|
eq(1, eval([[assert_fails('xxx', {}, 'stupid')]]))
|
||||||
|
command([[call assert_match("stupid: Expected {} but got 'E731:", v:errors[0])]])
|
||||||
|
expected_errors({"stupid: Expected {} but got 'E731: using Dictionary as a String'"})
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('can specify and get a message even when cmd succeeds', function()
|
||||||
|
eq(1, eval([[assert_fails('echo', '', 'echo command')]]))
|
||||||
|
expected_errors({'command did not fail: echo command'})
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- assert_inrange({lower}, {upper}, {actual}[, {msg}])
|
-- assert_inrange({lower}, {upper}, {actual}[, {msg}])
|
||||||
|
Reference in New Issue
Block a user