Compare commits

...

5 Commits

Author SHA1 Message Date
Bram Moolenaar
f65ed86f6f patch 8.2.2696: Lua test fails with Lua 5.4.3 and later
Problem:    Lua test fails with Lua 5.4.3 and later.
Solution:   Check for different error messages. (Yegappan Lakshmanan,
            closes #8050)
2021-04-03 14:13:33 +02:00
Bram Moolenaar
1e6bbfb560 patch 8.2.2695: cursor position reset with nested autocommands
Problem:    Cursor position reset with nested autocommands.
Solution:   Only check and reset line numbers for not nested autocommands.
            (closes #5820)
2021-04-03 13:19:26 +02:00
Bram Moolenaar
5b8cabfef7 patch 8.2.2694: when 'matchpairs' is empty every character beeps
Problem:    When 'matchpairs' is empty every character beeps. (Marco Hinz)
Solution:   Bail out when no character in 'matchpairs' was found.
            (closes #8053)  Add assert_nobeep().
2021-04-02 18:55:57 +02:00
Bram Moolenaar
dcf29ac87f patch 8.2.2693: Vim9: locked script variable can be changed
Problem:    Vim9: locked script variable can be changed.
Solution:   Check legacy script variable for being locked. (issue #8031)
2021-04-02 14:44:02 +02:00
Bram Moolenaar
f5906aa780 patch 8.2.2692: Vim9: locked script variable can be changed
Problem:    Vim9: locked script variable can be changed.
Solution:   Check for locked value. (closes #8031)
2021-04-02 14:35:15 +02:00
13 changed files with 167 additions and 35 deletions

View File

@@ -2440,6 +2440,7 @@ assert_inrange({lower}, {upper}, {actual} [, {msg}])
Number assert {actual} is inside the range
assert_match({pat}, {text} [, {msg}])
Number assert {pat} matches {text}
assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
assert_notequal({exp}, {act} [, {msg}])
Number assert {exp} is not equal {act}
assert_notmatch({pat}, {text} [, {msg}])

View File

@@ -243,7 +243,8 @@ test_srand_seed([seed]) *test_srand_seed()*
assert_beeps({cmd}) *assert_beeps()*
Run {cmd} and add an error message to |v:errors| if it does
NOT produce a beep or visual bell.
Also see |assert_fails()| and |assert-return|.
Also see |assert_fails()|, |assert_nobeep()| and
|assert-return|.
Can also be used as a |method|: >
GetCmd()->assert_beeps()
@@ -376,6 +377,14 @@ assert_match({pattern}, {actual} [, {msg}])
Can also be used as a |method|: >
getFile()->assert_match('foo.*')
<
assert_nobeep({cmd}) *assert_nobeep()*
Run {cmd} and add an error message to |v:errors| if it
produces a beep or visual bell.
Also see |assert_beeps()|.
Can also be used as a |method|: >
GetCmd()->assert_nobeep()
<
*assert_notequal()*
assert_notequal({expected}, {actual} [, {msg}])

View File

@@ -2116,14 +2116,16 @@ apply_autocmds_group(
ap->last = FALSE;
ap->last = TRUE;
// make sure cursor and topline are valid
check_lnums(TRUE);
if (nesting == 1)
// make sure cursor and topline are valid
check_lnums(TRUE);
do_cmdline(NULL, getnextac, (void *)&patcmd,
DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
// restore cursor and topline, unless they were changed
reset_lnums();
if (nesting == 1)
// restore cursor and topline, unless they were changed
reset_lnums();
#ifdef FEAT_EVAL
if (eap != NULL)

View File

@@ -739,6 +739,8 @@ static funcentry_T global_functions[] =
ret_number_bool, f_assert_inrange},
{"assert_match", 2, 3, FEARG_2, NULL,
ret_number_bool, f_assert_match},
{"assert_nobeep", 1, 2, FEARG_1, NULL,
ret_number_bool, f_assert_nobeep},
{"assert_notequal", 2, 3, FEARG_2, NULL,
ret_number_bool, f_assert_notequal},
{"assert_notmatch", 2, 3, FEARG_2, NULL,

View File

@@ -1,5 +1,6 @@
/* testing.c */
void f_assert_beeps(typval_T *argvars, typval_T *rettv);
void f_assert_nobeep(typval_T *argvars, typval_T *rettv);
void f_assert_equal(typval_T *argvars, typval_T *rettv);
void f_assert_equalfile(typval_T *argvars, typval_T *rettv);
void f_assert_notequal(typval_T *argvars, typval_T *rettv);

View File

@@ -2817,6 +2817,8 @@ showmatch(
if (*p == NUL)
return;
}
if (*p == NUL)
return;
if ((lpos = findmatch(NULL, NUL)) == NULL) // no match, so beep
vim_beep(BO_MATCH);

View File

@@ -12,13 +12,20 @@ endfunc
CheckFeature lua
CheckFeature float
let s:luaver = split(split(luaeval('_VERSION'), ' ')[1], '\.')
" Depending on the lua version, the error messages are different.
let s:luaver = split(split(systemlist('lua -v')[0], ' ')[1], '\.')
let s:major = str2nr(s:luaver[0])
let s:minor = str2nr(s:luaver[1])
if s:major < 5 || (s:major == 5 && s:minor < 3)
let s:lua_53_or_later = 0
else
let s:patch = str2nr(s:luaver[2])
let s:lua_53_or_later = 0
let s:lua_543_or_later = 0
if (s:major == 5 && s:minor >= 3) || s:major > 5
let s:lua_53_or_later = 1
if (s:major == 5
\ && ((s:minor == 4 && s:patch >= 3) || s:minor > 4))
\ || s:major > 5
let s:lua_543_or_later = 1
endif
endif
func TearDown()
@@ -55,10 +62,14 @@ func Test_lua_luado()
" Error cases
call assert_fails('luado string.format()',
\ "[string \"vim chunk\"]:1: bad argument #1 to 'format' (string expected, got no value)")
call assert_fails('luado func()',
\ s:lua_53_or_later
\ ? "[string \"vim chunk\"]:1: attempt to call a nil value (global 'func')"
\ : "[string \"vim chunk\"]:1: attempt to call global 'func' (a nil value)")
if s:lua_543_or_later
let msg = "[string \"vim chunk\"]:1: global 'func' is not callable (a nil value)"
elseif s:lua_53_or_later
let msg = "[string \"vim chunk\"]:1: attempt to call a nil value (global 'func')"
else
let msg = "[string \"vim chunk\"]:1: attempt to call global 'func' (a nil value)"
endif
call assert_fails('luado func()', msg)
call assert_fails('luado error("failed")', "[string \"vim chunk\"]:1: failed")
endfunc
@@ -143,10 +154,14 @@ func Test_lua_window()
" Window 3 does not exist so vim.window(3) should return nil
call assert_equal('nil', luaeval('tostring(vim.window(3))'))
call assert_fails("let n = luaeval('vim.window().xyz()')",
\ s:lua_53_or_later
\ ? "[string \"luaeval\"]:1: attempt to call a nil value (field 'xyz')"
\ : "[string \"luaeval\"]:1: attempt to call field 'xyz' (a nil value)")
if s:lua_543_or_later
let msg = "[string \"luaeval\"]:1: field 'xyz' is not callable (a nil value)"
elseif s:lua_53_or_later
let msg = "[string \"luaeval\"]:1: attempt to call a nil value (field 'xyz')"
else
let msg = "[string \"luaeval\"]:1: attempt to call field 'xyz' (a nil value)"
endif
call assert_fails("let n = luaeval('vim.window().xyz()')", msg)
call assert_fails('lua vim.window().xyz = 1',
\ "[string \"vim chunk\"]:1: invalid window property: `xyz'")
@@ -331,10 +346,14 @@ func Test_lua_buffer_insert()
call assert_equal('4', luaeval('vim.buffer()[4]'))
call assert_equal(v:null, luaeval('vim.buffer()[5]'))
call assert_equal(v:null, luaeval('vim.buffer()[{}]'))
call assert_fails('lua vim.buffer():xyz()',
\ s:lua_53_or_later
\ ? "[string \"vim chunk\"]:1: attempt to call a nil value (method 'xyz')"
\ : "[string \"vim chunk\"]:1: attempt to call method 'xyz' (a nil value)")
if s:lua_543_or_later
let msg = "[string \"vim chunk\"]:1: method 'xyz' is not callable (a nil value)"
elseif s:lua_53_or_later
let msg = "[string \"vim chunk\"]:1: attempt to call a nil value (method 'xyz')"
else
let msg = "[string \"vim chunk\"]:1: attempt to call method 'xyz' (a nil value)"
endif
call assert_fails('lua vim.buffer():xyz()', msg)
call assert_fails('lua vim.buffer()[1] = {}',
\ '[string "vim chunk"]:1: wrong argument to change')
bwipe!
@@ -438,10 +457,14 @@ func Test_lua_list()
lua ll = vim.eval('l')
let x = luaeval("ll[3]")
call assert_equal(v:null, x)
call assert_fails('let x = luaeval("ll:xyz(3)")',
\ s:lua_53_or_later
\ ? "[string \"luaeval\"]:1: attempt to call a nil value (method 'xyz')"
\ : "[string \"luaeval\"]:1: attempt to call method 'xyz' (a nil value)")
if s:lua_543_or_later
let msg = "[string \"luaeval\"]:1: method 'xyz' is not callable (a nil value)"
elseif s:lua_53_or_later
let msg = "[string \"luaeval\"]:1: attempt to call a nil value (method 'xyz')"
else
let msg = "[string \"luaeval\"]:1: attempt to call method 'xyz' (a nil value)"
endif
call assert_fails('let x = luaeval("ll:xyz(3)")', msg)
let y = luaeval("ll[{}]")
call assert_equal(v:null, y)
@@ -467,7 +490,7 @@ func Test_lua_list_table_insert_remove()
throw 'Skipped: Lua version < 5.3'
endif
let l = [1, 2]
let l = [1, 2]
lua t = vim.eval('l')
lua table.insert(t, 10)
lua t[#t + 1] = 20
@@ -625,10 +648,14 @@ func Test_lua_blob()
call assert_equal(2, n)
let n = luaeval('lb[6]')
call assert_equal(v:null, n)
call assert_fails('let x = luaeval("lb:xyz(3)")',
\ s:lua_53_or_later
\ ? "[string \"luaeval\"]:1: attempt to call a nil value (method 'xyz')"
\ : "[string \"luaeval\"]:1: attempt to call method 'xyz' (a nil value)")
if s:lua_543_or_later
let msg = "[string \"luaeval\"]:1: method 'xyz' is not callable (a nil value)"
elseif s:lua_53_or_later
let msg = "[string \"luaeval\"]:1: attempt to call a nil value (method 'xyz')"
else
let msg = "[string \"luaeval\"]:1: attempt to call method 'xyz' (a nil value)"
endif
call assert_fails('let x = luaeval("lb:xyz(3)")', msg)
let y = luaeval("lb[{}]")
call assert_equal(v:null, y)

View File

@@ -2002,5 +2002,32 @@ func Test_terminal_all_ansi_colors()
call delete('Xcolorscript')
endfunc
function On_BufFilePost()
doautocmd <nomodeline> User UserEvent
endfunction
func Test_terminal_nested_autocmd()
new
call setline(1, range(500))
$
let lastline = line('.')
augroup TermTest
autocmd BufFilePost * call On_BufFilePost()
autocmd User UserEvent silent
augroup END
let cmd = Get_cat_123_cmd()
let buf = term_start(cmd, #{term_finish: 'close', hidden: 1})
call assert_equal(lastline, line('.'))
call TermWait(buf)
exe buf . 'bwipe'
call delete('Xtext')
augroup TermTest
au!
augroup END
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -858,6 +858,14 @@ func Test_mps_latin1()
close!
endfunc
func Test_empty_matchpairs()
split
set matchpairs= showmatch
call assert_nobeep('call feedkeys("ax\tx\t\<Esc>", "xt")')
set matchpairs& noshowmatch
bwipe!
endfunc
func Test_mps_error()
let encoding_save = &encoding

View File

@@ -1346,6 +1346,27 @@ def Test_var_declaration_fails()
CheckScriptFailure(lines, 'E741:')
unlet g:constvar
lines =<< trim END
vim9script
var name = 'one'
lockvar name
def SetLocked()
name = 'two'
enddef
SetLocked()
END
CheckScriptFailure(lines, 'E741: Value is locked: name', 1)
lines =<< trim END
let s:legacy = 'one'
lockvar s:legacy
def SetLocked()
s:legacy = 'two'
enddef
call SetLocked()
END
CheckScriptFailure(lines, 'E741: Value is locked: s:legacy', 1)
lines =<< trim END
vim9script
def SetGlobalConst()
@@ -1354,7 +1375,7 @@ def Test_var_declaration_fails()
SetGlobalConst()
g:globConst = 234
END
CheckScriptFailure(lines, 'E741: Value is locked: globConst')
CheckScriptFailure(lines, 'E741: Value is locked: globConst', 1)
unlet g:globConst
lines =<< trim END

View File

@@ -338,7 +338,7 @@ assert_append_cmd_or_arg(garray_T *gap, typval_T *argvars, char_u *cmd)
}
static int
assert_beeps(typval_T *argvars)
assert_beeps(typval_T *argvars, int no_beep)
{
char_u *cmd = tv_get_string_chk(&argvars[0]);
garray_T ga;
@@ -348,10 +348,13 @@ assert_beeps(typval_T *argvars)
suppress_errthrow = TRUE;
emsg_silent = FALSE;
do_cmdline_cmd(cmd);
if (!called_vim_beep)
if (no_beep ? called_vim_beep : !called_vim_beep)
{
prepare_assert_error(&ga);
ga_concat(&ga, (char_u *)"command did not beep: ");
if (no_beep)
ga_concat(&ga, (char_u *)"command did beep: ");
else
ga_concat(&ga, (char_u *)"command did not beep: ");
ga_concat(&ga, cmd);
assert_error(&ga);
ga_clear(&ga);
@@ -369,7 +372,16 @@ assert_beeps(typval_T *argvars)
void
f_assert_beeps(typval_T *argvars, typval_T *rettv)
{
rettv->vval.v_number = assert_beeps(argvars);
rettv->vval.v_number = assert_beeps(argvars, FALSE);
}
/*
* "assert_nobeep(cmd [, error])" function
*/
void
f_assert_nobeep(typval_T *argvars, typval_T *rettv)
{
rettv->vval.v_number = assert_beeps(argvars, TRUE);
}
/*

View File

@@ -750,6 +750,16 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2696,
/**/
2695,
/**/
2694,
/**/
2693,
/**/
2692,
/**/
2691,
/**/

View File

@@ -1942,6 +1942,9 @@ call_def_function(
store_var(name, STACK_TV_BOT(0));
else
{
SOURCING_LNUM = iptr->isn_lnum;
if (var_check_permission(di, name) == FAIL)
goto on_error;
clear_tv(&di->di_tv);
di->di_tv = *STACK_TV_BOT(0);
}
@@ -1958,6 +1961,13 @@ call_def_function(
if (sv == NULL)
goto failed;
--ectx.ec_stack.ga_len;
// "const" and "final" are checked at compile time, locking
// the value needs to be checked here.
SOURCING_LNUM = iptr->isn_lnum;
if (value_check_lock(sv->sv_tv->v_lock, sv->sv_name, FALSE))
goto on_error;
clear_tv(sv->sv_tv);
*sv->sv_tv = *STACK_TV_BOT(0);
}