Mercurial > vim
comparison runtime/doc/eval.txt @ 13796:87012d2b17b5 v8.0.1770
patch 8.0.1770: assert functions don't return anything
commit https://github.com/vim/vim/commit/65a5464985f980d2bbbf4e14d39d416dce065ec7
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 28 16:56:53 2018 +0200
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.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 28 Apr 2018 17:00:06 +0200 |
parents | f309afff6f25 |
children | 28ac7914b2b6 |
comparison
equal
deleted
inserted
replaced
13795:d3f0d82cf9ec | 13796:87012d2b17b5 |
---|---|
1 *eval.txt* For Vim version 8.0. Last change: 2018 Apr 20 | 1 *eval.txt* For Vim version 8.0. Last change: 2018 Apr 28 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
1546 :silent! next | 1546 :silent! next |
1547 :if v:errmsg != "" | 1547 :if v:errmsg != "" |
1548 : ... handle error | 1548 : ... handle error |
1549 < "errmsg" also works, for backwards compatibility. | 1549 < "errmsg" also works, for backwards compatibility. |
1550 | 1550 |
1551 *v:errors* *errors-variable* | 1551 *v:errors* *errors-variable* *assert-return* |
1552 v:errors Errors found by assert functions, such as |assert_true()|. | 1552 v:errors Errors found by assert functions, such as |assert_true()|. |
1553 This is a list of strings. | 1553 This is a list of strings. |
1554 The assert functions append an item when an assert fails. | 1554 The assert functions append an item when an assert fails. |
1555 The return value indicates this: a one is returned if an item | |
1556 was added to v:errors, otherwise zero is returned. | |
1555 To remove old results make it empty: > | 1557 To remove old results make it empty: > |
1556 :let v:errors = [] | 1558 :let v:errors = [] |
1557 < If v:errors is set to anything but a list it is made an empty | 1559 < If v:errors is set to anything but a list it is made an empty |
1558 list by the assert function. | 1560 list by the assert function. |
1559 | 1561 |
2018 argc() Number number of files in the argument list | 2020 argc() Number number of files in the argument list |
2019 argidx() Number current index in the argument list | 2021 argidx() Number current index in the argument list |
2020 arglistid([{winnr} [, {tabnr}]]) Number argument list id | 2022 arglistid([{winnr} [, {tabnr}]]) Number argument list id |
2021 argv({nr}) String {nr} entry of the argument list | 2023 argv({nr}) String {nr} entry of the argument list |
2022 argv() List the argument list | 2024 argv() List the argument list |
2023 assert_beeps({cmd}) none assert {cmd} causes a beep | 2025 assert_beeps({cmd}) Number assert {cmd} causes a beep |
2024 assert_equal({exp}, {act} [, {msg}]) | 2026 assert_equal({exp}, {act} [, {msg}]) |
2025 none assert {exp} is equal to {act} | 2027 Number assert {exp} is equal to {act} |
2026 assert_equalfile({fname-one}, {fname-two}) | 2028 assert_equalfile({fname-one}, {fname-two}) |
2027 none assert file contents is equal | 2029 Number assert file contents is equal |
2028 assert_exception({error} [, {msg}]) | 2030 assert_exception({error} [, {msg}]) |
2029 none assert {error} is in v:exception | 2031 Number assert {error} is in v:exception |
2030 assert_fails({cmd} [, {error}]) none assert {cmd} fails | 2032 assert_fails({cmd} [, {error}]) Number assert {cmd} fails |
2031 assert_false({actual} [, {msg}]) | 2033 assert_false({actual} [, {msg}]) |
2032 none assert {actual} is false | 2034 Number assert {actual} is false |
2033 assert_inrange({lower}, {upper}, {actual} [, {msg}]) | 2035 assert_inrange({lower}, {upper}, {actual} [, {msg}]) |
2034 none assert {actual} is inside the range | 2036 Number assert {actual} is inside the range |
2035 assert_match({pat}, {text} [, {msg}]) | 2037 assert_match({pat}, {text} [, {msg}]) |
2036 none assert {pat} matches {text} | 2038 Number assert {pat} matches {text} |
2037 assert_notequal({exp}, {act} [, {msg}]) | 2039 assert_notequal({exp}, {act} [, {msg}]) |
2038 none assert {exp} is not equal {act} | 2040 Number assert {exp} is not equal {act} |
2039 assert_notmatch({pat}, {text} [, {msg}]) | 2041 assert_notmatch({pat}, {text} [, {msg}]) |
2040 none assert {pat} not matches {text} | 2042 Number assert {pat} not matches {text} |
2041 assert_report({msg}) none report a test failure | 2043 assert_report({msg}) Number report a test failure |
2042 assert_true({actual} [, {msg}]) none assert {actual} is true | 2044 assert_true({actual} [, {msg}]) Number assert {actual} is true |
2043 asin({expr}) Float arc sine of {expr} | 2045 asin({expr}) Float arc sine of {expr} |
2044 atan({expr}) Float arc tangent of {expr} | 2046 atan({expr}) Float arc tangent of {expr} |
2045 atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2} | 2047 atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2} |
2046 balloon_show({expr}) none show {expr} inside the balloon | 2048 balloon_show({expr}) none show {expr} inside the balloon |
2047 balloon_split({msg}) List split {msg} as used for a balloon | 2049 balloon_split({msg}) List split {msg} as used for a balloon |
2591 returned. | 2593 returned. |
2592 | 2594 |
2593 assert_beeps({cmd}) *assert_beeps()* | 2595 assert_beeps({cmd}) *assert_beeps()* |
2594 Run {cmd} and add an error message to |v:errors| if it does | 2596 Run {cmd} and add an error message to |v:errors| if it does |
2595 NOT produce a beep or visual bell. | 2597 NOT produce a beep or visual bell. |
2596 Also see |assert_fails()|. | 2598 Also see |assert_fails()| and |assert-return|. |
2597 | 2599 |
2598 *assert_equal()* | 2600 *assert_equal()* |
2599 assert_equal({expected}, {actual} [, {msg}]) | 2601 assert_equal({expected}, {actual} [, {msg}]) |
2600 When {expected} and {actual} are not equal an error message is | 2602 When {expected} and {actual} are not equal an error message is |
2601 added to |v:errors|. | 2603 added to |v:errors| and 1 is returned. Otherwise zero is |
2604 returned |assert-return|. | |
2602 There is no automatic conversion, the String "4" is different | 2605 There is no automatic conversion, the String "4" is different |
2603 from the Number 4. And the number 4 is different from the | 2606 from the Number 4. And the number 4 is different from the |
2604 Float 4.0. The value of 'ignorecase' is not used here, case | 2607 Float 4.0. The value of 'ignorecase' is not used here, case |
2605 always matters. | 2608 always matters. |
2606 When {msg} is omitted an error in the form "Expected | 2609 When {msg} is omitted an error in the form "Expected |
2612 | 2615 |
2613 *assert_equalfile()* | 2616 *assert_equalfile()* |
2614 assert_equalfile({fname-one}, {fname-two}) | 2617 assert_equalfile({fname-one}, {fname-two}) |
2615 When the files {fname-one} and {fname-two} do not contain | 2618 When the files {fname-one} and {fname-two} do not contain |
2616 exactly the same text an error message is added to |v:errors|. | 2619 exactly the same text an error message is added to |v:errors|. |
2620 Also see |assert-return|. | |
2617 When {fname-one} or {fname-two} does not exist the error will | 2621 When {fname-one} or {fname-two} does not exist the error will |
2618 mention that. | 2622 mention that. |
2619 Mainly useful with |terminal-diff|. | 2623 Mainly useful with |terminal-diff|. |
2620 | 2624 |
2621 assert_exception({error} [, {msg}]) *assert_exception()* | 2625 assert_exception({error} [, {msg}]) *assert_exception()* |
2622 When v:exception does not contain the string {error} an error | 2626 When v:exception does not contain the string {error} an error |
2623 message is added to |v:errors|. | 2627 message is added to |v:errors|. Also see |assert-return|. |
2624 This can be used to assert that a command throws an exception. | 2628 This can be used to assert that a command throws an exception. |
2625 Using the error number, followed by a colon, avoids problems | 2629 Using the error number, followed by a colon, avoids problems |
2626 with translations: > | 2630 with translations: > |
2627 try | 2631 try |
2628 commandthatfails | 2632 commandthatfails |
2631 call assert_exception('E492:') | 2635 call assert_exception('E492:') |
2632 endtry | 2636 endtry |
2633 | 2637 |
2634 assert_fails({cmd} [, {error}]) *assert_fails()* | 2638 assert_fails({cmd} [, {error}]) *assert_fails()* |
2635 Run {cmd} and add an error message to |v:errors| if it does | 2639 Run {cmd} and add an error message to |v:errors| if it does |
2636 NOT produce an error. | 2640 NOT produce an error. Also see |assert-return|. |
2637 When {error} is given it must match in |v:errmsg|. | 2641 When {error} is given it must match in |v:errmsg|. |
2638 Note that beeping is not considered an error, and some failing | 2642 Note that beeping is not considered an error, and some failing |
2639 commands only beep. Use |assert_beeps()| for those. | 2643 commands only beep. Use |assert_beeps()| for those. |
2640 | 2644 |
2641 assert_false({actual} [, {msg}]) *assert_false()* | 2645 assert_false({actual} [, {msg}]) *assert_false()* |
2642 When {actual} is not false an error message is added to | 2646 When {actual} is not false an error message is added to |
2643 |v:errors|, like with |assert_equal()|. | 2647 |v:errors|, like with |assert_equal()|. |
2648 Also see |assert-return|. | |
2644 A value is false when it is zero. When {actual} is not a | 2649 A value is false when it is zero. When {actual} is not a |
2645 number the assert fails. | 2650 number the assert fails. |
2646 When {msg} is omitted an error in the form | 2651 When {msg} is omitted an error in the form |
2647 "Expected False but got {actual}" is produced. | 2652 "Expected False but got {actual}" is produced. |
2648 | 2653 |
2649 assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()* | 2654 assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()* |
2650 This asserts number values. When {actual} is lower than | 2655 This asserts number values. When {actual} is lower than |
2651 {lower} or higher than {upper} an error message is added to | 2656 {lower} or higher than {upper} an error message is added to |
2652 |v:errors|. | 2657 |v:errors|. Also see |assert-return|. |
2653 When {msg} is omitted an error in the form | 2658 When {msg} is omitted an error in the form |
2654 "Expected range {lower} - {upper}, but got {actual}" is | 2659 "Expected range {lower} - {upper}, but got {actual}" is |
2655 produced. | 2660 produced. |
2656 | 2661 |
2657 *assert_match()* | 2662 *assert_match()* |
2658 assert_match({pattern}, {actual} [, {msg}]) | 2663 assert_match({pattern}, {actual} [, {msg}]) |
2659 When {pattern} does not match {actual} an error message is | 2664 When {pattern} does not match {actual} an error message is |
2660 added to |v:errors|. | 2665 added to |v:errors|. Also see |assert-return|. |
2661 | 2666 |
2662 {pattern} is used as with |=~|: The matching is always done | 2667 {pattern} is used as with |=~|: The matching is always done |
2663 like 'magic' was set and 'cpoptions' is empty, no matter what | 2668 like 'magic' was set and 'cpoptions' is empty, no matter what |
2664 the actual value of 'magic' or 'cpoptions' is. | 2669 the actual value of 'magic' or 'cpoptions' is. |
2665 | 2670 |
2676 | 2681 |
2677 *assert_notequal()* | 2682 *assert_notequal()* |
2678 assert_notequal({expected}, {actual} [, {msg}]) | 2683 assert_notequal({expected}, {actual} [, {msg}]) |
2679 The opposite of `assert_equal()`: add an error message to | 2684 The opposite of `assert_equal()`: add an error message to |
2680 |v:errors| when {expected} and {actual} are equal. | 2685 |v:errors| when {expected} and {actual} are equal. |
2686 Also see |assert-return|. | |
2681 | 2687 |
2682 *assert_notmatch()* | 2688 *assert_notmatch()* |
2683 assert_notmatch({pattern}, {actual} [, {msg}]) | 2689 assert_notmatch({pattern}, {actual} [, {msg}]) |
2684 The opposite of `assert_match()`: add an error message to | 2690 The opposite of `assert_match()`: add an error message to |
2685 |v:errors| when {pattern} matches {actual}. | 2691 |v:errors| when {pattern} matches {actual}. |
2692 Also see |assert-return|. | |
2686 | 2693 |
2687 assert_report({msg}) *assert_report()* | 2694 assert_report({msg}) *assert_report()* |
2688 Report a test failure directly, using {msg}. | 2695 Report a test failure directly, using {msg}. |
2696 Always returns one. | |
2689 | 2697 |
2690 assert_true({actual} [, {msg}]) *assert_true()* | 2698 assert_true({actual} [, {msg}]) *assert_true()* |
2691 When {actual} is not true an error message is added to | 2699 When {actual} is not true an error message is added to |
2692 |v:errors|, like with |assert_equal()|. | 2700 |v:errors|, like with |assert_equal()|. |
2701 Also see |assert-return|. | |
2693 A value is TRUE when it is a non-zero number. When {actual} | 2702 A value is TRUE when it is a non-zero number. When {actual} |
2694 is not a number the assert fails. | 2703 is not a number the assert fails. |
2695 When {msg} is omitted an error in the form "Expected True but | 2704 When {msg} is omitted an error in the form "Expected True but |
2696 got {actual}" is produced. | 2705 got {actual}" is produced. |
2697 | 2706 |
5390 To check if the job has no channel: > | 5399 To check if the job has no channel: > |
5391 if string(job_getchannel()) == 'channel fail' | 5400 if string(job_getchannel()) == 'channel fail' |
5392 < | 5401 < |
5393 {only available when compiled with the |+job| feature} | 5402 {only available when compiled with the |+job| feature} |
5394 | 5403 |
5395 job_info({job}) *job_info()* | 5404 job_info([{job}]) *job_info()* |
5396 Returns a Dictionary with information about {job}: | 5405 Returns a Dictionary with information about {job}: |
5397 "status" what |job_status()| returns | 5406 "status" what |job_status()| returns |
5398 "channel" what |job_getchannel()| returns | 5407 "channel" what |job_getchannel()| returns |
5408 "cmd" List of command arguments used to start the job | |
5399 "process" process ID | 5409 "process" process ID |
5400 "tty_in" terminal input name, empty when none | 5410 "tty_in" terminal input name, empty when none |
5401 "tty_out" terminal output name, empty when none | 5411 "tty_out" terminal output name, empty when none |
5402 "exitval" only valid when "status" is "dead" | 5412 "exitval" only valid when "status" is "dead" |
5403 "exit_cb" function to be called on exit | 5413 "exit_cb" function to be called on exit |
5404 "stoponexit" |job-stoponexit| | 5414 "stoponexit" |job-stoponexit| |
5415 | |
5416 Without any arguments, returns a List with all Job objects. | |
5405 | 5417 |
5406 job_setoptions({job}, {options}) *job_setoptions()* | 5418 job_setoptions({job}, {options}) *job_setoptions()* |
5407 Change options for {job}. Supported are: | 5419 Change options for {job}. Supported are: |
5408 "stoponexit" |job-stoponexit| | 5420 "stoponexit" |job-stoponexit| |
5409 "exit_cb" |job-exit_cb| | 5421 "exit_cb" |job-exit_cb| |