mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.1953: Vim9: extra "unknown" error after other error
Problem: Vim9: extra "unknown" error after other error.
Solution: Restore did_emsg count after EXEC instruction. (closes vim/vim#7254)
Improve error message from assert_fails()
631e8f9345
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
d9f0d2da4d
commit
0a3a2132d4
@ -142,7 +142,7 @@ static void ga_concat_shorten_esc(garray_T *gap, const char *str)
|
||||
}
|
||||
|
||||
/// Fill "gap" with information about an assert error.
|
||||
static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char *exp_str,
|
||||
static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *exp_str,
|
||||
typval_T *exp_tv_arg, typval_T *got_tv_arg, assert_type_T atype)
|
||||
{
|
||||
char *tofree;
|
||||
@ -220,7 +220,13 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char *exp_str
|
||||
ga_concat_shorten_esc(gap, tofree);
|
||||
xfree(tofree);
|
||||
} else {
|
||||
if (atype != ASSERT_INRANGE) {
|
||||
ga_concat(gap, "'");
|
||||
}
|
||||
ga_concat_shorten_esc(gap, exp_str);
|
||||
if (atype != ASSERT_INRANGE) {
|
||||
ga_concat(gap, "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (atype != ASSERT_NOTEQUAL) {
|
||||
@ -534,6 +540,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
} else if (argvars[1].v_type != VAR_UNKNOWN) {
|
||||
char buf[NUMBUFLEN];
|
||||
const char *expected;
|
||||
const char *expected_str = NULL;
|
||||
bool error_found = false;
|
||||
int error_found_index = 1;
|
||||
char *actual = emsg_assert_fails_msg == NULL ? "[unknown]" : emsg_assert_fails_msg;
|
||||
@ -551,12 +558,14 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
expected = tv_get_string_buf_chk(tv, buf);
|
||||
if (!pattern_match(expected, actual, false)) {
|
||||
error_found = true;
|
||||
expected_str = expected;
|
||||
} else if (tv_list_len(list) == 2) {
|
||||
tv = TV_LIST_ITEM_TV(tv_list_last(list));
|
||||
actual = get_vim_var_str(VV_ERRMSG);
|
||||
expected = tv_get_string_buf_chk(tv, buf);
|
||||
if (!pattern_match(expected, actual, false)) {
|
||||
error_found = true;
|
||||
expected_str = expected;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -600,7 +609,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
actual_tv.v_type = VAR_STRING;
|
||||
actual_tv.vval.v_string = actual;
|
||||
}
|
||||
fill_assert_error(&ga, &argvars[2], NULL,
|
||||
fill_assert_error(&ga, &argvars[2], expected_str,
|
||||
&argvars[error_found_index], &actual_tv, ASSERT_OTHER);
|
||||
ga_concat(&ga, ": ");
|
||||
assert_append_cmd_or_arg(&ga, argvars, cmd);
|
||||
|
@ -6,11 +6,11 @@ func Test_assert_false()
|
||||
call assert_equal(0, v:false->assert_false())
|
||||
|
||||
call assert_equal(1, assert_false(123))
|
||||
call assert_match("Expected False but got 123", v:errors[0])
|
||||
call assert_match("Expected 'False' but got 123", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
|
||||
call assert_equal(1, 123->assert_false())
|
||||
call assert_match("Expected False but got 123", v:errors[0])
|
||||
call assert_match("Expected 'False' but got 123", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
endfunc
|
||||
|
||||
@ -21,11 +21,11 @@ func Test_assert_true()
|
||||
call assert_equal(0, v:true->assert_true())
|
||||
|
||||
call assert_equal(1, assert_true(0))
|
||||
call assert_match("Expected True but got 0", v:errors[0])
|
||||
call assert_match("Expected 'True' but got 0", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
|
||||
call assert_equal(1, 0->assert_true())
|
||||
call assert_match("Expected True but got 0", v:errors[0])
|
||||
call assert_match("Expected 'True' but got 0", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
endfunc
|
||||
|
||||
@ -228,11 +228,11 @@ func Test_assert_fail_fails()
|
||||
call remove(v:errors, 0)
|
||||
|
||||
call assert_equal(1, assert_fails('xxx', ['E9876']))
|
||||
call assert_match("Expected \\['E9876'\\] but got 'E492:", v:errors[0])
|
||||
call assert_match("Expected 'E9876' but got 'E492:", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
|
||||
call assert_equal(1, assert_fails('xxx', ['E492:', 'E9876']))
|
||||
call assert_match("Expected \\['E492:', 'E9876'\\] but got 'E492:", v:errors[0])
|
||||
call assert_match("Expected 'E9876' but got 'E492:", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
|
||||
call assert_equal(1, assert_fails('echo', '', 'echo command'))
|
||||
|
Loading…
Reference in New Issue
Block a user