189a9c159SBram Moolenaar*testing.txt* For Vim version 8.2. Last change: 2021 Aug 15 2ed997adaSBram Moolenaar 3ed997adaSBram Moolenaar 4ed997adaSBram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar 5ed997adaSBram Moolenaar 6ed997adaSBram Moolenaar 7ed997adaSBram MoolenaarTesting Vim and Vim script *testing-support* 8ed997adaSBram Moolenaar 9ed997adaSBram MoolenaarExpression evaluation is explained in |eval.txt|. This file goes into details 10ed997adaSBram Moolenaarabout writing tests in Vim script. This can be used for testing Vim itself 11ed997adaSBram Moolenaarand for testing plugins. 12ed997adaSBram Moolenaar 13ed997adaSBram Moolenaar1. Testing Vim |testing| 145477506aSBram Moolenaar2. Test functions |test-functions-details| 155477506aSBram Moolenaar3. Assert functions |assert-functions-details| 16ed997adaSBram Moolenaar 17ed997adaSBram Moolenaar============================================================================== 18ed997adaSBram Moolenaar1. Testing Vim *testing* 19ed997adaSBram Moolenaar 20ed997adaSBram MoolenaarVim can be tested after building it, usually with "make test". 21ed997adaSBram MoolenaarThe tests are located in the directory "src/testdir". 22ed997adaSBram Moolenaar 23b96a32efSBram MoolenaarThere are two types of tests added over time: 24b96a32efSBram Moolenaar test20.in oldest, only for tiny and small builds 25b96a32efSBram Moolenaar test_something.vim new style tests 26b96a32efSBram Moolenaar 27ed997adaSBram Moolenaar *new-style-testing* 28f7c4d836SBram MoolenaarNew tests should be added as new style tests. The test scripts are named 29f7c4d836SBram Moolenaartest_<feature>.vim (replace <feature> with the feature under test). These use 30f7c4d836SBram Moolenaarfunctions such as |assert_equal()| to keep the test commands and the expected 31f7c4d836SBram Moolenaarresult in one place. 32b96a32efSBram Moolenaar *old-style-testing* 33b96a32efSBram MoolenaarThese tests are used only for testing Vim without the |+eval| feature. 34ed997adaSBram Moolenaar 35ed997adaSBram MoolenaarFind more information in the file src/testdir/README.txt. 36ed997adaSBram Moolenaar 37ed997adaSBram Moolenaar============================================================================== 385477506aSBram Moolenaar2. Test functions *test-functions-details* 39ed997adaSBram Moolenaar 40ed997adaSBram Moolenaartest_alloc_fail({id}, {countdown}, {repeat}) *test_alloc_fail()* 41ed997adaSBram Moolenaar This is for testing: If the memory allocation with {id} is 42ed997adaSBram Moolenaar called, then decrement {countdown}, and when it reaches zero 43ed997adaSBram Moolenaar let memory allocation fail {repeat} times. When {repeat} is 44ed997adaSBram Moolenaar smaller than one it fails one time. 45ed997adaSBram Moolenaar 46ce90e36fSBram Moolenaar Can also be used as a |method|: > 47ce90e36fSBram Moolenaar GetAllocId()->test_alloc_fail() 48ed997adaSBram Moolenaar 4989a9c159SBram Moolenaar 50ed997adaSBram Moolenaartest_autochdir() *test_autochdir()* 51ed997adaSBram Moolenaar Set a flag to enable the effect of 'autochdir' before Vim 52ed997adaSBram Moolenaar startup has finished. 53ed997adaSBram Moolenaar 54ed997adaSBram Moolenaar 55ed997adaSBram Moolenaartest_feedinput({string}) *test_feedinput()* 56ed997adaSBram Moolenaar Characters in {string} are queued for processing as if they 57ed997adaSBram Moolenaar were typed by the user. This uses a low level input buffer. 58ed997adaSBram Moolenaar This function works only when with |+unix| or GUI is running. 59ed997adaSBram Moolenaar 60ce90e36fSBram Moolenaar Can also be used as a |method|: > 61ce90e36fSBram Moolenaar GetText()->test_feedinput() 62ed997adaSBram Moolenaar 6389a9c159SBram Moolenaar 64ed997adaSBram Moolenaartest_garbagecollect_now() *test_garbagecollect_now()* 65ed997adaSBram Moolenaar Like garbagecollect(), but executed right away. This must 66ed997adaSBram Moolenaar only be called directly to avoid any structure to exist 67ed997adaSBram Moolenaar internally, and |v:testing| must have been set before calling 68ed997adaSBram Moolenaar any function. 69ed997adaSBram Moolenaar 70ed997adaSBram Moolenaar 71ed997adaSBram Moolenaartest_garbagecollect_soon() *test_garbagecollect_soon()* 72ed997adaSBram Moolenaar Set the flag to call the garbagecollector as if in the main 73ed997adaSBram Moolenaar loop. Only to be used in tests. 74ed997adaSBram Moolenaar 75ed997adaSBram Moolenaar 76ed997adaSBram Moolenaartest_getvalue({name}) *test_getvalue()* 77ed997adaSBram Moolenaar Get the value of an internal variable. These values for 78ed997adaSBram Moolenaar {name} are supported: 79ed997adaSBram Moolenaar need_fileinfo 80ed997adaSBram Moolenaar 81ce90e36fSBram Moolenaar Can also be used as a |method|: > 82ce90e36fSBram Moolenaar GetName()->test_getvalue() 83f1e7449dSYegappan Lakshmanan< 8418d46587SYegappan Lakshmanan *test_gui_drop_files()* 8518d46587SYegappan Lakshmanantest_gui_drop_files({list}, {row}, {col}, {mods}) 8618d46587SYegappan Lakshmanan Drop one or more files in {list} in the window at {row}, {col}. 8790df4b9dSBram Moolenaar This function only works when the GUI is running and the 88*2286304cSBram Moolenaar |drop_file| feature is present. 8918d46587SYegappan Lakshmanan 9018d46587SYegappan Lakshmanan The supported values for {mods} are: 9118d46587SYegappan Lakshmanan 0x4 Shift 9218d46587SYegappan Lakshmanan 0x8 Alt 9318d46587SYegappan Lakshmanan 0x10 Ctrl 94*2286304cSBram Moolenaar The files are added to the |argument-list| and the first file 95*2286304cSBram Moolenaar in {list} is edited in the window. See |drag-n-drop| for more 9618d46587SYegappan Lakshmanan information. 9718d46587SYegappan Lakshmanan 98f1e7449dSYegappan Lakshmanan *test_gui_mouse_event()* 99f1e7449dSYegappan Lakshmanantest_gui_mouse_event({button}, {row}, {col}, {multiclick}, {modifiers}) 10018d46587SYegappan Lakshmanan Inject a mouse button click event. This function only works 10118d46587SYegappan Lakshmanan when the GUI is running. 102f1e7449dSYegappan Lakshmanan The supported values for {button} are: 103f1e7449dSYegappan Lakshmanan 0 right mouse button 104f1e7449dSYegappan Lakshmanan 1 middle mouse button 105f1e7449dSYegappan Lakshmanan 2 left mouse button 106f1e7449dSYegappan Lakshmanan 3 mouse button release 107f1e7449dSYegappan Lakshmanan 4 scroll wheel down 108f1e7449dSYegappan Lakshmanan 5 scroll wheel up 109f1e7449dSYegappan Lakshmanan 6 scroll wheel left 110f1e7449dSYegappan Lakshmanan 7 scroll wheel right 11118d46587SYegappan Lakshmanan {row} and {col} specify the location of the mouse click. The 11218d46587SYegappan Lakshmanan first row of the Vim window is 1 and the last row is 'lines'. 11318d46587SYegappan Lakshmanan The maximum value of {col} is 'columns'. 114f1e7449dSYegappan Lakshmanan To inject a multiclick event, set {multiclick} to 1. 115f1e7449dSYegappan Lakshmanan The supported values for {modifiers} are: 116f1e7449dSYegappan Lakshmanan 4 shift is pressed 117f1e7449dSYegappan Lakshmanan 8 alt is pressed 118f1e7449dSYegappan Lakshmanan 16 ctrl is pressed 119f1e7449dSYegappan Lakshmanan After injecting the mouse event you probably should call 120f1e7449dSYegappan Lakshmanan |feedkeys()| to have them processed, e.g.: > 121f1e7449dSYegappan Lakshmanan call feedkeys("y", 'Lx!') 122f1e7449dSYegappan Lakshmanan 123ed997adaSBram Moolenaar 124ed997adaSBram Moolenaartest_ignore_error({expr}) *test_ignore_error()* 125ed997adaSBram Moolenaar Ignore any error containing {expr}. A normal message is given 126ed997adaSBram Moolenaar instead. 127ed997adaSBram Moolenaar This is only meant to be used in tests, where catching the 128ed997adaSBram Moolenaar error with try/catch cannot be used (because it skips over 129ed997adaSBram Moolenaar following code). 130ed997adaSBram Moolenaar {expr} is used literally, not as a pattern. 131ed997adaSBram Moolenaar When the {expr} is the string "RESET" then the list of ignored 132ed997adaSBram Moolenaar errors is made empty. 133ed997adaSBram Moolenaar 134ce90e36fSBram Moolenaar Can also be used as a |method|: > 135ce90e36fSBram Moolenaar GetErrorText()->test_ignore_error() 136ed997adaSBram Moolenaar 13789a9c159SBram Moolenaar 138ed997adaSBram Moolenaartest_null_blob() *test_null_blob()* 139ed997adaSBram Moolenaar Return a |Blob| that is null. Only useful for testing. 140ed997adaSBram Moolenaar 141ed997adaSBram Moolenaar 142ed997adaSBram Moolenaartest_null_channel() *test_null_channel()* 143ed997adaSBram Moolenaar Return a |Channel| that is null. Only useful for testing. 144ed997adaSBram Moolenaar {only available when compiled with the +channel feature} 145ed997adaSBram Moolenaar 146ed997adaSBram Moolenaar 147ed997adaSBram Moolenaartest_null_dict() *test_null_dict()* 148ed997adaSBram Moolenaar Return a |Dict| that is null. Only useful for testing. 149ed997adaSBram Moolenaar 150ed997adaSBram Moolenaar 151e69f6d04SBram Moolenaartest_null_function() *test_null_function()* 152d1caa941SBram Moolenaar Return a |Funcref| that is null. Only useful for testing. 153e69f6d04SBram Moolenaar 154e69f6d04SBram Moolenaar 155ed997adaSBram Moolenaartest_null_job() *test_null_job()* 156ed997adaSBram Moolenaar Return a |Job| that is null. Only useful for testing. 157ed997adaSBram Moolenaar {only available when compiled with the +job feature} 158ed997adaSBram Moolenaar 159ed997adaSBram Moolenaar 160ed997adaSBram Moolenaartest_null_list() *test_null_list()* 161ed997adaSBram Moolenaar Return a |List| that is null. Only useful for testing. 162ed997adaSBram Moolenaar 163ed997adaSBram Moolenaar 164ed997adaSBram Moolenaartest_null_partial() *test_null_partial()* 165ed997adaSBram Moolenaar Return a |Partial| that is null. Only useful for testing. 166ed997adaSBram Moolenaar 167ed997adaSBram Moolenaar 168ed997adaSBram Moolenaartest_null_string() *test_null_string()* 169ed997adaSBram Moolenaar Return a |String| that is null. Only useful for testing. 170ed997adaSBram Moolenaar 171ed997adaSBram Moolenaar 172ed997adaSBram Moolenaartest_option_not_set({name}) *test_option_not_set()* 173ed997adaSBram Moolenaar Reset the flag that indicates option {name} was set. Thus it 174ed997adaSBram Moolenaar looks like it still has the default value. Use like this: > 175ed997adaSBram Moolenaar set ambiwidth=double 176ed997adaSBram Moolenaar call test_option_not_set('ambiwidth') 177ed997adaSBram Moolenaar< Now the 'ambiwidth' option behaves like it was never changed, 178ed997adaSBram Moolenaar even though the value is "double". 179ed997adaSBram Moolenaar Only to be used for testing! 180ed997adaSBram Moolenaar 181ce90e36fSBram Moolenaar Can also be used as a |method|: > 182ce90e36fSBram Moolenaar GetOptionName()->test_option_not_set() 183ce90e36fSBram Moolenaar 184ed997adaSBram Moolenaar 185ed997adaSBram Moolenaartest_override({name}, {val}) *test_override()* 186ed997adaSBram Moolenaar Overrides certain parts of Vim's internal processing to be able 187ed997adaSBram Moolenaar to run tests. Only to be used for testing Vim! 188ed997adaSBram Moolenaar The override is enabled when {val} is non-zero and removed 189ed997adaSBram Moolenaar when {val} is zero. 190ed997adaSBram Moolenaar Current supported values for name are: 191ed997adaSBram Moolenaar 192ed997adaSBram Moolenaar name effect when {val} is non-zero ~ 193ed997adaSBram Moolenaar redraw disable the redrawing() function 194ed997adaSBram Moolenaar redraw_flag ignore the RedrawingDisabled flag 195ed997adaSBram Moolenaar char_avail disable the char_avail() function 196ed997adaSBram Moolenaar starting reset the "starting" variable, see below 197ed997adaSBram Moolenaar nfa_fail makes the NFA regexp engine fail to force a 198ed997adaSBram Moolenaar fallback to the old engine 199ed997adaSBram Moolenaar no_query_mouse do not query the mouse position for "dec" 200ed997adaSBram Moolenaar terminals 201ed997adaSBram Moolenaar no_wait_return set the "no_wait_return" flag. Not restored 202ed997adaSBram Moolenaar with "ALL". 203b340baedSBram Moolenaar ui_delay time in msec to use in ui_delay(); overrules a 204b340baedSBram Moolenaar wait time of up to 3 seconds for messages 2050c0eddd3SBram Moolenaar term_props reset all terminal properties when the version 2060c0eddd3SBram Moolenaar string is detected 207c8cdf0f8SBram Moolenaar uptime overrules sysinfo.uptime 208ed997adaSBram Moolenaar ALL clear all overrides ({val} is not used) 209ed997adaSBram Moolenaar 210ed997adaSBram Moolenaar "starting" is to be used when a test should behave like 211ed997adaSBram Moolenaar startup was done. Since the tests are run by sourcing a 212ed997adaSBram Moolenaar script the "starting" variable is non-zero. This is usually a 213ed997adaSBram Moolenaar good thing (tests run faster), but sometimes changes behavior 214ed997adaSBram Moolenaar in a way that the test doesn't work properly. 215ed997adaSBram Moolenaar When using: > 216ed997adaSBram Moolenaar call test_override('starting', 1) 217ed997adaSBram Moolenaar< The value of "starting" is saved. It is restored by: > 218ed997adaSBram Moolenaar call test_override('starting', 0) 219ed997adaSBram Moolenaar 220ce90e36fSBram Moolenaar< Can also be used as a |method|: > 221ce90e36fSBram Moolenaar GetOverrideVal()-> test_override('starting') 222ed997adaSBram Moolenaar 22389a9c159SBram Moolenaar 224ed997adaSBram Moolenaartest_refcount({expr}) *test_refcount()* 225ed997adaSBram Moolenaar Return the reference count of {expr}. When {expr} is of a 226ed997adaSBram Moolenaar type that does not have a reference count, returns -1. Only 227ed997adaSBram Moolenaar to be used for testing. 228ed997adaSBram Moolenaar 229ce90e36fSBram Moolenaar Can also be used as a |method|: > 230ce90e36fSBram Moolenaar GetVarname()->test_refcount() 231ce90e36fSBram Moolenaar 232ed997adaSBram Moolenaar 233ed997adaSBram Moolenaartest_scrollbar({which}, {value}, {dragging}) *test_scrollbar()* 234ed997adaSBram Moolenaar Pretend using scrollbar {which} to move it to position 235ed997adaSBram Moolenaar {value}. {which} can be: 236ed997adaSBram Moolenaar left Left scrollbar of the current window 237ed997adaSBram Moolenaar right Right scrollbar of the current window 238ed997adaSBram Moolenaar hor Horizontal scrollbar 239ed997adaSBram Moolenaar 240ed997adaSBram Moolenaar For the vertical scrollbars {value} can be 1 to the 241ed997adaSBram Moolenaar line-count of the buffer. For the horizontal scrollbar the 242ed997adaSBram Moolenaar {value} can be between 1 and the maximum line length, assuming 243ed997adaSBram Moolenaar 'wrap' is not set. 244ed997adaSBram Moolenaar 245ed997adaSBram Moolenaar When {dragging} is non-zero it's like dragging the scrollbar, 246ed997adaSBram Moolenaar otherwise it's like clicking in the scrollbar. 247ed997adaSBram Moolenaar Only works when the {which} scrollbar actually exists, 248ed997adaSBram Moolenaar obviously only when using the GUI. 249ed997adaSBram Moolenaar 250ce90e36fSBram Moolenaar Can also be used as a |method|: > 251ce90e36fSBram Moolenaar GetValue()->test_scrollbar('right', 0) 252ed997adaSBram Moolenaar 25389a9c159SBram Moolenaar 254ed997adaSBram Moolenaartest_setmouse({row}, {col}) *test_setmouse()* 255ed997adaSBram Moolenaar Set the mouse position to be used for the next mouse action. 256ed997adaSBram Moolenaar {row} and {col} are one based. 257ed997adaSBram Moolenaar For example: > 258ed997adaSBram Moolenaar call test_setmouse(4, 20) 259ed997adaSBram Moolenaar call feedkeys("\<LeftMouse>", "xt") 260ed997adaSBram Moolenaar 26189a9c159SBram Moolenaar 262ed997adaSBram Moolenaartest_settime({expr}) *test_settime()* 263ed997adaSBram Moolenaar Set the time Vim uses internally. Currently only used for 264ed997adaSBram Moolenaar timestamps in the history, as they are used in viminfo, and 265ed997adaSBram Moolenaar for undo. 266ed997adaSBram Moolenaar Using a value of 1 makes Vim not sleep after a warning or 267ed997adaSBram Moolenaar error message. 268ed997adaSBram Moolenaar {expr} must evaluate to a number. When the value is zero the 269ed997adaSBram Moolenaar normal behavior is restored. 270ed997adaSBram Moolenaar 271ce90e36fSBram Moolenaar Can also be used as a |method|: > 272ce90e36fSBram Moolenaar GetTime()->test_settime() 273ce90e36fSBram Moolenaar 27489a9c159SBram Moolenaar 2754f645c54SBram Moolenaartest_srand_seed([seed]) *test_srand_seed()* 2764f645c54SBram Moolenaar When [seed] is given this sets the seed value used by 2774f645c54SBram Moolenaar `srand()`. When omitted the test seed is removed. 2784f645c54SBram Moolenaar 27989a9c159SBram Moolenaar 28089a9c159SBram Moolenaartest_unknown() *test_unknown()* 28189a9c159SBram Moolenaar Return a value with unknown type. Only useful for testing. 28289a9c159SBram Moolenaar 28389a9c159SBram Moolenaar 28489a9c159SBram Moolenaartest_void() *test_void()* 28589a9c159SBram Moolenaar Return a value with void type. Only useful for testing. 28689a9c159SBram Moolenaar 287ed997adaSBram Moolenaar============================================================================== 2885477506aSBram Moolenaar3. Assert functions *assert-functions-details* 289ed997adaSBram Moolenaar 290ed997adaSBram Moolenaar 291ed997adaSBram Moolenaarassert_beeps({cmd}) *assert_beeps()* 292ed997adaSBram Moolenaar Run {cmd} and add an error message to |v:errors| if it does 293ed997adaSBram Moolenaar NOT produce a beep or visual bell. 2945b8cabfeSBram Moolenaar Also see |assert_fails()|, |assert_nobeep()| and 2955b8cabfeSBram Moolenaar |assert-return|. 296ed997adaSBram Moolenaar 29724278d24SBram Moolenaar Can also be used as a |method|: > 29824278d24SBram Moolenaar GetCmd()->assert_beeps() 29924278d24SBram Moolenaar< 300ed997adaSBram Moolenaar *assert_equal()* 301ed997adaSBram Moolenaarassert_equal({expected}, {actual} [, {msg}]) 302ed997adaSBram Moolenaar When {expected} and {actual} are not equal an error message is 303ed997adaSBram Moolenaar added to |v:errors| and 1 is returned. Otherwise zero is 304ed997adaSBram Moolenaar returned |assert-return|. 305ed997adaSBram Moolenaar There is no automatic conversion, the String "4" is different 306ed997adaSBram Moolenaar from the Number 4. And the number 4 is different from the 307ed997adaSBram Moolenaar Float 4.0. The value of 'ignorecase' is not used here, case 308ed997adaSBram Moolenaar always matters. 309ed997adaSBram Moolenaar When {msg} is omitted an error in the form "Expected 310ed997adaSBram Moolenaar {expected} but got {actual}" is produced. 311ed997adaSBram Moolenaar Example: > 312ed997adaSBram Moolenaar assert_equal('foo', 'bar') 313ed997adaSBram Moolenaar< Will result in a string to be added to |v:errors|: 314ed997adaSBram Moolenaar test.vim line 12: Expected 'foo' but got 'bar' ~ 315ed997adaSBram Moolenaar 3167ff78465SBram Moolenaar Can also be used as a |method|, the base is passed as the 3177ff78465SBram Moolenaar second argument: > 31825e42231SBram Moolenaar mylist->assert_equal([1, 2, 3]) 31925e42231SBram Moolenaar 32025e42231SBram Moolenaar< *assert_equalfile()* 321fb517bacSBram Moolenaarassert_equalfile({fname-one}, {fname-two} [, {msg}]) 322ed997adaSBram Moolenaar When the files {fname-one} and {fname-two} do not contain 323ed997adaSBram Moolenaar exactly the same text an error message is added to |v:errors|. 324ed997adaSBram Moolenaar Also see |assert-return|. 325ed997adaSBram Moolenaar When {fname-one} or {fname-two} does not exist the error will 326ed997adaSBram Moolenaar mention that. 327ed997adaSBram Moolenaar Mainly useful with |terminal-diff|. 328ed997adaSBram Moolenaar 329e49fbff3SBram Moolenaar Can also be used as a |method|: > 330e49fbff3SBram Moolenaar GetLog()->assert_equalfile('expected.log') 331e49fbff3SBram Moolenaar 332ed997adaSBram Moolenaarassert_exception({error} [, {msg}]) *assert_exception()* 333ed997adaSBram Moolenaar When v:exception does not contain the string {error} an error 334ed997adaSBram Moolenaar message is added to |v:errors|. Also see |assert-return|. 335ed997adaSBram Moolenaar This can be used to assert that a command throws an exception. 336ed997adaSBram Moolenaar Using the error number, followed by a colon, avoids problems 337ed997adaSBram Moolenaar with translations: > 338ed997adaSBram Moolenaar try 339ed997adaSBram Moolenaar commandthatfails 340ed997adaSBram Moolenaar call assert_false(1, 'command should have failed') 341ed997adaSBram Moolenaar catch 342ed997adaSBram Moolenaar call assert_exception('E492:') 343ed997adaSBram Moolenaar endtry 3441d634542SBram Moolenaar< 3451d634542SBram Moolenaar *assert_fails()* 3469bd5d879SBram Moolenaarassert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]]) 347ed997adaSBram Moolenaar Run {cmd} and add an error message to |v:errors| if it does 3489b7bf9e9SBram Moolenaar NOT produce an error or when {error} is not found in the 3499b7bf9e9SBram Moolenaar error message. Also see |assert-return|. 3509b7bf9e9SBram Moolenaar 3519b7bf9e9SBram Moolenaar When {error} is a string it must be found literally in the 3529b7bf9e9SBram Moolenaar first reported error. Most often this will be the error code, 3539b7bf9e9SBram Moolenaar including the colon, e.g. "E123:". > 3549b7bf9e9SBram Moolenaar assert_fails('bad cmd', 'E987:') 3559b7bf9e9SBram Moolenaar< 3569b7bf9e9SBram Moolenaar When {error} is a |List| with one or two strings, these are 3579b7bf9e9SBram Moolenaar used as patterns. The first pattern is matched against the 3589b7bf9e9SBram Moolenaar first reported error: > 3599b7bf9e9SBram Moolenaar assert_fails('cmd', ['E987:.*expected bool']) 3609b7bf9e9SBram Moolenaar< The second pattern, if present, is matched against the last 3614072ba57SBram Moolenaar reported error. 3624072ba57SBram Moolenaar If there is only one error then both patterns must match. This 3634072ba57SBram Moolenaar can be used to check that there is only one error. 3644072ba57SBram Moolenaar To only match the last error use an empty string for the first 3654072ba57SBram Moolenaar error: > 3669b7bf9e9SBram Moolenaar assert_fails('cmd', ['', 'E987:']) 3679b7bf9e9SBram Moolenaar< 3681d634542SBram Moolenaar If {msg} is empty then it is not used. Do this to get the 3691d634542SBram Moolenaar default message when passing the {lnum} argument. 3701d634542SBram Moolenaar 3711d634542SBram Moolenaar When {lnum} is present and not negative, and the {error} 3721d634542SBram Moolenaar argument is present and matches, then this is compared with 3731d634542SBram Moolenaar the line number at which the error was reported. That can be 3741d634542SBram Moolenaar the line number in a function or in a script. 3751d634542SBram Moolenaar 3769bd5d879SBram Moolenaar When {context} is present it is used as a pattern and matched 3779bd5d879SBram Moolenaar against the context (script name or function name) where 3789bd5d879SBram Moolenaar {lnum} is located in. 3799bd5d879SBram Moolenaar 380ed997adaSBram Moolenaar Note that beeping is not considered an error, and some failing 381ed997adaSBram Moolenaar commands only beep. Use |assert_beeps()| for those. 382ed997adaSBram Moolenaar 38324278d24SBram Moolenaar Can also be used as a |method|: > 38424278d24SBram Moolenaar GetCmd()->assert_fails('E99:') 38524278d24SBram Moolenaar 386ed997adaSBram Moolenaarassert_false({actual} [, {msg}]) *assert_false()* 387ed997adaSBram Moolenaar When {actual} is not false an error message is added to 388ed997adaSBram Moolenaar |v:errors|, like with |assert_equal()|. 389ed997adaSBram Moolenaar Also see |assert-return|. 390ed997adaSBram Moolenaar A value is false when it is zero. When {actual} is not a 391ed997adaSBram Moolenaar number the assert fails. 392ed997adaSBram Moolenaar When {msg} is omitted an error in the form 393ed997adaSBram Moolenaar "Expected False but got {actual}" is produced. 394ed997adaSBram Moolenaar 39524278d24SBram Moolenaar Can also be used as a |method|: > 39624278d24SBram Moolenaar GetResult()->assert_false() 39724278d24SBram Moolenaar 398ed997adaSBram Moolenaarassert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()* 399ed997adaSBram Moolenaar This asserts number and |Float| values. When {actual} is lower 400ed997adaSBram Moolenaar than {lower} or higher than {upper} an error message is added 401ed997adaSBram Moolenaar to |v:errors|. Also see |assert-return|. 402ed997adaSBram Moolenaar When {msg} is omitted an error in the form 403ed997adaSBram Moolenaar "Expected range {lower} - {upper}, but got {actual}" is 404ed997adaSBram Moolenaar produced. 405ed997adaSBram Moolenaar 406ed997adaSBram Moolenaar *assert_match()* 407ed997adaSBram Moolenaarassert_match({pattern}, {actual} [, {msg}]) 408ed997adaSBram Moolenaar When {pattern} does not match {actual} an error message is 409ed997adaSBram Moolenaar added to |v:errors|. Also see |assert-return|. 410ed997adaSBram Moolenaar 411ed997adaSBram Moolenaar {pattern} is used as with |=~|: The matching is always done 412ed997adaSBram Moolenaar like 'magic' was set and 'cpoptions' is empty, no matter what 413ed997adaSBram Moolenaar the actual value of 'magic' or 'cpoptions' is. 414ed997adaSBram Moolenaar 415ed997adaSBram Moolenaar {actual} is used as a string, automatic conversion applies. 416ed997adaSBram Moolenaar Use "^" and "$" to match with the start and end of the text. 417ed997adaSBram Moolenaar Use both to match the whole text. 418ed997adaSBram Moolenaar 419ed997adaSBram Moolenaar When {msg} is omitted an error in the form 420ed997adaSBram Moolenaar "Pattern {pattern} does not match {actual}" is produced. 421ed997adaSBram Moolenaar Example: > 422ed997adaSBram Moolenaar assert_match('^f.*o$', 'foobar') 423ed997adaSBram Moolenaar< Will result in a string to be added to |v:errors|: 424ed997adaSBram Moolenaar test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~ 425ed997adaSBram Moolenaar 42624278d24SBram Moolenaar Can also be used as a |method|: > 42724278d24SBram Moolenaar getFile()->assert_match('foo.*') 42824278d24SBram Moolenaar< 4295b8cabfeSBram Moolenaarassert_nobeep({cmd}) *assert_nobeep()* 4305b8cabfeSBram Moolenaar Run {cmd} and add an error message to |v:errors| if it 4315b8cabfeSBram Moolenaar produces a beep or visual bell. 4325b8cabfeSBram Moolenaar Also see |assert_beeps()|. 4335b8cabfeSBram Moolenaar 4345b8cabfeSBram Moolenaar Can also be used as a |method|: > 4355b8cabfeSBram Moolenaar GetCmd()->assert_nobeep() 4365b8cabfeSBram Moolenaar< 437ed997adaSBram Moolenaar *assert_notequal()* 438ed997adaSBram Moolenaarassert_notequal({expected}, {actual} [, {msg}]) 439ed997adaSBram Moolenaar The opposite of `assert_equal()`: add an error message to 440ed997adaSBram Moolenaar |v:errors| when {expected} and {actual} are equal. 441ed997adaSBram Moolenaar Also see |assert-return|. 442ed997adaSBram Moolenaar 44325e42231SBram Moolenaar Can also be used as a |method|: > 44425e42231SBram Moolenaar mylist->assert_notequal([1, 2, 3]) 44525e42231SBram Moolenaar 44625e42231SBram Moolenaar< *assert_notmatch()* 447ed997adaSBram Moolenaarassert_notmatch({pattern}, {actual} [, {msg}]) 448ed997adaSBram Moolenaar The opposite of `assert_match()`: add an error message to 449ed997adaSBram Moolenaar |v:errors| when {pattern} matches {actual}. 450ed997adaSBram Moolenaar Also see |assert-return|. 451ed997adaSBram Moolenaar 45224278d24SBram Moolenaar Can also be used as a |method|: > 45324278d24SBram Moolenaar getFile()->assert_notmatch('bar.*') 45424278d24SBram Moolenaar 455e49fbff3SBram Moolenaar 456ed997adaSBram Moolenaarassert_report({msg}) *assert_report()* 4576aa57295SBram Moolenaar Report a test failure directly, using String {msg}. 458ed997adaSBram Moolenaar Always returns one. 459ed997adaSBram Moolenaar 460e49fbff3SBram Moolenaar Can also be used as a |method|: > 461e49fbff3SBram Moolenaar GetMessage()->assert_report() 462e49fbff3SBram Moolenaar 463e49fbff3SBram Moolenaar 464ed997adaSBram Moolenaarassert_true({actual} [, {msg}]) *assert_true()* 465ed997adaSBram Moolenaar When {actual} is not true an error message is added to 466ed997adaSBram Moolenaar |v:errors|, like with |assert_equal()|. 467ed997adaSBram Moolenaar Also see |assert-return|. 468ed997adaSBram Moolenaar A value is TRUE when it is a non-zero number. When {actual} 469ed997adaSBram Moolenaar is not a number the assert fails. 470ed997adaSBram Moolenaar When {msg} is omitted an error in the form "Expected True but 471ed997adaSBram Moolenaar got {actual}" is produced. 472ed997adaSBram Moolenaar 47324278d24SBram Moolenaar Can also be used as a |method|: > 47424278d24SBram Moolenaar GetResult()->assert_true() 47524278d24SBram Moolenaar< 476ed997adaSBram Moolenaar 477ed997adaSBram Moolenaar vim:tw=78:ts=8:noet:ft=help:norl: 478