mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.0.1770: assert functions don't return anything
Problem: Assert functions don't return anything. Solution: Return non-zero when the assertion fails.
This commit is contained in:
parent
9b25af3620
commit
65a5464985
@ -1,4 +1,4 @@
|
|||||||
*eval.txt* For Vim version 8.0. Last change: 2018 Apr 20
|
*eval.txt* For Vim version 8.0. Last change: 2018 Apr 28
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -1548,10 +1548,12 @@ v:errmsg Last given error message. It's allowed to set this variable.
|
|||||||
: ... handle error
|
: ... handle error
|
||||||
< "errmsg" also works, for backwards compatibility.
|
< "errmsg" also works, for backwards compatibility.
|
||||||
|
|
||||||
*v:errors* *errors-variable*
|
*v:errors* *errors-variable* *assert-return*
|
||||||
v:errors Errors found by assert functions, such as |assert_true()|.
|
v:errors Errors found by assert functions, such as |assert_true()|.
|
||||||
This is a list of strings.
|
This is a list of strings.
|
||||||
The assert functions append an item when an assert fails.
|
The assert functions append an item when an assert fails.
|
||||||
|
The return value indicates this: a one is returned if an item
|
||||||
|
was added to v:errors, otherwise zero is returned.
|
||||||
To remove old results make it empty: >
|
To remove old results make it empty: >
|
||||||
:let v:errors = []
|
:let v:errors = []
|
||||||
< If v:errors is set to anything but a list it is made an empty
|
< If v:errors is set to anything but a list it is made an empty
|
||||||
@ -2020,26 +2022,26 @@ argidx() Number current index in the argument list
|
|||||||
arglistid([{winnr} [, {tabnr}]]) Number argument list id
|
arglistid([{winnr} [, {tabnr}]]) Number argument list id
|
||||||
argv({nr}) String {nr} entry of the argument list
|
argv({nr}) String {nr} entry of the argument list
|
||||||
argv() List the argument list
|
argv() List the argument list
|
||||||
assert_beeps({cmd}) none assert {cmd} causes a beep
|
assert_beeps({cmd}) Number assert {cmd} causes a beep
|
||||||
assert_equal({exp}, {act} [, {msg}])
|
assert_equal({exp}, {act} [, {msg}])
|
||||||
none assert {exp} is equal to {act}
|
Number assert {exp} is equal to {act}
|
||||||
assert_equalfile({fname-one}, {fname-two})
|
assert_equalfile({fname-one}, {fname-two})
|
||||||
none assert file contents is equal
|
Number assert file contents is equal
|
||||||
assert_exception({error} [, {msg}])
|
assert_exception({error} [, {msg}])
|
||||||
none assert {error} is in v:exception
|
Number assert {error} is in v:exception
|
||||||
assert_fails({cmd} [, {error}]) none assert {cmd} fails
|
assert_fails({cmd} [, {error}]) Number assert {cmd} fails
|
||||||
assert_false({actual} [, {msg}])
|
assert_false({actual} [, {msg}])
|
||||||
none assert {actual} is false
|
Number assert {actual} is false
|
||||||
assert_inrange({lower}, {upper}, {actual} [, {msg}])
|
assert_inrange({lower}, {upper}, {actual} [, {msg}])
|
||||||
none assert {actual} is inside the range
|
Number assert {actual} is inside the range
|
||||||
assert_match({pat}, {text} [, {msg}])
|
assert_match({pat}, {text} [, {msg}])
|
||||||
none assert {pat} matches {text}
|
Number assert {pat} matches {text}
|
||||||
assert_notequal({exp}, {act} [, {msg}])
|
assert_notequal({exp}, {act} [, {msg}])
|
||||||
none assert {exp} is not equal {act}
|
Number assert {exp} is not equal {act}
|
||||||
assert_notmatch({pat}, {text} [, {msg}])
|
assert_notmatch({pat}, {text} [, {msg}])
|
||||||
none assert {pat} not matches {text}
|
Number assert {pat} not matches {text}
|
||||||
assert_report({msg}) none report a test failure
|
assert_report({msg}) Number report a test failure
|
||||||
assert_true({actual} [, {msg}]) none assert {actual} is true
|
assert_true({actual} [, {msg}]) Number assert {actual} is true
|
||||||
asin({expr}) Float arc sine of {expr}
|
asin({expr}) Float arc sine of {expr}
|
||||||
atan({expr}) Float arc tangent of {expr}
|
atan({expr}) Float arc tangent of {expr}
|
||||||
atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
|
atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
|
||||||
@ -2593,12 +2595,13 @@ argv([{nr}]) The result is the {nr}th file in the argument list of the
|
|||||||
assert_beeps({cmd}) *assert_beeps()*
|
assert_beeps({cmd}) *assert_beeps()*
|
||||||
Run {cmd} and add an error message to |v:errors| if it does
|
Run {cmd} and add an error message to |v:errors| if it does
|
||||||
NOT produce a beep or visual bell.
|
NOT produce a beep or visual bell.
|
||||||
Also see |assert_fails()|.
|
Also see |assert_fails()| and |assert-return|.
|
||||||
|
|
||||||
*assert_equal()*
|
*assert_equal()*
|
||||||
assert_equal({expected}, {actual} [, {msg}])
|
assert_equal({expected}, {actual} [, {msg}])
|
||||||
When {expected} and {actual} are not equal an error message is
|
When {expected} and {actual} are not equal an error message is
|
||||||
added to |v:errors|.
|
added to |v:errors| and 1 is returned. Otherwise zero is
|
||||||
|
returned |assert-return|.
|
||||||
There is no automatic conversion, the String "4" is different
|
There is no automatic conversion, the String "4" is different
|
||||||
from the Number 4. And the number 4 is different from the
|
from the Number 4. And the number 4 is different from the
|
||||||
Float 4.0. The value of 'ignorecase' is not used here, case
|
Float 4.0. The value of 'ignorecase' is not used here, case
|
||||||
@ -2614,13 +2617,14 @@ assert_equal({expected}, {actual} [, {msg}])
|
|||||||
assert_equalfile({fname-one}, {fname-two})
|
assert_equalfile({fname-one}, {fname-two})
|
||||||
When the files {fname-one} and {fname-two} do not contain
|
When the files {fname-one} and {fname-two} do not contain
|
||||||
exactly the same text an error message is added to |v:errors|.
|
exactly the same text an error message is added to |v:errors|.
|
||||||
|
Also see |assert-return|.
|
||||||
When {fname-one} or {fname-two} does not exist the error will
|
When {fname-one} or {fname-two} does not exist the error will
|
||||||
mention that.
|
mention that.
|
||||||
Mainly useful with |terminal-diff|.
|
Mainly useful with |terminal-diff|.
|
||||||
|
|
||||||
assert_exception({error} [, {msg}]) *assert_exception()*
|
assert_exception({error} [, {msg}]) *assert_exception()*
|
||||||
When v:exception does not contain the string {error} an error
|
When v:exception does not contain the string {error} an error
|
||||||
message is added to |v:errors|.
|
message is added to |v:errors|. Also see |assert-return|.
|
||||||
This can be used to assert that a command throws an exception.
|
This can be used to assert that a command throws an exception.
|
||||||
Using the error number, followed by a colon, avoids problems
|
Using the error number, followed by a colon, avoids problems
|
||||||
with translations: >
|
with translations: >
|
||||||
@ -2633,7 +2637,7 @@ assert_exception({error} [, {msg}]) *assert_exception()*
|
|||||||
|
|
||||||
assert_fails({cmd} [, {error}]) *assert_fails()*
|
assert_fails({cmd} [, {error}]) *assert_fails()*
|
||||||
Run {cmd} and add an error message to |v:errors| if it does
|
Run {cmd} and add an error message to |v:errors| if it does
|
||||||
NOT produce an error.
|
NOT produce an error. Also see |assert-return|.
|
||||||
When {error} is given it must match in |v:errmsg|.
|
When {error} is given it must match in |v:errmsg|.
|
||||||
Note that beeping is not considered an error, and some failing
|
Note that beeping is not considered an error, and some failing
|
||||||
commands only beep. Use |assert_beeps()| for those.
|
commands only beep. Use |assert_beeps()| for those.
|
||||||
@ -2641,6 +2645,7 @@ assert_fails({cmd} [, {error}]) *assert_fails()*
|
|||||||
assert_false({actual} [, {msg}]) *assert_false()*
|
assert_false({actual} [, {msg}]) *assert_false()*
|
||||||
When {actual} is not false an error message is added to
|
When {actual} is not false an error message is added to
|
||||||
|v:errors|, like with |assert_equal()|.
|
|v:errors|, like with |assert_equal()|.
|
||||||
|
Also see |assert-return|.
|
||||||
A value is false when it is zero. When {actual} is not a
|
A value is false when it is zero. When {actual} is not a
|
||||||
number the assert fails.
|
number the assert fails.
|
||||||
When {msg} is omitted an error in the form
|
When {msg} is omitted an error in the form
|
||||||
@ -2649,7 +2654,7 @@ assert_false({actual} [, {msg}]) *assert_false()*
|
|||||||
assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
|
assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
|
||||||
This asserts number values. When {actual} is lower than
|
This asserts number values. When {actual} is lower than
|
||||||
{lower} or higher than {upper} an error message is added to
|
{lower} or higher than {upper} an error message is added to
|
||||||
|v:errors|.
|
|v:errors|. Also see |assert-return|.
|
||||||
When {msg} is omitted an error in the form
|
When {msg} is omitted an error in the form
|
||||||
"Expected range {lower} - {upper}, but got {actual}" is
|
"Expected range {lower} - {upper}, but got {actual}" is
|
||||||
produced.
|
produced.
|
||||||
@ -2657,7 +2662,7 @@ assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
|
|||||||
*assert_match()*
|
*assert_match()*
|
||||||
assert_match({pattern}, {actual} [, {msg}])
|
assert_match({pattern}, {actual} [, {msg}])
|
||||||
When {pattern} does not match {actual} an error message is
|
When {pattern} does not match {actual} an error message is
|
||||||
added to |v:errors|.
|
added to |v:errors|. Also see |assert-return|.
|
||||||
|
|
||||||
{pattern} is used as with |=~|: The matching is always done
|
{pattern} is used as with |=~|: The matching is always done
|
||||||
like 'magic' was set and 'cpoptions' is empty, no matter what
|
like 'magic' was set and 'cpoptions' is empty, no matter what
|
||||||
@ -2678,18 +2683,22 @@ assert_match({pattern}, {actual} [, {msg}])
|
|||||||
assert_notequal({expected}, {actual} [, {msg}])
|
assert_notequal({expected}, {actual} [, {msg}])
|
||||||
The opposite of `assert_equal()`: add an error message to
|
The opposite of `assert_equal()`: add an error message to
|
||||||
|v:errors| when {expected} and {actual} are equal.
|
|v:errors| when {expected} and {actual} are equal.
|
||||||
|
Also see |assert-return|.
|
||||||
|
|
||||||
*assert_notmatch()*
|
*assert_notmatch()*
|
||||||
assert_notmatch({pattern}, {actual} [, {msg}])
|
assert_notmatch({pattern}, {actual} [, {msg}])
|
||||||
The opposite of `assert_match()`: add an error message to
|
The opposite of `assert_match()`: add an error message to
|
||||||
|v:errors| when {pattern} matches {actual}.
|
|v:errors| when {pattern} matches {actual}.
|
||||||
|
Also see |assert-return|.
|
||||||
|
|
||||||
assert_report({msg}) *assert_report()*
|
assert_report({msg}) *assert_report()*
|
||||||
Report a test failure directly, using {msg}.
|
Report a test failure directly, using {msg}.
|
||||||
|
Always returns one.
|
||||||
|
|
||||||
assert_true({actual} [, {msg}]) *assert_true()*
|
assert_true({actual} [, {msg}]) *assert_true()*
|
||||||
When {actual} is not true an error message is added to
|
When {actual} is not true an error message is added to
|
||||||
|v:errors|, like with |assert_equal()|.
|
|v:errors|, like with |assert_equal()|.
|
||||||
|
Also see |assert-return|.
|
||||||
A value is TRUE when it is a non-zero number. When {actual}
|
A value is TRUE when it is a non-zero number. When {actual}
|
||||||
is not a number the assert fails.
|
is not a number the assert fails.
|
||||||
When {msg} is omitted an error in the form "Expected True but
|
When {msg} is omitted an error in the form "Expected True but
|
||||||
@ -5392,10 +5401,11 @@ job_getchannel({job}) *job_getchannel()*
|
|||||||
<
|
<
|
||||||
{only available when compiled with the |+job| feature}
|
{only available when compiled with the |+job| feature}
|
||||||
|
|
||||||
job_info({job}) *job_info()*
|
job_info([{job}]) *job_info()*
|
||||||
Returns a Dictionary with information about {job}:
|
Returns a Dictionary with information about {job}:
|
||||||
"status" what |job_status()| returns
|
"status" what |job_status()| returns
|
||||||
"channel" what |job_getchannel()| returns
|
"channel" what |job_getchannel()| returns
|
||||||
|
"cmd" List of command arguments used to start the job
|
||||||
"process" process ID
|
"process" process ID
|
||||||
"tty_in" terminal input name, empty when none
|
"tty_in" terminal input name, empty when none
|
||||||
"tty_out" terminal output name, empty when none
|
"tty_out" terminal output name, empty when none
|
||||||
@ -5403,6 +5413,8 @@ job_info({job}) *job_info()*
|
|||||||
"exit_cb" function to be called on exit
|
"exit_cb" function to be called on exit
|
||||||
"stoponexit" |job-stoponexit|
|
"stoponexit" |job-stoponexit|
|
||||||
|
|
||||||
|
Without any arguments, returns a List with all Job objects.
|
||||||
|
|
||||||
job_setoptions({job}, {options}) *job_setoptions()*
|
job_setoptions({job}, {options}) *job_setoptions()*
|
||||||
Change options for {job}. Supported are:
|
Change options for {job}. Supported are:
|
||||||
"stoponexit" |job-stoponexit|
|
"stoponexit" |job-stoponexit|
|
||||||
|
46
src/eval.c
46
src/eval.c
@ -8815,7 +8815,7 @@ assert_error(garray_T *gap)
|
|||||||
list_append_string(vimvars[VV_ERRORS].vv_list, gap->ga_data, gap->ga_len);
|
list_append_string(vimvars[VV_ERRORS].vv_list, gap->ga_data, gap->ga_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
assert_equal_common(typval_T *argvars, assert_type_T atype)
|
assert_equal_common(typval_T *argvars, assert_type_T atype)
|
||||||
{
|
{
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
@ -8828,10 +8828,12 @@ assert_equal_common(typval_T *argvars, assert_type_T atype)
|
|||||||
atype);
|
atype);
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
assert_equalfile(typval_T *argvars)
|
assert_equalfile(typval_T *argvars)
|
||||||
{
|
{
|
||||||
char_u buf1[NUMBUFLEN];
|
char_u buf1[NUMBUFLEN];
|
||||||
@ -8843,7 +8845,7 @@ assert_equalfile(typval_T *argvars)
|
|||||||
FILE *fd2;
|
FILE *fd2;
|
||||||
|
|
||||||
if (fname1 == NULL || fname2 == NULL)
|
if (fname1 == NULL || fname2 == NULL)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
IObuff[0] = NUL;
|
IObuff[0] = NUL;
|
||||||
fd1 = mch_fopen((char *)fname1, READBIN);
|
fd1 = mch_fopen((char *)fname1, READBIN);
|
||||||
@ -8897,10 +8899,12 @@ assert_equalfile(typval_T *argvars)
|
|||||||
ga_concat(&ga, IObuff);
|
ga_concat(&ga, IObuff);
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
assert_match_common(typval_T *argvars, assert_type_T atype)
|
assert_match_common(typval_T *argvars, assert_type_T atype)
|
||||||
{
|
{
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
@ -8918,10 +8922,12 @@ assert_match_common(typval_T *argvars, assert_type_T atype)
|
|||||||
atype);
|
atype);
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
assert_inrange(typval_T *argvars)
|
assert_inrange(typval_T *argvars)
|
||||||
{
|
{
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
@ -8934,7 +8940,7 @@ assert_inrange(typval_T *argvars)
|
|||||||
char_u numbuf[NUMBUFLEN];
|
char_u numbuf[NUMBUFLEN];
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
return;
|
return 0;
|
||||||
if (actual < lower || actual > upper)
|
if (actual < lower || actual > upper)
|
||||||
{
|
{
|
||||||
prepare_assert_error(&ga);
|
prepare_assert_error(&ga);
|
||||||
@ -8951,13 +8957,16 @@ assert_inrange(typval_T *argvars)
|
|||||||
}
|
}
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Common for assert_true() and assert_false().
|
* Common for assert_true() and assert_false().
|
||||||
|
* Return non-zero for failure.
|
||||||
*/
|
*/
|
||||||
void
|
int
|
||||||
assert_bool(typval_T *argvars, int isTrue)
|
assert_bool(typval_T *argvars, int isTrue)
|
||||||
{
|
{
|
||||||
int error = FALSE;
|
int error = FALSE;
|
||||||
@ -8965,7 +8974,7 @@ assert_bool(typval_T *argvars, int isTrue)
|
|||||||
|
|
||||||
if (argvars[0].v_type == VAR_SPECIAL
|
if (argvars[0].v_type == VAR_SPECIAL
|
||||||
&& argvars[0].vval.v_number == (isTrue ? VVAL_TRUE : VVAL_FALSE))
|
&& argvars[0].vval.v_number == (isTrue ? VVAL_TRUE : VVAL_FALSE))
|
||||||
return;
|
return 0;
|
||||||
if (argvars[0].v_type != VAR_NUMBER
|
if (argvars[0].v_type != VAR_NUMBER
|
||||||
|| (get_tv_number_chk(&argvars[0], &error) == 0) == isTrue
|
|| (get_tv_number_chk(&argvars[0], &error) == 0) == isTrue
|
||||||
|| error)
|
|| error)
|
||||||
@ -8976,10 +8985,12 @@ assert_bool(typval_T *argvars, int isTrue)
|
|||||||
NULL, &argvars[0], ASSERT_OTHER);
|
NULL, &argvars[0], ASSERT_OTHER);
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
assert_report(typval_T *argvars)
|
assert_report(typval_T *argvars)
|
||||||
{
|
{
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
@ -8988,9 +8999,10 @@ assert_report(typval_T *argvars)
|
|||||||
ga_concat(&ga, get_tv_string(&argvars[0]));
|
ga_concat(&ga, get_tv_string(&argvars[0]));
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
assert_exception(typval_T *argvars)
|
assert_exception(typval_T *argvars)
|
||||||
{
|
{
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
@ -9002,6 +9014,7 @@ assert_exception(typval_T *argvars)
|
|||||||
ga_concat(&ga, (char_u *)"v:exception is not set");
|
ga_concat(&ga, (char_u *)"v:exception is not set");
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else if (error != NULL
|
else if (error != NULL
|
||||||
&& strstr((char *)vimvars[VV_EXCEPTION].vv_str, (char *)error) == NULL)
|
&& strstr((char *)vimvars[VV_EXCEPTION].vv_str, (char *)error) == NULL)
|
||||||
@ -9011,14 +9024,17 @@ assert_exception(typval_T *argvars)
|
|||||||
&vimvars[VV_EXCEPTION].vv_tv, ASSERT_OTHER);
|
&vimvars[VV_EXCEPTION].vv_tv, ASSERT_OTHER);
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
assert_beeps(typval_T *argvars)
|
assert_beeps(typval_T *argvars)
|
||||||
{
|
{
|
||||||
char_u *cmd = get_tv_string_chk(&argvars[0]);
|
char_u *cmd = get_tv_string_chk(&argvars[0]);
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
called_vim_beep = FALSE;
|
called_vim_beep = FALSE;
|
||||||
suppress_errthrow = TRUE;
|
suppress_errthrow = TRUE;
|
||||||
@ -9031,17 +9047,20 @@ assert_beeps(typval_T *argvars)
|
|||||||
ga_concat(&ga, cmd);
|
ga_concat(&ga, cmd);
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
suppress_errthrow = FALSE;
|
suppress_errthrow = FALSE;
|
||||||
emsg_on_display = FALSE;
|
emsg_on_display = FALSE;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
assert_fails(typval_T *argvars)
|
assert_fails(typval_T *argvars)
|
||||||
{
|
{
|
||||||
char_u *cmd = get_tv_string_chk(&argvars[0]);
|
char_u *cmd = get_tv_string_chk(&argvars[0]);
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
called_emsg = FALSE;
|
called_emsg = FALSE;
|
||||||
suppress_errthrow = TRUE;
|
suppress_errthrow = TRUE;
|
||||||
@ -9054,6 +9073,7 @@ assert_fails(typval_T *argvars)
|
|||||||
ga_concat(&ga, cmd);
|
ga_concat(&ga, cmd);
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
ret = 1;
|
||||||
}
|
}
|
||||||
else if (argvars[1].v_type != VAR_UNKNOWN)
|
else if (argvars[1].v_type != VAR_UNKNOWN)
|
||||||
{
|
{
|
||||||
@ -9068,6 +9088,7 @@ assert_fails(typval_T *argvars)
|
|||||||
&vimvars[VV_ERRMSG].vv_tv, ASSERT_OTHER);
|
&vimvars[VV_ERRMSG].vv_tv, ASSERT_OTHER);
|
||||||
assert_error(&ga);
|
assert_error(&ga);
|
||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
|
ret = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9076,6 +9097,7 @@ assert_fails(typval_T *argvars)
|
|||||||
emsg_silent = FALSE;
|
emsg_silent = FALSE;
|
||||||
emsg_on_display = FALSE;
|
emsg_on_display = FALSE;
|
||||||
set_vim_var_string(VV_ERRMSG, NULL, 0);
|
set_vim_var_string(VV_ERRMSG, NULL, 0);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1300,108 +1300,108 @@ f_argv(typval_T *argvars, typval_T *rettv)
|
|||||||
* "assert_beeps(cmd [, error])" function
|
* "assert_beeps(cmd [, error])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_beeps(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_beeps(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_beeps(argvars);
|
rettv->vval.v_number = assert_beeps(argvars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_equal(expected, actual[, msg])" function
|
* "assert_equal(expected, actual[, msg])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_equal(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_equal(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_equal_common(argvars, ASSERT_EQUAL);
|
rettv->vval.v_number = assert_equal_common(argvars, ASSERT_EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_equalfile(fname-one, fname-two)" function
|
* "assert_equalfile(fname-one, fname-two)" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_equalfile(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_equalfile(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_equalfile(argvars);
|
rettv->vval.v_number = assert_equalfile(argvars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_notequal(expected, actual[, msg])" function
|
* "assert_notequal(expected, actual[, msg])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_notequal(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_notequal(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_equal_common(argvars, ASSERT_NOTEQUAL);
|
rettv->vval.v_number = assert_equal_common(argvars, ASSERT_NOTEQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_exception(string[, msg])" function
|
* "assert_exception(string[, msg])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_exception(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_exception(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_exception(argvars);
|
rettv->vval.v_number = assert_exception(argvars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_fails(cmd [, error])" function
|
* "assert_fails(cmd [, error])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_fails(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_fails(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_fails(argvars);
|
rettv->vval.v_number = assert_fails(argvars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_false(actual[, msg])" function
|
* "assert_false(actual[, msg])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_false(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_false(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_bool(argvars, FALSE);
|
rettv->vval.v_number = assert_bool(argvars, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_inrange(lower, upper[, msg])" function
|
* "assert_inrange(lower, upper[, msg])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_inrange(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_inrange(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_inrange(argvars);
|
rettv->vval.v_number = assert_inrange(argvars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_match(pattern, actual[, msg])" function
|
* "assert_match(pattern, actual[, msg])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_match(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_match(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_match_common(argvars, ASSERT_MATCH);
|
rettv->vval.v_number = assert_match_common(argvars, ASSERT_MATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_notmatch(pattern, actual[, msg])" function
|
* "assert_notmatch(pattern, actual[, msg])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_notmatch(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_notmatch(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_match_common(argvars, ASSERT_NOTMATCH);
|
rettv->vval.v_number = assert_match_common(argvars, ASSERT_NOTMATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_report(msg)" function
|
* "assert_report(msg)" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_report(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_report(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_report(argvars);
|
rettv->vval.v_number = assert_report(argvars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "assert_true(actual[, msg])" function
|
* "assert_true(actual[, msg])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_assert_true(typval_T *argvars, typval_T *rettv UNUSED)
|
f_assert_true(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
assert_bool(argvars, TRUE);
|
rettv->vval.v_number = assert_bool(argvars, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEAT_FLOAT
|
#ifdef FEAT_FLOAT
|
||||||
|
@ -121,15 +121,15 @@ void last_set_msg(scid_T scriptID);
|
|||||||
void reset_v_option_vars(void);
|
void reset_v_option_vars(void);
|
||||||
void prepare_assert_error(garray_T *gap);
|
void prepare_assert_error(garray_T *gap);
|
||||||
void assert_error(garray_T *gap);
|
void assert_error(garray_T *gap);
|
||||||
void assert_equal_common(typval_T *argvars, assert_type_T atype);
|
int assert_equal_common(typval_T *argvars, assert_type_T atype);
|
||||||
void assert_equalfile(typval_T *argvars);
|
int assert_equalfile(typval_T *argvars);
|
||||||
void assert_match_common(typval_T *argvars, assert_type_T atype);
|
int assert_match_common(typval_T *argvars, assert_type_T atype);
|
||||||
void assert_inrange(typval_T *argvars);
|
int assert_inrange(typval_T *argvars);
|
||||||
void assert_bool(typval_T *argvars, int isTrue);
|
int assert_bool(typval_T *argvars, int isTrue);
|
||||||
void assert_report(typval_T *argvars);
|
int assert_report(typval_T *argvars);
|
||||||
void assert_exception(typval_T *argvars);
|
int assert_exception(typval_T *argvars);
|
||||||
void assert_beeps(typval_T *argvars);
|
int assert_beeps(typval_T *argvars);
|
||||||
void assert_fails(typval_T *argvars);
|
int assert_fails(typval_T *argvars);
|
||||||
void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, typval_T *exp_tv, typval_T *got_tv, assert_type_T atype);
|
void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, typval_T *exp_tv, typval_T *got_tv, assert_type_T atype);
|
||||||
int typval_compare(typval_T *typ1, typval_T *typ2, exptype_T type, int type_is, int ic);
|
int typval_compare(typval_T *typ1, typval_T *typ2, exptype_T type, int type_is, int ic);
|
||||||
char_u *typval_tostring(typval_T *arg);
|
char_u *typval_tostring(typval_T *arg);
|
||||||
|
@ -1,58 +1,66 @@
|
|||||||
" Test that the methods used for testing work.
|
" Test that the methods used for testing work.
|
||||||
|
|
||||||
func Test_assert_false()
|
func Test_assert_false()
|
||||||
call assert_false(0)
|
call assert_equal(0, assert_false(0))
|
||||||
call assert_false(v:false)
|
call assert_equal(0, assert_false(v:false))
|
||||||
|
|
||||||
|
call assert_equal(1, assert_false(123))
|
||||||
|
call assert_match("Expected False but got 123", v:errors[0])
|
||||||
|
call remove(v:errors, 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_assert_true()
|
func Test_assert_true()
|
||||||
call assert_true(1)
|
call assert_equal(0, assert_true(1))
|
||||||
call assert_true(123)
|
call assert_equal(0, assert_true(123))
|
||||||
call assert_true(v:true)
|
call assert_equal(0, assert_true(v:true))
|
||||||
|
|
||||||
|
call assert_equal(1, assert_true(0))
|
||||||
|
call assert_match("Expected True but got 0", v:errors[0])
|
||||||
|
call remove(v:errors, 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_assert_equal()
|
func Test_assert_equal()
|
||||||
let s = 'foo'
|
let s = 'foo'
|
||||||
call assert_equal('foo', s)
|
call assert_equal(0, assert_equal('foo', s))
|
||||||
let n = 4
|
let n = 4
|
||||||
call assert_equal(4, n)
|
call assert_equal(0, assert_equal(4, n))
|
||||||
let l = [1, 2, 3]
|
let l = [1, 2, 3]
|
||||||
call assert_equal([1, 2, 3], l)
|
call assert_equal(0, assert_equal([1, 2, 3], l))
|
||||||
|
|
||||||
let s = 'foo'
|
let s = 'foo'
|
||||||
call assert_equal('bar', s)
|
call assert_equal(1, assert_equal('bar', s))
|
||||||
call assert_match("Expected 'bar' but got 'foo'", v:errors[0])
|
call assert_match("Expected 'bar' but got 'foo'", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_assert_equalfile()
|
func Test_assert_equalfile()
|
||||||
call assert_equalfile('abcabc', 'xyzxyz')
|
call assert_equal(1, assert_equalfile('abcabc', 'xyzxyz'))
|
||||||
call assert_match("E485: Can't read file abcabc", v:errors[0])
|
call assert_match("E485: Can't read file abcabc", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
|
|
||||||
let goodtext = ["one", "two", "three"]
|
let goodtext = ["one", "two", "three"]
|
||||||
call writefile(goodtext, 'Xone')
|
call writefile(goodtext, 'Xone')
|
||||||
call assert_equalfile('Xone', 'xyzxyz')
|
call assert_equal(1, assert_equalfile('Xone', 'xyzxyz'))
|
||||||
call assert_match("E485: Can't read file xyzxyz", v:errors[0])
|
call assert_match("E485: Can't read file xyzxyz", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
|
|
||||||
call writefile(goodtext, 'Xtwo')
|
call writefile(goodtext, 'Xtwo')
|
||||||
call assert_equalfile('Xone', 'Xtwo')
|
call assert_equal(0, assert_equalfile('Xone', 'Xtwo'))
|
||||||
|
|
||||||
call writefile([goodtext[0]], 'Xone')
|
call writefile([goodtext[0]], 'Xone')
|
||||||
call assert_equalfile('Xone', 'Xtwo')
|
call assert_equal(1, assert_equalfile('Xone', 'Xtwo'))
|
||||||
call assert_match("first file is shorter", v:errors[0])
|
call assert_match("first file is shorter", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
|
|
||||||
call writefile(goodtext, 'Xone')
|
call writefile(goodtext, 'Xone')
|
||||||
call writefile([goodtext[0]], 'Xtwo')
|
call writefile([goodtext[0]], 'Xtwo')
|
||||||
call assert_equalfile('Xone', 'Xtwo')
|
call assert_equal(1, assert_equalfile('Xone', 'Xtwo'))
|
||||||
call assert_match("second file is shorter", v:errors[0])
|
call assert_match("second file is shorter", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
|
|
||||||
call writefile(['1234X89'], 'Xone')
|
call writefile(['1234X89'], 'Xone')
|
||||||
call writefile(['1234Y89'], 'Xtwo')
|
call writefile(['1234Y89'], 'Xtwo')
|
||||||
call assert_equalfile('Xone', 'Xtwo')
|
call assert_equal(1, assert_equalfile('Xone', 'Xtwo'))
|
||||||
call assert_match("difference at byte 4", v:errors[0])
|
call assert_match("difference at byte 4", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
|
|
||||||
@ -62,17 +70,17 @@ endfunc
|
|||||||
|
|
||||||
func Test_assert_notequal()
|
func Test_assert_notequal()
|
||||||
let n = 4
|
let n = 4
|
||||||
call assert_notequal('foo', n)
|
call assert_equal(0, assert_notequal('foo', n))
|
||||||
let s = 'foo'
|
let s = 'foo'
|
||||||
call assert_notequal([1, 2, 3], s)
|
call assert_equal(0, assert_notequal([1, 2, 3], s))
|
||||||
|
|
||||||
call assert_notequal('foo', s)
|
call assert_equal(1, assert_notequal('foo', s))
|
||||||
call assert_match("Expected not equal to 'foo'", v:errors[0])
|
call assert_match("Expected not equal to 'foo'", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_assert_report()
|
func Test_assert_report()
|
||||||
call assert_report('something is wrong')
|
call assert_equal(1, assert_report('something is wrong'))
|
||||||
call assert_match('something is wrong', v:errors[0])
|
call assert_match('something is wrong', v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
endfunc
|
endfunc
|
||||||
@ -81,7 +89,7 @@ func Test_assert_exception()
|
|||||||
try
|
try
|
||||||
nocommand
|
nocommand
|
||||||
catch
|
catch
|
||||||
call assert_exception('E492:')
|
call assert_equal(0, assert_exception('E492:'))
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -89,9 +97,9 @@ func Test_assert_exception()
|
|||||||
catch
|
catch
|
||||||
try
|
try
|
||||||
" illegal argument, get NULL for error
|
" illegal argument, get NULL for error
|
||||||
call assert_exception([])
|
call assert_equal(1, assert_exception([]))
|
||||||
catch
|
catch
|
||||||
call assert_exception('E730:')
|
call assert_equal(0, assert_exception('E730:'))
|
||||||
endtry
|
endtry
|
||||||
endtry
|
endtry
|
||||||
endfunc
|
endfunc
|
||||||
@ -113,59 +121,59 @@ func Test_compare_fail()
|
|||||||
try
|
try
|
||||||
call assert_equal(s:w, '')
|
call assert_equal(s:w, '')
|
||||||
catch
|
catch
|
||||||
call assert_exception('E724:')
|
call assert_equal(0, assert_exception('E724:'))
|
||||||
call assert_match("Expected NULL but got ''", v:errors[0])
|
call assert_match("Expected NULL but got ''", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
endtry
|
endtry
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_match()
|
func Test_match()
|
||||||
call assert_match('^f.*b.*r$', 'foobar')
|
call assert_equal(0, assert_match('^f.*b.*r$', 'foobar'))
|
||||||
|
|
||||||
call assert_match('bar.*foo', 'foobar')
|
call assert_equal(1, assert_match('bar.*foo', 'foobar'))
|
||||||
call assert_match("Pattern 'bar.*foo' does not match 'foobar'", v:errors[0])
|
call assert_match("Pattern 'bar.*foo' does not match 'foobar'", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
|
|
||||||
call assert_match('bar.*foo', 'foobar', 'wrong')
|
call assert_equal(1, assert_match('bar.*foo', 'foobar', 'wrong'))
|
||||||
call assert_match('wrong', v:errors[0])
|
call assert_match('wrong', v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_notmatch()
|
func Test_notmatch()
|
||||||
call assert_notmatch('foo', 'bar')
|
call assert_equal(0, assert_notmatch('foo', 'bar'))
|
||||||
call assert_notmatch('^foobar$', 'foobars')
|
call assert_equal(0, assert_notmatch('^foobar$', 'foobars'))
|
||||||
|
|
||||||
call assert_notmatch('foo', 'foobar')
|
call assert_equal(1, assert_notmatch('foo', 'foobar'))
|
||||||
call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0])
|
call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_assert_fail_fails()
|
func Test_assert_fail_fails()
|
||||||
call assert_fails('xxx', {})
|
call assert_equal(1, assert_fails('xxx', {}))
|
||||||
call assert_match("Expected {} but got 'E731:", v:errors[0])
|
call assert_match("Expected {} but got 'E731:", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_assert_beeps()
|
func Test_assert_beeps()
|
||||||
new
|
new
|
||||||
call assert_beeps('normal h')
|
call assert_equal(0, assert_beeps('normal h'))
|
||||||
|
|
||||||
call assert_beeps('normal 0')
|
call assert_equal(1, assert_beeps('normal 0'))
|
||||||
call assert_match("command did not beep: normal 0", v:errors[0])
|
call assert_match("command did not beep: normal 0", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
bwipe
|
bwipe
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_assert_inrange()
|
func Test_assert_inrange()
|
||||||
call assert_inrange(7, 7, 7)
|
call assert_equal(0, assert_inrange(7, 7, 7))
|
||||||
call assert_inrange(5, 7, 5)
|
call assert_equal(0, assert_inrange(5, 7, 5))
|
||||||
call assert_inrange(5, 7, 6)
|
call assert_equal(0, assert_inrange(5, 7, 6))
|
||||||
call assert_inrange(5, 7, 7)
|
call assert_equal(0, assert_inrange(5, 7, 7))
|
||||||
|
|
||||||
call assert_inrange(5, 7, 4)
|
call assert_equal(1, assert_inrange(5, 7, 4))
|
||||||
call assert_match("Expected range 5 - 7, but got 4", v:errors[0])
|
call assert_match("Expected range 5 - 7, but got 4", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
call assert_inrange(5, 7, 8)
|
call assert_equal(1, assert_inrange(5, 7, 8))
|
||||||
call assert_match("Expected range 5 - 7, but got 8", v:errors[0])
|
call assert_match("Expected range 5 - 7, but got 8", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
|
|
||||||
|
@ -761,6 +761,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1770,
|
||||||
/**/
|
/**/
|
||||||
1769,
|
1769,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user