Patch 8.2.1631

5 views
Skip to first unread message

Bram Moolenaar

unread,
Sep 6, 2020, 3:48:25 PM9/6/20
to vim...@googlegroups.com

Patch 8.2.1631
Problem: test_fails() does not check the context of the line number.
Solution: Use another argument to specify the context of the line number.
Files: runtime/doc/testing.txt, runtime/doc/eval.txt,
src/testdir/test_vim9_func.vim, src/testing.c, src/globals.h,
src/evalfunc.c, src/message.c


*** ../vim-8.2.1630/runtime/doc/testing.txt 2020-08-18 13:41:47.211350448 +0200
--- runtime/doc/testing.txt 2020-09-06 21:20:42.367778734 +0200
***************
*** 293,299 ****
endtry
<
*assert_fails()*
! assert_fails({cmd} [, {error} [, {msg} [, {lnum}]]])
Run {cmd} and add an error message to |v:errors| if it does
NOT produce an error or when {error} is not found in the
error message. Also see |assert-return|.
--- 293,299 ----
endtry
<
*assert_fails()*
! assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
Run {cmd} and add an error message to |v:errors| if it does
NOT produce an error or when {error} is not found in the
error message. Also see |assert-return|.
***************
*** 320,325 ****
--- 320,329 ----
the line number at which the error was reported. That can be
the line number in a function or in a script.

+ When {context} is present it is used as a pattern and matched
+ against the context (script name or function name) where
+ {lnum} is located in.
+
Note that beeping is not considered an error, and some failing
commands only beep. Use |assert_beeps()| for those.

*** ../vim-8.2.1630/runtime/doc/eval.txt 2020-09-04 16:35:06.421571299 +0200
--- runtime/doc/eval.txt 2020-09-06 21:21:10.607682621 +0200
***************
*** 2347,2353 ****
Number assert file contents are equal
assert_exception({error} [, {msg}])
Number assert {error} is in v:exception
! assert_fails({cmd} [, {error} [, {msg}]])
Number assert {cmd} fails
assert_false({actual} [, {msg}])
Number assert {actual} is false
--- 2361,2367 ----
Number assert file contents are equal
assert_exception({error} [, {msg}])
Number assert {error} is in v:exception
! assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
Number assert {cmd} fails
assert_false({actual} [, {msg}])
Number assert {actual} is false
*** ../vim-8.2.1630/src/testdir/test_vim9_func.vim 2020-09-06 20:06:53.601733711 +0200
--- src/testdir/test_vim9_func.vim 2020-09-06 21:37:16.712769033 +0200
***************
*** 30,36 ****
def Test_return_something()
assert_equal('string', ReturnString())
assert_equal(123, ReturnNumber())
! assert_fails('ReturnGlobal()', 'E1029: Expected number but got string')
enddef

def Test_missing_return()
--- 30,36 ----
def Test_return_something()
assert_equal('string', ReturnString())
assert_equal(123, ReturnNumber())
! assert_fails('ReturnGlobal()', 'E1029: Expected number but got string', '', 1, 'ReturnGlobal')
enddef

def Test_missing_return()
***************
*** 112,118 ****
def Test_call_default_args()
assert_equal('string', MyDefaultArgs())
assert_equal('one', MyDefaultArgs('one'))
! assert_fails('MyDefaultArgs("one", "two")', 'E118:')

assert_equal('test', MyDefaultSecond('test'))
assert_equal('test', MyDefaultSecond('test', true))
--- 112,118 ----
def Test_call_default_args()
assert_equal('string', MyDefaultArgs())
assert_equal('one', MyDefaultArgs('one'))
! assert_fails('MyDefaultArgs("one", "two")', 'E118:', '', 3, 'Test_call_default_args')

assert_equal('test', MyDefaultSecond('test'))
assert_equal('test', MyDefaultSecond('test', true))
***************
*** 139,145 ****
func Test_call_default_args_from_func()
call assert_equal('string', MyDefaultArgs())
call assert_equal('one', MyDefaultArgs('one'))
! call assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
endfunc

def Test_nested_global_function()
--- 139,145 ----
func Test_call_default_args_from_func()
call assert_equal('string', MyDefaultArgs())
call assert_equal('one', MyDefaultArgs('one'))
! call assert_fails('call MyDefaultArgs("one", "two")', 'E118:', '', 3, 'Test_call_default_args_from_func')
endfunc

def Test_nested_global_function()
***************
*** 245,251 ****
enddef

def Test_call_def_varargs()
! assert_fails('MyDefVarargs()', 'E119:')
assert_equal('one,foo', MyDefVarargs('one'))
assert_equal('one,two', MyDefVarargs('one', 'two'))
assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three'))
--- 245,251 ----
enddef

def Test_call_def_varargs()
! assert_fails('MyDefVarargs()', 'E119:', '', 1, 'Test_call_def_varargs')
assert_equal('one,foo', MyDefVarargs('one'))
assert_equal('one,two', MyDefVarargs('one', 'two'))
assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three'))
***************
*** 362,368 ****

def Test_using_var_as_arg()
writefile(['def Func(x: number)', 'let x = 234', 'enddef', 'defcompile'], 'Xdef')
! assert_fails('so Xdef', 'E1006:')
delete('Xdef')
enddef

--- 362,368 ----

def Test_using_var_as_arg()
writefile(['def Func(x: number)', 'let x = 234', 'enddef', 'defcompile'], 'Xdef')
! assert_fails('so Xdef', 'E1006:', '', 1, 'Func')
delete('Xdef')
enddef

***************
*** 388,394 ****

def Test_call_func_defined_later()
assert_equal('one', g:DefinedLater('one'))
! assert_fails('NotDefined("one")', 'E117:')
enddef

func DefinedLater(arg)
--- 388,394 ----

def Test_call_func_defined_later()
assert_equal('one', g:DefinedLater('one'))
! assert_fails('NotDefined("one")', 'E117:', '', 2, 'Test_call_func_defined_later')
enddef

func DefinedLater(arg)
***************
*** 397,404 ****

def Test_call_funcref()
assert_equal(3, g:SomeFunc('abc'))
! assert_fails('NotAFunc()', 'E117:') # comment after call
! assert_fails('g:NotAFunc()', 'E117:')

let lines =<< trim END
vim9script
--- 397,404 ----

def Test_call_funcref()
assert_equal(3, g:SomeFunc('abc'))
! assert_fails('NotAFunc()', 'E117:', '', 2, 'Test_call_funcref') # comment after call
! assert_fails('g:NotAFunc()', 'E117:', '', 3, 'Test_call_funcref')

let lines =<< trim END
vim9script
***************
*** 524,530 ****

def Test_error_in_nested_function()
# Error in called function requires unwinding the call stack.
! assert_fails('FuncWithForwardCall()', 'E1096:')
enddef

def Test_return_type_wrong()
--- 524,530 ----

def Test_error_in_nested_function()
# Error in called function requires unwinding the call stack.
! assert_fails('FuncWithForwardCall()', 'E1096:', 1, 'FuncWithForwardCall')
enddef

def Test_return_type_wrong()
***************
*** 705,711 ****
defcompile
END
writefile(lines, 'Xcall_const.vim')
! assert_fails('source Xcall_const.vim', 'E46:')
delete('Xcall_const.vim')
enddef

--- 705,711 ----
defcompile
END
writefile(lines, 'Xcall_const.vim')
! assert_fails('source Xcall_const.vim', 'E46:', '', 1, 'MyFunc')
delete('Xcall_const.vim')
enddef

***************
*** 736,743 ****
CallGoneSoon()
END
writefile(lines, 'XToDelFunc')
! assert_fails('so XToDelFunc', 'E933:')
! assert_fails('so XToDelFunc', 'E933:')

delete('XToDelFunc')
enddef
--- 736,743 ----
CallGoneSoon()
END
writefile(lines, 'XToDelFunc')
! assert_fails('so XToDelFunc', 'E933:', '', 1, 'CallGoneSoon')
! assert_fails('so XToDelFunc', 'E933:', '', 1, 'CallGoneSoon')

delete('XToDelFunc')
enddef
***************
*** 748,754 ****
writefile(['def Func1(): string', 'return "Func1"', 'enddef'], 'Xdef')
so Xdef
writefile(['def! Func0(): string', 'enddef', 'defcompile'], 'Xdef')
! assert_fails('so Xdef', 'E1027:')
writefile(['def Func2(): string', 'return "Func2"', 'enddef'], 'Xdef')
so Xdef
delete('Xdef')
--- 748,754 ----
writefile(['def Func1(): string', 'return "Func1"', 'enddef'], 'Xdef')
so Xdef
writefile(['def! Func0(): string', 'enddef', 'defcompile'], 'Xdef')
! assert_fails('so Xdef', 'E1027:', '', 1, 'Func0')
writefile(['def Func2(): string', 'return "Func2"', 'enddef'], 'Xdef')
so Xdef
delete('Xdef')
***************
*** 824,830 ****
defcompile
END
call writefile(l, 'Xinvalidarg')
! call assert_fails('so Xinvalidarg', 'E118:')
let l =<< trim END
def! FArgErr(): float
return ceil()
--- 824,830 ----
defcompile
END
call writefile(l, 'Xinvalidarg')
! call assert_fails('so Xinvalidarg', 'E118:', '', 1, 'FArgErr')
let l =<< trim END
def! FArgErr(): float
return ceil()
***************
*** 832,838 ****
defcompile
END
call writefile(l, 'Xinvalidarg')
! call assert_fails('so Xinvalidarg', 'E119:')
call delete('Xinvalidarg')
endfunc

--- 832,838 ----
defcompile
END
call writefile(l, 'Xinvalidarg')
! call assert_fails('so Xinvalidarg', 'E119:', '', 1, 'FArgErr')
call delete('Xinvalidarg')
endfunc

*** ../vim-8.2.1630/src/testing.c 2020-08-18 23:24:09.916049066 +0200
--- src/testing.c 2020-09-06 21:31:31.701755530 +0200
***************
*** 573,579 ****
char_u buf[NUMBUFLEN];
char_u *expected;
int error_found = FALSE;
! int lnum_error_found = FALSE;
char_u *actual = emsg_assert_fails_msg == NULL ? (char_u *)"[unknown]"
: emsg_assert_fails_msg;

--- 573,579 ----
char_u buf[NUMBUFLEN];
char_u *expected;
int error_found = FALSE;
! int error_found_index = 1;
char_u *actual = emsg_assert_fails_msg == NULL ? (char_u *)"[unknown]"
: emsg_assert_fails_msg;

***************
*** 616,627 ****
}

if (!error_found && argvars[2].v_type != VAR_UNKNOWN
! && argvars[3].v_type == VAR_NUMBER
! && argvars[3].vval.v_number >= 0
! && argvars[3].vval.v_number != emsg_assert_fails_lnum)
{
! error_found = TRUE;
! lnum_error_found = TRUE;
}

if (error_found)
--- 616,637 ----
}

if (!error_found && argvars[2].v_type != VAR_UNKNOWN
! && argvars[3].v_type == VAR_NUMBER)
{
! if (argvars[3].vval.v_number >= 0
! && argvars[3].vval.v_number != emsg_assert_fails_lnum)
! {
! error_found = TRUE;
! error_found_index = 3;
! }
! if (!error_found && argvars[4].v_type == VAR_STRING
! && argvars[4].vval.v_string != NULL
! && !pattern_match(argvars[4].vval.v_string,
! emsg_assert_fails_context, FALSE))
! {
! error_found = TRUE;
! error_found_index = 4;
! }
}

if (error_found)
***************
*** 629,647 ****
typval_T actual_tv;

prepare_assert_error(&ga);
! if (lnum_error_found)
{
actual_tv.v_type = VAR_NUMBER;
actual_tv.vval.v_number = emsg_assert_fails_lnum;
}
else
{
actual_tv.v_type = VAR_STRING;
actual_tv.vval.v_string = actual;
}
fill_assert_error(&ga, &argvars[2], NULL,
! &argvars[lnum_error_found ? 3 : 1],
! &actual_tv, ASSERT_OTHER);
ga_concat(&ga, (char_u *)": ");
assert_append_cmd_or_arg(&ga, argvars, cmd);
assert_error(&ga);
--- 639,661 ----
typval_T actual_tv;

prepare_assert_error(&ga);
! if (error_found_index == 3)
{
actual_tv.v_type = VAR_NUMBER;
actual_tv.vval.v_number = emsg_assert_fails_lnum;
}
+ else if (error_found_index == 4)
+ {
+ actual_tv.v_type = VAR_STRING;
+ actual_tv.vval.v_string = emsg_assert_fails_context;
+ }
else
{
actual_tv.v_type = VAR_STRING;
actual_tv.vval.v_string = actual;
}
fill_assert_error(&ga, &argvars[2], NULL,
! &argvars[error_found_index], &actual_tv, ASSERT_OTHER);
ga_concat(&ga, (char_u *)": ");
assert_append_cmd_or_arg(&ga, argvars, cmd);
assert_error(&ga);
*** ../vim-8.2.1630/src/globals.h 2020-09-05 15:48:32.469546692 +0200
--- src/globals.h 2020-09-06 21:21:50.807547595 +0200
***************
*** 224,229 ****
--- 224,230 ----
EXTERN int emsg_assert_fails_used INIT(= FALSE);
EXTERN char_u *emsg_assert_fails_msg INIT(= NULL);
EXTERN long emsg_assert_fails_lnum INIT(= 0);
+ EXTERN char_u *emsg_assert_fails_context INIT(= NULL);

EXTERN int did_endif INIT(= FALSE); // just had ":endif"
#endif
*** ../vim-8.2.1630/src/evalfunc.c 2020-09-06 18:22:47.245500821 +0200
--- src/evalfunc.c 2020-09-06 21:33:07.741477408 +0200
***************
*** 495,501 ****
{"assert_equal", 2, 3, FEARG_2, ret_number, f_assert_equal},
{"assert_equalfile", 2, 3, FEARG_1, ret_number, f_assert_equalfile},
{"assert_exception", 1, 2, 0, ret_number, f_assert_exception},
! {"assert_fails", 1, 4, FEARG_1, ret_number, f_assert_fails},
{"assert_false", 1, 2, FEARG_1, ret_number, f_assert_false},
{"assert_inrange", 3, 4, FEARG_3, ret_number, f_assert_inrange},
{"assert_match", 2, 3, FEARG_2, ret_number, f_assert_match},
--- 495,501 ----
{"assert_equal", 2, 3, FEARG_2, ret_number, f_assert_equal},
{"assert_equalfile", 2, 3, FEARG_1, ret_number, f_assert_equalfile},
{"assert_exception", 1, 2, 0, ret_number, f_assert_exception},
! {"assert_fails", 1, 5, FEARG_1, ret_number, f_assert_fails},
{"assert_false", 1, 2, FEARG_1, ret_number, f_assert_false},
{"assert_inrange", 3, 4, FEARG_3, ret_number, f_assert_inrange},
{"assert_match", 2, 3, FEARG_2, ret_number, f_assert_match},
*** ../vim-8.2.1630/src/message.c 2020-08-18 13:41:47.215350419 +0200
--- src/message.c 2020-09-06 21:32:12.809636074 +0200
***************
*** 658,663 ****
--- 658,666 ----
{
emsg_assert_fails_msg = vim_strsave(s);
emsg_assert_fails_lnum = SOURCING_LNUM;
+ vim_free(emsg_assert_fails_context);
+ emsg_assert_fails_context = vim_strsave(
+ SOURCING_NAME == NULL ? (char_u *)"" : SOURCING_NAME);
}

// set "v:errmsg", also when using ":silent! cmd"
*** ../vim-8.2.1630/src/version.c 2020-09-06 21:12:56.621232486 +0200
--- src/version.c 2020-09-06 21:46:07.027295224 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1631,
/**/

--
When I look deep into your eyes, I see JPEG artifacts.
I can tell by the pixels that we're wrong for each other. (xkcd)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages