mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:partial:8.2.1183: assert_fails() checks the last error message
Problem: assert_fails() checks the last error message.
Solution: Check the first error, it is more relevant. Fix all the tests
that rely on the old behavior.
9b7bf9e98f
Skip test_listener.vim, test_textprop.vim, test_viminfo.vim.
Skip test_python2.vim: affected line fails and hasn't been ported.
Skip test_python3.vim: affected lines fail and haven't been ported.
Skip CHECK_LIST_MATERIALIZE.
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
a86295cd5c
commit
8b0c5de4e0
@ -101,8 +101,23 @@ assert_exception({error} [, {msg}]) *assert_exception()*
|
||||
|
||||
assert_fails({cmd} [, {error} [, {msg}]]) *assert_fails()*
|
||||
Run {cmd} and add an error message to |v:errors| if it does
|
||||
NOT produce an error. Also see |assert-return|.
|
||||
When {error} is given it must match in |v:errmsg|.
|
||||
NOT produce an error or when {error} is not found in the
|
||||
error message. Also see |assert-return|.
|
||||
|
||||
When {error} is a string it must be found literally in the
|
||||
first reported error. Most often this will be the error code,
|
||||
including the colon, e.g. "E123:". >
|
||||
assert_fails('bad cmd', 'E987:')
|
||||
<
|
||||
When {error} is a |List| with one or two strings, these are
|
||||
used as patterns. The first pattern is matched against the
|
||||
first reported error: >
|
||||
assert_fails('cmd', ['E987:.*expected bool'])
|
||||
< The second pattern, if present, is matched against the last
|
||||
reported error. To only match the last error use an empty
|
||||
string for the first error: >
|
||||
assert_fails('cmd', ['', 'E987:'])
|
||||
<
|
||||
Note that beeping is not considered an error, and some failing
|
||||
commands only beep. Use |assert_beeps()| for those.
|
||||
|
||||
|
@ -545,7 +545,7 @@ int var_redir_start(char *name, int append)
|
||||
|
||||
// check if we can write to the variable: set it to or append an empty
|
||||
// string
|
||||
int save_emsg = did_emsg;
|
||||
const int called_emsg_before = called_emsg;
|
||||
did_emsg = false;
|
||||
typval_T tv;
|
||||
tv.v_type = VAR_STRING;
|
||||
@ -556,9 +556,7 @@ int var_redir_start(char *name, int append)
|
||||
set_var_lval(redir_lval, redir_endp, &tv, true, false, "=");
|
||||
}
|
||||
clear_lval(redir_lval);
|
||||
int err = did_emsg;
|
||||
did_emsg |= save_emsg;
|
||||
if (err) {
|
||||
if (called_emsg > called_emsg_before) {
|
||||
redir_endp = NULL; // don't store a value, only cleanup
|
||||
var_redir_stop();
|
||||
return FAIL;
|
||||
@ -2185,7 +2183,7 @@ char *get_user_var_name(expand_T *xp, int idx)
|
||||
/// Does not use 'cpo' and always uses 'magic'.
|
||||
///
|
||||
/// @return true if "pat" matches "text".
|
||||
int pattern_match(char *pat, char *text, bool ic)
|
||||
int pattern_match(const char *pat, const char *text, bool ic)
|
||||
{
|
||||
int matches = 0;
|
||||
regmatch_T regmatch;
|
||||
@ -2193,7 +2191,7 @@ int pattern_match(char *pat, char *text, bool ic)
|
||||
// avoid 'l' flag in 'cpoptions'
|
||||
char *save_cpo = p_cpo;
|
||||
p_cpo = empty_option;
|
||||
regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
|
||||
regmatch.regprog = vim_regcomp((char *)pat, RE_MAGIC + RE_STRING);
|
||||
if (regmatch.regprog != NULL) {
|
||||
regmatch.rm_ic = ic;
|
||||
matches = vim_regexec_nl(®match, (char_u *)text, (colnr_T)0);
|
||||
@ -8881,7 +8879,7 @@ int typval_compare(typval_T *typ1, typval_T *typ2, exprtype_T type, bool ic)
|
||||
|
||||
case EXPR_MATCH:
|
||||
case EXPR_NOMATCH:
|
||||
n1 = pattern_match((char *)s2, (char *)s1, ic);
|
||||
n1 = pattern_match(s2, s1, ic);
|
||||
if (type == EXPR_NOMATCH) {
|
||||
n1 = !n1;
|
||||
}
|
||||
|
@ -194,6 +194,10 @@ EXTERN int emsg_skip INIT(= 0); // don't display errors for
|
||||
// expression that is skipped
|
||||
EXTERN bool emsg_severe INIT(= false); // use message of next of several
|
||||
// emsg() calls for throw
|
||||
// used by assert_fails()
|
||||
EXTERN bool emsg_assert_fails_used INIT(= false);
|
||||
EXTERN char *emsg_assert_fails_msg INIT(= NULL);
|
||||
|
||||
EXTERN bool did_endif INIT(= false); // just had ":endif"
|
||||
EXTERN dict_T vimvardict; // Dictionary with v: variables
|
||||
EXTERN dict_T globvardict; // Dictionary with g: variables
|
||||
|
@ -663,6 +663,10 @@ static bool emsg_multiline(const char *s, bool multiline)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (emsg_assert_fails_used && emsg_assert_fails_msg == NULL) {
|
||||
emsg_assert_fails_msg = xstrdup(s);
|
||||
}
|
||||
|
||||
// set "v:errmsg", also when using ":silent! cmd"
|
||||
set_vim_var_string(VV_ERRMSG, s, -1);
|
||||
|
||||
|
@ -122,9 +122,7 @@ endfunc
|
||||
func Test_multibyte()
|
||||
" using an invalid character should not cause a crash
|
||||
set wic
|
||||
" Except on Windows, E472 is also thrown last, but v8.1.1183 isn't ported yet
|
||||
" call assert_fails('tc û<><C3BB><EFBFBD>¦*', has('win32') ? 'E480:' : 'E344:')
|
||||
call assert_fails('tc û<><C3BB><EFBFBD>¦*', has('win32') ? 'E480:' : 'E472:')
|
||||
call assert_fails('tc û<><C3BB><EFBFBD>¦*', has('win32') ? 'E480:' : 'E344:')
|
||||
set nowic
|
||||
endfunc
|
||||
|
||||
|
@ -175,9 +175,7 @@ func Test_autocmd_bufunload_avoiding_SEGV_01()
|
||||
exe 'autocmd BufUnload <buffer> ' . (lastbuf + 1) . 'bwipeout!'
|
||||
augroup END
|
||||
|
||||
" Todo: check for E937 generated first
|
||||
" call assert_fails('edit bb.txt', 'E937:')
|
||||
call assert_fails('edit bb.txt', 'E517:')
|
||||
call assert_fails('edit bb.txt', ['E937:', 'E517:'])
|
||||
|
||||
autocmd! test_autocmd_bufunload
|
||||
augroup! test_autocmd_bufunload
|
||||
@ -2933,7 +2931,7 @@ func Test_BufDelete_changebuf()
|
||||
augroup END
|
||||
let save_cpo = &cpo
|
||||
set cpo+=f
|
||||
call assert_fails('r Xfile', 'E484:')
|
||||
call assert_fails('r Xfile', ['E812:', 'E484:'])
|
||||
call assert_equal('somefile', @%)
|
||||
let &cpo = save_cpo
|
||||
augroup TestAuCmd
|
||||
|
@ -76,7 +76,7 @@ func Test_bunload_with_offset()
|
||||
let caught_E90 = 1
|
||||
endtry
|
||||
call assert_equal(1, caught_E90)
|
||||
call assert_fails('$bunload', 'E515:')
|
||||
call assert_fails('$bunload', 'E90:')
|
||||
endfunc
|
||||
|
||||
" Test for :buffer, :bnext, :bprevious, :brewind, :blast and :bmodified
|
||||
@ -282,7 +282,7 @@ func Test_goto_buf_with_confirm()
|
||||
call assert_equal(1, &modified)
|
||||
call assert_equal('', @%)
|
||||
call feedkeys('y', 'L')
|
||||
call assert_fails('confirm b Xfile', 'E37:')
|
||||
call assert_fails('confirm b Xfile', ['', 'E37:'])
|
||||
call assert_equal(1, &modified)
|
||||
call assert_equal('', @%)
|
||||
call feedkeys('n', 'L')
|
||||
|
@ -5,7 +5,7 @@ source check.vim
|
||||
|
||||
func Test_cd_large_path()
|
||||
" This used to crash with a heap write overflow.
|
||||
call assert_fails('cd ' . repeat('x', 5000), 'E472:')
|
||||
call assert_fails('cd ' . repeat('x', 5000), 'E344:')
|
||||
endfunc
|
||||
|
||||
func Test_cd_up_and_down()
|
||||
@ -45,9 +45,7 @@ func Test_cd_minus()
|
||||
call assert_equal(path, getcwd())
|
||||
|
||||
" Test for :cd - after a failed :cd
|
||||
" v8.2.1183 is not ported yet
|
||||
" call assert_fails('cd /nonexistent', 'E344:')
|
||||
call assert_fails('cd /nonexistent', 'E472:')
|
||||
call assert_fails('cd /nonexistent', 'E344:')
|
||||
call assert_equal(path, getcwd())
|
||||
cd -
|
||||
call assert_equal(path_dotdot, getcwd())
|
||||
@ -103,7 +101,7 @@ func Test_chdir_func()
|
||||
call assert_equal('testdir', fnamemodify(getcwd(1, 1), ':t'))
|
||||
|
||||
" Error case
|
||||
call assert_fails("call chdir('dir-abcd')", 'E472:')
|
||||
call assert_fails("call chdir('dir-abcd')", 'E344:')
|
||||
silent! let d = chdir("dir_abcd")
|
||||
call assert_equal("", d)
|
||||
" Should not crash
|
||||
|
@ -102,7 +102,7 @@ func Test_client_server()
|
||||
call remote_send(v:servername, ":let g:testvar2 = 75\<CR>")
|
||||
call feedkeys('', 'x')
|
||||
call assert_equal(75, g:testvar2)
|
||||
call assert_fails('let v = remote_expr(v:servername, "/2")', 'E449:')
|
||||
call assert_fails('let v = remote_expr(v:servername, "/2")', ['E15:.*/2'])
|
||||
|
||||
call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
|
||||
call assert_equal('got it', g:myserverid->remote_read(2))
|
||||
@ -184,8 +184,8 @@ func Test_client_server()
|
||||
|
||||
call assert_fails('call remote_startserver([])', 'E730:')
|
||||
call assert_fails("let x = remote_peek([])", 'E730:')
|
||||
call assert_fails("let x = remote_read('vim10')", 'E277:')
|
||||
call assert_fails("call server2client('abc', 'xyz')", 'E258:')
|
||||
call assert_fails("let x = remote_read('vim10')", ['E573:.*vim10'])
|
||||
call assert_fails("call server2client('abc', 'xyz')", ['E573:.*abc'])
|
||||
endfunc
|
||||
|
||||
" Uncomment this line to get a debugging log
|
||||
|
@ -1154,7 +1154,7 @@ func Test_cmdline_search_range()
|
||||
call assert_equal('B', getline(2))
|
||||
|
||||
let @/ = 'apple'
|
||||
call assert_fails('\/print', 'E486:')
|
||||
call assert_fails('\/print', ['E486:.*apple'])
|
||||
|
||||
bwipe!
|
||||
endfunc
|
||||
@ -1272,7 +1272,7 @@ func Test_verbosefile()
|
||||
call delete('Xlog')
|
||||
call mkdir('Xdir')
|
||||
if !has('win32') " FIXME: no error on Windows, libuv bug?
|
||||
call assert_fails('set verbosefile=Xdir', 'E474:')
|
||||
call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
|
||||
endif
|
||||
call delete('Xdir', 'd')
|
||||
endfunc
|
||||
@ -1525,7 +1525,7 @@ func Test_cmdwin_jump_to_win()
|
||||
call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
|
||||
new
|
||||
set modified
|
||||
call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', 'E162:')
|
||||
call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
|
||||
close!
|
||||
call feedkeys("q/:close\<CR>", "xt")
|
||||
call assert_equal(1, winnr('$'))
|
||||
@ -1539,13 +1539,7 @@ endfunc
|
||||
|
||||
func Test_cmdwin_tabpage()
|
||||
tabedit
|
||||
" v8.2.1919 isn't ported yet, so E492 is thrown after E11 here.
|
||||
" v8.2.1183 also isn't ported yet, so we also can't assert E11 directly.
|
||||
" For now, assert E11 and E492 separately. When v8.2.1183 is ported, the
|
||||
" assert for E492 will fail and this workaround should be removed.
|
||||
" call assert_fails("silent norm q/g :I\<Esc>", 'E11:')
|
||||
call assert_fails("silent norm q/g ", 'E11:')
|
||||
call assert_fails("silent norm q/g :I\<Esc>", 'E492:')
|
||||
call assert_fails("silent norm q/g :I\<Esc>", 'E11:')
|
||||
tabclose!
|
||||
endfunc
|
||||
|
||||
|
@ -104,7 +104,7 @@ func Test_cpo_C()
|
||||
source Xfile
|
||||
call assert_equal([1, 2], g:l)
|
||||
set cpo+=C
|
||||
call assert_fails('source Xfile', 'E10:')
|
||||
call assert_fails('source Xfile', ['E697:', 'E10:'])
|
||||
call delete('Xfile')
|
||||
let &cpo = save_cpo
|
||||
endfunc
|
||||
|
@ -481,8 +481,8 @@ func Test_redir_cmd()
|
||||
call assert_fails('redir abc', 'E475:')
|
||||
call assert_fails('redir => 1abc', 'E474:')
|
||||
call assert_fails('redir => a b', 'E488:')
|
||||
call assert_fails('redir => abc[1]', 'E475:')
|
||||
let b=0zFF
|
||||
call assert_fails('redir => abc[1]', 'E121:')
|
||||
let b = 0zFF
|
||||
call assert_fails('redir =>> b', 'E734:')
|
||||
unlet b
|
||||
|
||||
|
@ -528,7 +528,7 @@ func Test_setmatches()
|
||||
endif
|
||||
eval set->setmatches()
|
||||
call assert_equal(exp, getmatches())
|
||||
call assert_fails('let m = setmatches([], [])', 'E957:')
|
||||
call assert_fails('let m = setmatches([], [])', 'E745:')
|
||||
endfunc
|
||||
|
||||
func Test_empty_concatenate()
|
||||
|
@ -211,7 +211,7 @@ func Test_str2nr()
|
||||
if has('float')
|
||||
call assert_fails('call str2nr(1.2)', 'E806:')
|
||||
endif
|
||||
call assert_fails('call str2nr(10, [])', 'E474:')
|
||||
call assert_fails('call str2nr(10, [])', 'E745:')
|
||||
endfunc
|
||||
|
||||
func Test_strftime()
|
||||
@ -1728,11 +1728,11 @@ func Test_libcall_libcallnr()
|
||||
call assert_equal(4, 'abcd'->libcallnr(libc, 'strlen'))
|
||||
call assert_equal(char2nr('A'), char2nr('a')->libcallnr(libc, 'toupper'))
|
||||
|
||||
call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", 'E364:')
|
||||
call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", 'E364:')
|
||||
call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", ['', 'E364:'])
|
||||
call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", ['', 'E364:'])
|
||||
|
||||
call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:')
|
||||
call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:')
|
||||
call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", ['', 'E364:'])
|
||||
call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", ['', 'E364:'])
|
||||
endfunc
|
||||
|
||||
sandbox function Fsandbox()
|
||||
|
@ -39,7 +39,7 @@ endfunc
|
||||
func Test_global_error()
|
||||
call assert_fails('g\\a', 'E10:')
|
||||
call assert_fails('g', 'E148:')
|
||||
call assert_fails('g/\(/y', 'E476:')
|
||||
call assert_fails('g/\(/y', 'E54:')
|
||||
endfunc
|
||||
|
||||
" Test for printing lines using :g with different search patterns
|
||||
|
@ -262,7 +262,7 @@ func Test_let_errors()
|
||||
let l = [1, 2, 3]
|
||||
call assert_fails('let l[:] = 5', 'E709:')
|
||||
|
||||
call assert_fails('let x:lnum=5', 'E488:')
|
||||
call assert_fails('let x:lnum=5', ['E121:', 'E488:'])
|
||||
call assert_fails('let v:=5', 'E461:')
|
||||
call assert_fails('let [a]', 'E474:')
|
||||
call assert_fails('let [a, b] = [', 'E697:')
|
||||
|
@ -680,10 +680,10 @@ func Test_reverse_sort_uniq()
|
||||
endif
|
||||
|
||||
call assert_fails('call reverse("")', 'E899:')
|
||||
call assert_fails('call uniq([1, 2], {x, y -> []})', 'E882:')
|
||||
call assert_fails('call uniq([1, 2], {x, y -> []})', 'E745:')
|
||||
call assert_fails("call sort([1, 2], function('min'), 1)", "E715:")
|
||||
call assert_fails("call sort([1, 2], function('invalid_func'))", "E700:")
|
||||
call assert_fails("call sort([1, 2], function('min'))", "E702:")
|
||||
call assert_fails("call sort([1, 2], function('min'))", "E118:")
|
||||
endfunc
|
||||
|
||||
" reduce a list or a blob
|
||||
@ -983,7 +983,7 @@ func Test_listdict_index()
|
||||
call assert_fails('echo d[1:2]', 'E719:')
|
||||
call assert_fails("let v = [4, 6][{-> 1}]", 'E729:')
|
||||
call assert_fails("let v = range(5)[2:[]]", 'E730:')
|
||||
call assert_fails("let v = range(5)[2:{-> 2}(]", 'E116:')
|
||||
call assert_fails("let v = range(5)[2:{-> 2}(]", ['E15:', 'E116:'])
|
||||
call assert_fails("let v = range(5)[2:3", 'E111:')
|
||||
call assert_fails("let l = insert([1,2,3], 4, 10)", 'E684:')
|
||||
call assert_fails("let l = insert([1,2,3], 4, -10)", 'E684:')
|
||||
|
@ -163,7 +163,7 @@ func Test_matchadd_error()
|
||||
" call assert_fails("call matchadd('GroupDoesNotExist', 'X')", 'E28:')
|
||||
call matchadd('GroupDoesNotExist', 'X')
|
||||
call assert_equal([{'group': 'GroupDoesNotExist', 'pattern': 'X', 'priority': 10, 'id': 1206}], getmatches())
|
||||
call assert_fails("call matchadd('Search', '\\(')", 'E475:')
|
||||
call assert_fails("call matchadd('Search', '\\(')", 'E54:')
|
||||
call assert_fails("call matchadd('Search', 'XXX', 1, 123, 1)", 'E715:')
|
||||
call assert_fails("call matchadd('Error', 'XXX', 1, 3)", 'E798:')
|
||||
call assert_fails("call matchadd('Error', 'XXX', 1, 0)", 'E799:')
|
||||
|
@ -6,9 +6,7 @@ source check.vim
|
||||
" Test for matchfuzzy()
|
||||
func Test_matchfuzzy()
|
||||
call assert_fails('call matchfuzzy(10, "abc")', 'E686:')
|
||||
" Needs v8.2.1183; match the final error that's thrown for now
|
||||
" call assert_fails('call matchfuzzy(["abc"], [])', 'E730:')
|
||||
call assert_fails('call matchfuzzy(["abc"], [])', 'E475:')
|
||||
call assert_fails('call matchfuzzy(["abc"], [])', 'E730:')
|
||||
call assert_fails("let x = matchfuzzy(v:_null_list, 'foo')", 'E686:')
|
||||
call assert_fails('call matchfuzzy(["abc"], v:_null_string)', 'E475:')
|
||||
call assert_equal([], matchfuzzy([], 'abc'))
|
||||
@ -75,12 +73,9 @@ func Test_matchfuzzy()
|
||||
call assert_fails("let x = matchfuzzy(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:')
|
||||
call assert_equal([], matchfuzzy(l, 'cam'))
|
||||
" Nvim's callback implementation is different, so E6000 is expected instead,
|
||||
" but we need v8.2.1183 to assert it
|
||||
" call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E921:')
|
||||
" call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E6000:')
|
||||
call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E475:')
|
||||
" call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:')
|
||||
call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E475:')
|
||||
call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E6000:')
|
||||
call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:')
|
||||
call assert_fails("let x = matchfuzzy(l, 'cam', v:_null_dict)", 'E715:')
|
||||
call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : v:_null_string})", 'E475:')
|
||||
" Nvim doesn't have null functions
|
||||
@ -155,12 +150,9 @@ func Test_matchfuzzypos()
|
||||
call assert_fails("let x = matchfuzzypos(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:')
|
||||
call assert_equal([[], [], []], matchfuzzypos(l, 'cam'))
|
||||
" Nvim's callback implementation is different, so E6000 is expected instead,
|
||||
" but we need v8.2.1183 to assert it
|
||||
" call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E921:')
|
||||
" call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E6000:')
|
||||
call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E475:')
|
||||
" call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E730:')
|
||||
call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E475:')
|
||||
call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E6000:')
|
||||
call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E730:')
|
||||
call assert_fails("let x = matchfuzzypos(l, 'cam', v:_null_dict)", 'E715:')
|
||||
call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : v:_null_string})", 'E475:')
|
||||
" Nvim doesn't have null functions
|
||||
|
@ -153,7 +153,7 @@ func Test_menu_errors()
|
||||
call assert_fails('menu Test.Foo.Bar', 'E327:')
|
||||
call assert_fails('cmenu Test.Foo', 'E328:')
|
||||
call assert_fails('emenu x Test.Foo', 'E475:')
|
||||
call assert_fails('emenu Test.Foo.Bar', 'E334:')
|
||||
call assert_fails('emenu Test.Foo.Bar', 'E327:')
|
||||
call assert_fails('menutranslate Test', 'E474:')
|
||||
|
||||
silent! unmenu Foo
|
||||
|
@ -131,9 +131,9 @@ func Test_method_syntax()
|
||||
eval [1, 2, 3]
|
||||
\ ->sort(
|
||||
\ )
|
||||
call assert_fails('eval [1, 2, 3]-> sort()', 'E260:')
|
||||
call assert_fails('eval [1, 2, 3]-> sort()', 'E15:')
|
||||
call assert_fails('eval [1, 2, 3]->sort ()', 'E274:')
|
||||
call assert_fails('eval [1, 2, 3]-> sort ()', 'E260:')
|
||||
call assert_fails('eval [1, 2, 3]-> sort ()', 'E15:')
|
||||
endfunc
|
||||
|
||||
func Test_method_lambda()
|
||||
|
@ -1650,7 +1650,7 @@ func Test_normal23_K()
|
||||
call setline(1, '---')
|
||||
call assert_fails('normal! ggv2lK', 'E349:')
|
||||
call setline(1, ['abc', 'xyz'])
|
||||
call assert_fails("normal! gg2lv2h\<C-]>", 'E426:')
|
||||
call assert_fails("normal! gg2lv2h\<C-]>", 'E433:')
|
||||
call assert_beeps("normal! ggVjK")
|
||||
|
||||
" clean up
|
||||
|
@ -740,7 +740,7 @@ func s:test_xhelpgrep(cchar)
|
||||
" Search for non existing help string
|
||||
call assert_fails('Xhelpgrep a1b2c3', 'E480:')
|
||||
" Invalid regular expression
|
||||
call assert_fails('Xhelpgrep \@<!', 'E480:')
|
||||
call assert_fails('Xhelpgrep \@<!', 'E866:')
|
||||
endfunc
|
||||
|
||||
func Test_helpgrep()
|
||||
@ -4101,8 +4101,8 @@ endfunc
|
||||
|
||||
func Test_lvimgrep_crash2()
|
||||
au BufNewFile x sfind
|
||||
call assert_fails('lvimgrep x x', 'E480:')
|
||||
call assert_fails('lvimgrep x x x', 'E480:')
|
||||
call assert_fails('lvimgrep x x', 'E471:')
|
||||
call assert_fails('lvimgrep x x x', 'E471:')
|
||||
|
||||
au! BufNewFile
|
||||
endfunc
|
||||
|
@ -33,11 +33,11 @@ func Test_Rand()
|
||||
endif
|
||||
call assert_fails('echo srand([1])', 'E745:')
|
||||
call assert_fails('echo rand("burp")', 'E475:')
|
||||
call assert_fails('echo rand([1, 2, 3])', 'E475:')
|
||||
call assert_fails('echo rand([[1], 2, 3, 4])', 'E475:')
|
||||
call assert_fails('echo rand([1, [2], 3, 4])', 'E475:')
|
||||
call assert_fails('echo rand([1, 2, [3], 4])', 'E475:')
|
||||
call assert_fails('echo rand([1, 2, 3, [4]])', 'E475:')
|
||||
call assert_fails('echo rand([1, 2, 3])', 'E730:')
|
||||
call assert_fails('echo rand([[1], 2, 3, 4])', 'E730:')
|
||||
call assert_fails('echo rand([1, [2], 3, 4])', 'E730:')
|
||||
call assert_fails('echo rand([1, 2, [3], 4])', 'E730:')
|
||||
call assert_fails('echo rand([1, 2, 3, [4]])', 'E730:')
|
||||
|
||||
" call test_settime(0)
|
||||
endfunc
|
||||
|
@ -101,7 +101,7 @@ func Test_multi_failure()
|
||||
set re=2
|
||||
call assert_fails('/a**', 'E871:')
|
||||
call assert_fails('/a*\+', 'E871:')
|
||||
call assert_fails('/a\{a}', 'E870:')
|
||||
call assert_fails('/a\{a}', 'E554:')
|
||||
set re=0
|
||||
endfunc
|
||||
|
||||
|
@ -1647,8 +1647,8 @@ func Test_search_with_no_last_pat()
|
||||
call assert_fails(";//p", 'E35:')
|
||||
call assert_fails("??p", 'E35:')
|
||||
call assert_fails(";??p", 'E35:')
|
||||
call assert_fails('g//p', 'E476:')
|
||||
call assert_fails('v//p', 'E476:')
|
||||
call assert_fails('g//p', ['E35:', 'E476:'])
|
||||
call assert_fails('v//p', ['E35:', 'E476:'])
|
||||
call writefile(v:errors, 'Xresult')
|
||||
qall!
|
||||
[SCRIPT]
|
||||
@ -1669,8 +1669,8 @@ func Test_search_tilde_pat()
|
||||
call assert_fails('exe "normal /~\<CR>"', 'E33:')
|
||||
call assert_fails('exe "normal ?~\<CR>"', 'E33:')
|
||||
set regexpengine=2
|
||||
call assert_fails('exe "normal /~\<CR>"', 'E383:')
|
||||
call assert_fails('exe "normal ?~\<CR>"', 'E383:')
|
||||
call assert_fails('exe "normal /~\<CR>"', ['E33:', 'E383:'])
|
||||
call assert_fails('exe "normal ?~\<CR>"', ['E33:', 'E383:'])
|
||||
set regexpengine&
|
||||
call writefile(v:errors, 'Xresult')
|
||||
qall!
|
||||
|
@ -483,13 +483,13 @@ func Test_sign_funcs()
|
||||
call assert_fails('call sign_place(5, "", "sign1", "@", {"lnum" : 10})',
|
||||
\ 'E158:')
|
||||
call assert_fails('call sign_place(5, "", "sign1", [], {"lnum" : 10})',
|
||||
\ 'E158:')
|
||||
\ 'E730:')
|
||||
call assert_fails('call sign_place(21, "", "sign1", "Xsign",
|
||||
\ {"lnum" : -1})', 'E474:')
|
||||
call assert_fails('call sign_place(22, "", "sign1", "Xsign",
|
||||
\ {"lnum" : 0})', 'E474:')
|
||||
call assert_fails('call sign_place(22, "", "sign1", "Xsign",
|
||||
\ {"lnum" : []})', 'E474:')
|
||||
\ {"lnum" : []})', 'E745:')
|
||||
call assert_equal(-1, sign_place(1, "*", "sign1", "Xsign", {"lnum" : 10}))
|
||||
|
||||
" Tests for sign_getplaced()
|
||||
@ -1731,7 +1731,7 @@ func Test_sign_jump_func()
|
||||
call assert_fails("call sign_jump(5, 'g5', 'foo')", 'E157:')
|
||||
call assert_fails('call sign_jump([], "", "foo")', 'E745:')
|
||||
call assert_fails('call sign_jump(2, [], "foo")', 'E730:')
|
||||
call assert_fails('call sign_jump(2, "", {})', 'E158:')
|
||||
call assert_fails('call sign_jump(2, "", {})', 'E731:')
|
||||
call assert_fails('call sign_jump(2, "", "baz")', 'E158:')
|
||||
|
||||
sign unplace * group=*
|
||||
|
@ -495,7 +495,7 @@ func Test_spellsuggest_expr_errors()
|
||||
return [[{}, {}]]
|
||||
endfunc
|
||||
set spellsuggest=expr:MySuggest3()
|
||||
call assert_fails("call spellsuggest('baord')", 'E728:')
|
||||
call assert_fails("call spellsuggest('baord')", 'E731:')
|
||||
|
||||
set nospell spellsuggest&
|
||||
delfunc MySuggest
|
||||
|
@ -446,7 +446,7 @@ func Test_substitute_errors()
|
||||
|
||||
call assert_fails('s/FOO/bar/', 'E486:')
|
||||
call assert_fails('s/foo/bar/@', 'E488:')
|
||||
call assert_fails('s/\(/bar/', 'E476:')
|
||||
call assert_fails('s/\(/bar/', 'E54:')
|
||||
call assert_fails('s afooabara', 'E146:')
|
||||
call assert_fails('s\\a', 'E10:')
|
||||
|
||||
@ -841,9 +841,9 @@ endfunc
|
||||
func Test_sub_with_no_last_pat()
|
||||
let lines =<< trim [SCRIPT]
|
||||
call assert_fails('~', 'E33:')
|
||||
call assert_fails('s//abc/g', 'E476:')
|
||||
call assert_fails('s\/bar', 'E476:')
|
||||
call assert_fails('s\&bar&', 'E476:')
|
||||
call assert_fails('s//abc/g', 'E35:')
|
||||
call assert_fails('s\/bar', 'E35:')
|
||||
call assert_fails('s\&bar&', 'E33:')
|
||||
call writefile(v:errors, 'Xresult')
|
||||
qall!
|
||||
[SCRIPT]
|
||||
|
@ -378,7 +378,7 @@ func Test_syntax_invalid_arg()
|
||||
call assert_fails('syntax sync x', 'E404:')
|
||||
call assert_fails('syntax keyword Abc a[', 'E789:')
|
||||
call assert_fails('syntax keyword Abc a[bc]d', 'E890:')
|
||||
call assert_fails('syntax cluster Abc add=A add=', 'E475:')
|
||||
call assert_fails('syntax cluster Abc add=A add=', 'E406:')
|
||||
|
||||
" Test for too many \z\( and unmatched \z\(
|
||||
" Not able to use assert_fails() here because both E50:/E879: and E475:
|
||||
|
@ -85,7 +85,7 @@ func Test_tagfunc()
|
||||
return v:null
|
||||
endfunc
|
||||
set tags= tfu=NullTagFunc
|
||||
call assert_fails('tag nothing', 'E426')
|
||||
call assert_fails('tag nothing', 'E433')
|
||||
delf NullTagFunc
|
||||
|
||||
bwipe!
|
||||
|
@ -8,7 +8,7 @@ func Test_ptag_with_notagstack()
|
||||
CheckFeature quickfix
|
||||
|
||||
set notagstack
|
||||
call assert_fails('ptag does_not_exist_tag_name', 'E426')
|
||||
call assert_fails('ptag does_not_exist_tag_name', 'E433')
|
||||
set tagstack&vim
|
||||
endfunc
|
||||
|
||||
@ -346,7 +346,7 @@ func Test_tagjump_etags()
|
||||
\ "Xmain.c,64",
|
||||
\ ";;;;\x7f1,0",
|
||||
\ ], 'Xtags')
|
||||
call assert_fails('tag foo', 'E426:')
|
||||
call assert_fails('tag foo', 'E431:')
|
||||
|
||||
call delete('Xtags')
|
||||
call delete('Xtags2')
|
||||
|
@ -84,13 +84,11 @@ func Test_taglist_ctags_etags()
|
||||
endfunc
|
||||
|
||||
func Test_tags_too_long()
|
||||
call assert_fails('tag ' . repeat('x', 1020), 'E426')
|
||||
call assert_fails('tag ' . repeat('x', 1020), ['E433', 'E426'])
|
||||
tags
|
||||
endfunc
|
||||
|
||||
func Test_tagfiles()
|
||||
" Nvim: different default for 'tags'.
|
||||
set tags=./tags,tags
|
||||
call assert_equal([], tagfiles())
|
||||
|
||||
call writefile(["FFoo\tXfoo\t1"], 'Xtags1')
|
||||
|
@ -2000,13 +2000,11 @@ endfunc
|
||||
func Test_try_catch_errors()
|
||||
call assert_fails('throw |', 'E471:')
|
||||
call assert_fails("throw \n ", 'E471:')
|
||||
call assert_fails('catch abc', 'E603:')
|
||||
call assert_fails('catch abc', 'E654:')
|
||||
call assert_fails('try | let i = 1| finally | catch | endtry', 'E604:')
|
||||
call assert_fails('finally', 'E606:')
|
||||
call assert_fails('try | finally | finally | endtry', 'E607:')
|
||||
" v8.2.3486 has been ported, but v8.2.1183 hasn't, so E170 appears here.
|
||||
" call assert_fails('try | for i in range(5) | endif | endtry', 'E580:')
|
||||
call assert_fails('try | for i in range(5) | endif | endtry', 'E170:')
|
||||
call assert_fails('try | for i in range(5) | endif | endtry', 'E580:')
|
||||
call assert_fails('try | while v:true | endtry', 'E170:')
|
||||
call assert_fails('try | if v:true | endtry', 'E171:')
|
||||
endfunc
|
||||
|
@ -21,7 +21,7 @@ func Test_strchars()
|
||||
call assert_equal(exp[i][1], inp[i]->strchars(0))
|
||||
call assert_equal(exp[i][2], strchars(inp[i], 1))
|
||||
endfor
|
||||
call assert_fails("let v=strchars('abc', [])", 'E474:')
|
||||
call assert_fails("let v=strchars('abc', [])", 'E745:')
|
||||
call assert_fails("let v=strchars('abc', 2)", 'E474:')
|
||||
endfunc
|
||||
|
||||
|
@ -115,7 +115,7 @@ func Test_winbuf_close()
|
||||
call assert_equal('Xtest2', bufname('%'))
|
||||
quit!
|
||||
call assert_equal('Xtest3', bufname('%'))
|
||||
call assert_fails('silent! quit!', 'E162')
|
||||
call assert_fails('silent! quit!', 'E37')
|
||||
call assert_equal('Xtest1', bufname('%'))
|
||||
|
||||
call delete('Xtest1')
|
||||
|
@ -325,7 +325,7 @@ func Test_write_autocmd_unloadbuf_lockmark()
|
||||
autocmd BufWritePre Xfile enew | write
|
||||
augroup END
|
||||
e Xfile
|
||||
call assert_fails('lockmarks write', 'E203:')
|
||||
call assert_fails('lockmarks write', ['E32', 'E203:'])
|
||||
augroup WriteTest
|
||||
au!
|
||||
augroup END
|
||||
|
@ -249,8 +249,7 @@ static int assert_match_common(typval_T *argvars, assert_type_T atype)
|
||||
|
||||
if (pat == NULL || text == NULL) {
|
||||
emsg(_(e_invarg));
|
||||
} else if (pattern_match((char *)pat, (char *)text, false)
|
||||
!= (atype == ASSERT_MATCH)) {
|
||||
} else if (pattern_match(pat, text, false) != (atype == ASSERT_MATCH)) {
|
||||
garray_T ga;
|
||||
prepare_assert_error(&ga);
|
||||
fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1], atype);
|
||||
@ -477,11 +476,13 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
garray_T ga;
|
||||
int save_trylevel = trylevel;
|
||||
const int called_emsg_before = called_emsg;
|
||||
bool wrong_arg = false;
|
||||
|
||||
// trylevel must be zero for a ":throw" command to be considered failed
|
||||
trylevel = 0;
|
||||
suppress_errthrow = true;
|
||||
emsg_silent = true;
|
||||
emsg_assert_fails_used = true;
|
||||
|
||||
do_cmdline_cmd(cmd);
|
||||
if (called_emsg == called_emsg_before) {
|
||||
@ -493,13 +494,43 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
rettv->vval.v_number = 1;
|
||||
} else if (argvars[1].v_type != VAR_UNKNOWN) {
|
||||
char buf[NUMBUFLEN];
|
||||
const char *const error = tv_get_string_buf_chk(&argvars[1], buf);
|
||||
const char *expected;
|
||||
bool error_found = false;
|
||||
char *actual = emsg_assert_fails_msg == NULL ? "[unknown]" : emsg_assert_fails_msg;
|
||||
|
||||
if (error == NULL
|
||||
|| strstr(get_vim_var_str(VV_ERRMSG), error) == NULL) {
|
||||
if (argvars[1].v_type == VAR_STRING) {
|
||||
expected = tv_get_string_buf_chk(&argvars[1], buf);
|
||||
error_found = expected == NULL || strstr(actual, expected) == NULL;
|
||||
} else if (argvars[1].v_type == VAR_LIST) {
|
||||
const list_T *const list = argvars[1].vval.v_list;
|
||||
if (list == NULL || tv_list_len(list) < 1 || tv_list_len(list) > 2) {
|
||||
wrong_arg = true;
|
||||
goto theend;
|
||||
}
|
||||
const typval_T *tv = TV_LIST_ITEM_TV(tv_list_first(list));
|
||||
expected = tv_get_string_buf_chk(tv, buf);
|
||||
if (!pattern_match(expected, actual, false)) {
|
||||
error_found = true;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
wrong_arg = true;
|
||||
goto theend;
|
||||
}
|
||||
|
||||
if (error_found) {
|
||||
typval_T actual_tv;
|
||||
actual_tv.v_type = VAR_STRING;
|
||||
actual_tv.vval.v_string = actual;
|
||||
prepare_assert_error(&ga);
|
||||
fill_assert_error(&ga, &argvars[2], NULL, &argvars[1],
|
||||
get_vim_var_tv(VV_ERRMSG), ASSERT_OTHER);
|
||||
&actual_tv, ASSERT_OTHER);
|
||||
ga_concat(&ga, ": ");
|
||||
assert_append_cmd_or_arg(&ga, argvars, cmd);
|
||||
assert_error(&ga);
|
||||
@ -508,11 +539,18 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
}
|
||||
}
|
||||
|
||||
theend:
|
||||
trylevel = save_trylevel;
|
||||
suppress_errthrow = false;
|
||||
emsg_silent = false;
|
||||
emsg_on_display = false;
|
||||
emsg_assert_fails_used = false;
|
||||
XFREE_CLEAR(emsg_assert_fails_msg);
|
||||
set_vim_var_string(VV_ERRMSG, NULL, 0);
|
||||
if (wrong_arg) {
|
||||
emsg(_(
|
||||
"E856: assert_fails() second argument must be a string or a list with one or two strings"));
|
||||
}
|
||||
}
|
||||
|
||||
// "assert_false(actual[, msg])" function
|
||||
|
Loading…
Reference in New Issue
Block a user