blob: b03726572b4f437862e7c43fac8fb70c0b276336 [file] [log] [blame]
Bram Moolenaar86b48162022-12-06 18:20:10 +00001*testing.txt* For Vim version 9.0. Last change: 2022 Nov 28
Bram Moolenaared997ad2019-07-21 16:42:00 +02002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Testing Vim and Vim script *testing-support*
8
9Expression evaluation is explained in |eval.txt|. This file goes into details
10about writing tests in Vim script. This can be used for testing Vim itself
11and for testing plugins.
12
131. Testing Vim |testing|
Bram Moolenaar54775062019-07-31 21:07:14 +0200142. Test functions |test-functions-details|
153. Assert functions |assert-functions-details|
Bram Moolenaared997ad2019-07-21 16:42:00 +020016
17==============================================================================
181. Testing Vim *testing*
19
20Vim can be tested after building it, usually with "make test".
21The tests are located in the directory "src/testdir".
22
Bram Moolenaarb96a32e2020-08-13 18:59:55 +020023There are two types of tests added over time:
24 test20.in oldest, only for tiny and small builds
25 test_something.vim new style tests
26
Bram Moolenaared997ad2019-07-21 16:42:00 +020027 *new-style-testing*
Bram Moolenaarf7c4d832020-08-11 20:42:19 +020028New tests should be added as new style tests. The test scripts are named
29test_<feature>.vim (replace <feature> with the feature under test). These use
30functions such as |assert_equal()| to keep the test commands and the expected
31result in one place.
Bram Moolenaarb96a32e2020-08-13 18:59:55 +020032 *old-style-testing*
33These tests are used only for testing Vim without the |+eval| feature.
Bram Moolenaared997ad2019-07-21 16:42:00 +020034
35Find more information in the file src/testdir/README.txt.
36
37==============================================================================
Bram Moolenaar54775062019-07-31 21:07:14 +0200382. Test functions *test-functions-details*
Bram Moolenaared997ad2019-07-21 16:42:00 +020039
40test_alloc_fail({id}, {countdown}, {repeat}) *test_alloc_fail()*
41 This is for testing: If the memory allocation with {id} is
42 called, then decrement {countdown}, and when it reaches zero
43 let memory allocation fail {repeat} times. When {repeat} is
44 smaller than one it fails one time.
45
Bram Moolenaarce90e362019-09-08 18:58:44 +020046 Can also be used as a |method|: >
47 GetAllocId()->test_alloc_fail()
Bram Moolenaared997ad2019-07-21 16:42:00 +020048
Bram Moolenaar89a9c152021-08-29 21:55:35 +020049
Bram Moolenaared997ad2019-07-21 16:42:00 +020050test_autochdir() *test_autochdir()*
51 Set a flag to enable the effect of 'autochdir' before Vim
52 startup has finished.
53
54
55test_feedinput({string}) *test_feedinput()*
56 Characters in {string} are queued for processing as if they
57 were typed by the user. This uses a low level input buffer.
58 This function works only when with |+unix| or GUI is running.
59
Bram Moolenaarce90e362019-09-08 18:58:44 +020060 Can also be used as a |method|: >
61 GetText()->test_feedinput()
Bram Moolenaared997ad2019-07-21 16:42:00 +020062
Bram Moolenaar89a9c152021-08-29 21:55:35 +020063
Bram Moolenaared997ad2019-07-21 16:42:00 +020064test_garbagecollect_now() *test_garbagecollect_now()*
65 Like garbagecollect(), but executed right away. This must
66 only be called directly to avoid any structure to exist
67 internally, and |v:testing| must have been set before calling
Bram Moolenaara2baa732022-02-04 16:09:54 +000068 any function. *E1142*
69 This will not work when called from a :def function, because
70 variables on the stack will be freed.
Bram Moolenaared997ad2019-07-21 16:42:00 +020071
72
73test_garbagecollect_soon() *test_garbagecollect_soon()*
74 Set the flag to call the garbagecollector as if in the main
75 loop. Only to be used in tests.
76
77
78test_getvalue({name}) *test_getvalue()*
79 Get the value of an internal variable. These values for
80 {name} are supported:
81 need_fileinfo
82
Bram Moolenaarce90e362019-09-08 18:58:44 +020083 Can also be used as a |method|: >
84 GetName()->test_getvalue()
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +020085<
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +000086 *test_gui_event()*
87test_gui_event({event}, {args})
88 Generate a GUI {event} with arguments {args} for testing Vim
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +000089 functionality. This function works only when the GUI is
90 running.
Bram Moolenaar22863042021-10-16 15:23:36 +010091
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +000092 {event} is a String and the supported values are:
93 "dropfiles" drop one or more files in a window.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010094 "findrepl" search and replace text.
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +000095 "mouse" mouse button click event.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010096 "scrollbar" move or drag the scrollbar.
Christopher Plewright20b795e2022-12-20 20:01:58 +000097 "key" send a low-level keyboard event.
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +000098 "tabline" select a tab page by mouse click.
99 "tabmenu" select a tabline menu entry.
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +0200100
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000101 {args} is a Dict and contains the arguments for the event.
102
103 "dropfiles":
104 Drop one or more files in a specified window. The supported
105 items in {args} are:
106 files: List of file names
107 row: window row number
108 col: window column number
109 modifiers: key modifiers. The supported values are:
110 0x4 Shift
111 0x8 Alt
112 0x10 Ctrl
113 The files are added to the |argument-list| and the first
114 file in {files} is edited in the window. See |drag-n-drop|
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +0000115 for more information. This event works only when the
116 |drop_file| feature is present.
117
118 "findrepl":
Bram Moolenaara2baa732022-02-04 16:09:54 +0000119 {only available when the GUI has a find/replace dialog}
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +0000120 Perform a search and replace of text. The supported items
121 in {args} are:
122 find_text: string to find.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +0100123 repl_text: replacement string.
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +0000124 flags: flags controlling the find/replace. Supported
125 values are:
126 1 search next string (find dialog)
127 2 search next string (replace dialog)
128 3 replace string once
129 4 replace all matches
130 8 match whole words only
131 16 match case
132 forward: set to 1 for forward search.
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000133
134 "mouse":
Ernie Raelc4cb5442022-04-03 15:47:28 +0100135 Inject either a mouse button click, or a mouse move, event.
136 The supported items in {args} are:
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000137 button: mouse button. The supported values are:
Bram Moolenaar86b48162022-12-06 18:20:10 +0000138 0 left mouse button
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000139 1 middle mouse button
Bram Moolenaar86b48162022-12-06 18:20:10 +0000140 2 right mouse button
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000141 3 mouse button release
142 4 scroll wheel down
143 5 scroll wheel up
144 6 scroll wheel left
145 7 scroll wheel right
146 row: mouse click row number. The first row of the
147 Vim window is 1 and the last row is 'lines'.
148 col: mouse click column number. The maximum value
149 of {col} is 'columns'.
150 multiclick: set to 1 to inject a multiclick mouse event.
151 modifiers: key modifiers. The supported values are:
152 4 shift is pressed
153 8 alt is pressed
154 16 ctrl is pressed
Ernie Raelc4cb5442022-04-03 15:47:28 +0100155 move: Optional; if used and TRUE then a mouse move
156 event can be generated.
157 Only {args} row: and col: are used and
Bram Moolenaar7add8d32022-05-16 15:27:46 +0100158 required; they are interpreted as pixels or
159 screen cells, depending on "cell".
Ernie Raelc4cb5442022-04-03 15:47:28 +0100160 Only results in an event when 'mousemoveevent'
161 is set or a popup uses mouse move events.
Bram Moolenaar7add8d32022-05-16 15:27:46 +0100162 cell: Optional: when present and TRUE then "move"
163 uses screen cells instead of pixel positions
Ernie Raelc4cb5442022-04-03 15:47:28 +0100164
165 "scrollbar":
166 Set or drag the left, right or horizontal scrollbar. Only
167 works when the scrollbar actually exists. The supported
168 items in {args} are:
169 which: scrollbar. The supported values are:
170 left Left scrollbar of the current window
171 right Right scrollbar of the current window
172 hor Horizontal scrollbar
173 value: amount to scroll. For the vertical scrollbars
174 the value can be 1 to the line-count of the
175 buffer. For the horizontal scrollbar the
176 value can be between 1 and the maximum line
177 length, assuming 'wrap' is not set.
178 dragging: 1 to drag the scrollbar and 0 to click in the
179 scrollbar.
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000180
Christopher Plewright20b795e2022-12-20 20:01:58 +0000181 "key":
182 Send a low-level keyboard event (e.g. key-up or down).
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +0100183 Currently only supported on MS-Windows.
184 The supported items in {args} are:
185 event: The supported string values are:
186 keyup generate a keyup event
187 keydown generate a keydown event
188 keycode: Keycode to use for a keyup or a keydown event.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +0100189 *E1291*
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +0100190
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000191 "tabline":
192 Inject a mouse click event on the tabline to select a
193 tabpage. The supported items in {args} are:
194 tabnr: tab page number
195
196 "tabmenu":
197 Inject an event to select a tabline menu entry. The
198 supported items in {args} are:
199 tabnr: tab page number
200 item: tab page menu item number. 1 for the first
201 menu item, 2 for the second item and so on.
202
203 After injecting the GUI events you probably should call
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200204 |feedkeys()| to have them processed, e.g.: >
205 call feedkeys("y", 'Lx!')
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000206<
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +0000207 Returns TRUE if the event is successfully added, FALSE if
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000208 there is a failure.
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +0000209
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000210 Can also be used as a |method|: >
211 GetEvent()->test_gui_event({args})
212<
Bram Moolenaared997ad2019-07-21 16:42:00 +0200213test_ignore_error({expr}) *test_ignore_error()*
214 Ignore any error containing {expr}. A normal message is given
215 instead.
216 This is only meant to be used in tests, where catching the
217 error with try/catch cannot be used (because it skips over
218 following code).
219 {expr} is used literally, not as a pattern.
220 When the {expr} is the string "RESET" then the list of ignored
221 errors is made empty.
222
Bram Moolenaarce90e362019-09-08 18:58:44 +0200223 Can also be used as a |method|: >
224 GetErrorText()->test_ignore_error()
Bram Moolenaared997ad2019-07-21 16:42:00 +0200225
Christopher Plewright20b795e2022-12-20 20:01:58 +0000226
227test_mswin_event({event}, {args}) *test_mswin_event()*
228 Generate a low-level MS-Windows {event} with arguments {args}
229 for testing Vim functionality. It works for MS-Windows GUI
230 and for the console.
231
232 {event} is a String and the supported values are:
233 "mouse" mouse event.
234 "key" keyboard event.
235
236 "mouse":
237 Inject either a mouse button click, or a mouse move, event.
238 The supported items in {args} are:
239 button: mouse button. The supported values are:
240 0 right mouse button
241 1 middle mouse button
242 2 left mouse button
243 3 mouse button release
244 4 scroll wheel down
245 5 scroll wheel up
246 6 scroll wheel left
247 7 scroll wheel right
248 row: mouse click row number. The first row of the
249 Vim window is 1 and the last row is 'lines'.
250 col: mouse click column number. The maximum value
251 of {col} is 'columns'.
252 Note: row and col are always interpreted as
253 screen cells for the console application.
254 But, they may be interpreted as pixels
255 for the GUI, depending on "cell".
256 multiclick: set to 1 to inject a double-click mouse event.
257 modifiers: key modifiers. The supported values are:
258 4 shift is pressed
259 8 alt is pressed
260 16 ctrl is pressed
261 move: Optional; if used and TRUE then a mouse move
262 event can be generated.
263 Only {args} row: and col: are used and
264 required.
265 Only results in an event when 'mousemoveevent'
266 is set or a popup uses mouse move events.
267 cell: Optional for the GUI: when present and TRUE
268 then "move" uses screen cells instead of pixel
269 positions. Not used by the console.
270
271 "key":
272 Send a low-level keyboard event (e.g. keyup or keydown).
273 The supported items in {args} are:
274 event: The supported string values are:
275 keyup generate a keyup event
276 keydown generate a keydown event
277 keycode: Keycode to use for a keyup or a keydown event.
278 modifiers: Optional; key modifiers.
279 The supported values are:
280 2 shift is pressed
281 4 ctrl is pressed
282 8 alt is pressed
283 Note: These values are different from the
284 mouse modifiers.
285 *E1291*
286 Returns TRUE if the event is successfully added, FALSE if
287 there is a failure.
288
289 Can also be used as a |method|: >
290 GetEvent()->test_mswin_event({args})
291<
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200292
Bram Moolenaared997ad2019-07-21 16:42:00 +0200293test_null_blob() *test_null_blob()*
294 Return a |Blob| that is null. Only useful for testing.
295
296
297test_null_channel() *test_null_channel()*
298 Return a |Channel| that is null. Only useful for testing.
299 {only available when compiled with the +channel feature}
300
301
302test_null_dict() *test_null_dict()*
303 Return a |Dict| that is null. Only useful for testing.
304
305
Bram Moolenaare69f6d02020-04-01 22:11:01 +0200306test_null_function() *test_null_function()*
Bram Moolenaard1caa942020-04-10 22:10:56 +0200307 Return a |Funcref| that is null. Only useful for testing.
Bram Moolenaare69f6d02020-04-01 22:11:01 +0200308
309
Bram Moolenaared997ad2019-07-21 16:42:00 +0200310test_null_job() *test_null_job()*
311 Return a |Job| that is null. Only useful for testing.
312 {only available when compiled with the +job feature}
313
314
315test_null_list() *test_null_list()*
316 Return a |List| that is null. Only useful for testing.
317
318
319test_null_partial() *test_null_partial()*
320 Return a |Partial| that is null. Only useful for testing.
321
322
323test_null_string() *test_null_string()*
324 Return a |String| that is null. Only useful for testing.
325
326
327test_option_not_set({name}) *test_option_not_set()*
328 Reset the flag that indicates option {name} was set. Thus it
329 looks like it still has the default value. Use like this: >
330 set ambiwidth=double
331 call test_option_not_set('ambiwidth')
332< Now the 'ambiwidth' option behaves like it was never changed,
333 even though the value is "double".
334 Only to be used for testing!
335
Bram Moolenaarce90e362019-09-08 18:58:44 +0200336 Can also be used as a |method|: >
337 GetOptionName()->test_option_not_set()
338
Bram Moolenaared997ad2019-07-21 16:42:00 +0200339
340test_override({name}, {val}) *test_override()*
341 Overrides certain parts of Vim's internal processing to be able
342 to run tests. Only to be used for testing Vim!
343 The override is enabled when {val} is non-zero and removed
344 when {val} is zero.
Bram Moolenaar3e4fa3d2022-01-13 22:05:09 +0000345 Current supported values for {name} are:
Bram Moolenaared997ad2019-07-21 16:42:00 +0200346
Bram Moolenaar3e4fa3d2022-01-13 22:05:09 +0000347 {name} effect when {val} is non-zero ~
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100348 alloc_lines make a copy of every buffer line into allocated
349 memory, so that memory access errors can be found
350 by valgrind
Bram Moolenaar3e4fa3d2022-01-13 22:05:09 +0000351 autoload `import autoload` will load the script right
352 away, not postponed until an item is used
Bram Moolenaared997ad2019-07-21 16:42:00 +0200353 char_avail disable the char_avail() function
Bram Moolenaared997ad2019-07-21 16:42:00 +0200354 nfa_fail makes the NFA regexp engine fail to force a
355 fallback to the old engine
356 no_query_mouse do not query the mouse position for "dec"
357 terminals
358 no_wait_return set the "no_wait_return" flag. Not restored
359 with "ALL".
Bram Moolenaar3e4fa3d2022-01-13 22:05:09 +0000360 redraw disable the redrawing() function
361 redraw_flag ignore the RedrawingDisabled flag
362 starting reset the "starting" variable, see below
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +0200363 term_props reset all terminal properties when the version
364 string is detected
Bram Moolenaar3e4fa3d2022-01-13 22:05:09 +0000365 ui_delay time in msec to use in ui_delay(); overrules a
366 wait time of up to 3 seconds for messages
Bram Moolenaarc8cdf0f2021-03-13 13:28:13 +0100367 uptime overrules sysinfo.uptime
ichizokae1bd872022-01-20 14:57:29 +0000368 vterm_title setting the window title by a job running in a
369 terminal window
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100370 ALL clear all overrides, except alloc_lines ({val} is
371 not used)
Bram Moolenaared997ad2019-07-21 16:42:00 +0200372
373 "starting" is to be used when a test should behave like
374 startup was done. Since the tests are run by sourcing a
375 script the "starting" variable is non-zero. This is usually a
376 good thing (tests run faster), but sometimes changes behavior
377 in a way that the test doesn't work properly.
378 When using: >
379 call test_override('starting', 1)
380< The value of "starting" is saved. It is restored by: >
381 call test_override('starting', 0)
382
Bram Moolenaarce90e362019-09-08 18:58:44 +0200383< Can also be used as a |method|: >
384 GetOverrideVal()-> test_override('starting')
Bram Moolenaared997ad2019-07-21 16:42:00 +0200385
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200386
Bram Moolenaared997ad2019-07-21 16:42:00 +0200387test_refcount({expr}) *test_refcount()*
388 Return the reference count of {expr}. When {expr} is of a
389 type that does not have a reference count, returns -1. Only
390 to be used for testing.
391
Bram Moolenaarce90e362019-09-08 18:58:44 +0200392 Can also be used as a |method|: >
393 GetVarname()->test_refcount()
394
Bram Moolenaared997ad2019-07-21 16:42:00 +0200395
Bram Moolenaared997ad2019-07-21 16:42:00 +0200396test_setmouse({row}, {col}) *test_setmouse()*
397 Set the mouse position to be used for the next mouse action.
398 {row} and {col} are one based.
399 For example: >
400 call test_setmouse(4, 20)
401 call feedkeys("\<LeftMouse>", "xt")
402
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200403
Bram Moolenaared997ad2019-07-21 16:42:00 +0200404test_settime({expr}) *test_settime()*
405 Set the time Vim uses internally. Currently only used for
406 timestamps in the history, as they are used in viminfo, and
407 for undo.
408 Using a value of 1 makes Vim not sleep after a warning or
409 error message.
410 {expr} must evaluate to a number. When the value is zero the
411 normal behavior is restored.
412
Bram Moolenaarce90e362019-09-08 18:58:44 +0200413 Can also be used as a |method|: >
414 GetTime()->test_settime()
415
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200416
Bram Moolenaar4f645c52020-02-08 16:40:39 +0100417test_srand_seed([seed]) *test_srand_seed()*
418 When [seed] is given this sets the seed value used by
419 `srand()`. When omitted the test seed is removed.
420
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200421
422test_unknown() *test_unknown()*
423 Return a value with unknown type. Only useful for testing.
424
425
426test_void() *test_void()*
427 Return a value with void type. Only useful for testing.
428
Bram Moolenaared997ad2019-07-21 16:42:00 +0200429==============================================================================
Bram Moolenaar54775062019-07-31 21:07:14 +02004303. Assert functions *assert-functions-details*
Bram Moolenaared997ad2019-07-21 16:42:00 +0200431
432
433assert_beeps({cmd}) *assert_beeps()*
434 Run {cmd} and add an error message to |v:errors| if it does
435 NOT produce a beep or visual bell.
Bram Moolenaar5b8cabf2021-04-02 18:55:57 +0200436 Also see |assert_fails()|, |assert_nobeep()| and
437 |assert-return|.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200438
Bram Moolenaar24278d22019-08-16 21:49:22 +0200439 Can also be used as a |method|: >
440 GetCmd()->assert_beeps()
441<
Bram Moolenaared997ad2019-07-21 16:42:00 +0200442 *assert_equal()*
443assert_equal({expected}, {actual} [, {msg}])
444 When {expected} and {actual} are not equal an error message is
445 added to |v:errors| and 1 is returned. Otherwise zero is
446 returned |assert-return|.
447 There is no automatic conversion, the String "4" is different
448 from the Number 4. And the number 4 is different from the
449 Float 4.0. The value of 'ignorecase' is not used here, case
450 always matters.
451 When {msg} is omitted an error in the form "Expected
452 {expected} but got {actual}" is produced.
453 Example: >
454 assert_equal('foo', 'bar')
455< Will result in a string to be added to |v:errors|:
456 test.vim line 12: Expected 'foo' but got 'bar' ~
457
Bram Moolenaar7ff78462020-07-10 22:00:53 +0200458 Can also be used as a |method|, the base is passed as the
459 second argument: >
Bram Moolenaar25e42232019-08-04 15:04:10 +0200460 mylist->assert_equal([1, 2, 3])
461
Bram Moolenaar25e42232019-08-04 15:04:10 +0200462< *assert_equalfile()*
Bram Moolenaarfb517ba2020-06-03 19:55:35 +0200463assert_equalfile({fname-one}, {fname-two} [, {msg}])
Bram Moolenaared997ad2019-07-21 16:42:00 +0200464 When the files {fname-one} and {fname-two} do not contain
465 exactly the same text an error message is added to |v:errors|.
466 Also see |assert-return|.
467 When {fname-one} or {fname-two} does not exist the error will
468 mention that.
469 Mainly useful with |terminal-diff|.
470
Bram Moolenaare49fbff2019-08-21 22:50:07 +0200471 Can also be used as a |method|: >
472 GetLog()->assert_equalfile('expected.log')
473
Bram Moolenaared997ad2019-07-21 16:42:00 +0200474assert_exception({error} [, {msg}]) *assert_exception()*
475 When v:exception does not contain the string {error} an error
476 message is added to |v:errors|. Also see |assert-return|.
477 This can be used to assert that a command throws an exception.
478 Using the error number, followed by a colon, avoids problems
479 with translations: >
480 try
481 commandthatfails
482 call assert_false(1, 'command should have failed')
483 catch
484 call assert_exception('E492:')
485 endtry
Bram Moolenaar1d634542020-08-18 13:41:50 +0200486<
487 *assert_fails()*
Bram Moolenaar9bd5d872020-09-06 21:47:48 +0200488assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
Bram Moolenaared997ad2019-07-21 16:42:00 +0200489 Run {cmd} and add an error message to |v:errors| if it does
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200490 NOT produce an error or when {error} is not found in the
491 error message. Also see |assert-return|.
Bram Moolenaar6f4754b2022-01-23 12:07:04 +0000492 *E856*
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200493 When {error} is a string it must be found literally in the
494 first reported error. Most often this will be the error code,
495 including the colon, e.g. "E123:". >
496 assert_fails('bad cmd', 'E987:')
497<
498 When {error} is a |List| with one or two strings, these are
499 used as patterns. The first pattern is matched against the
500 first reported error: >
501 assert_fails('cmd', ['E987:.*expected bool'])
502< The second pattern, if present, is matched against the last
Bram Moolenaar4072ba52020-12-23 13:56:35 +0100503 reported error.
504 If there is only one error then both patterns must match. This
505 can be used to check that there is only one error.
506 To only match the last error use an empty string for the first
507 error: >
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200508 assert_fails('cmd', ['', 'E987:'])
509<
Bram Moolenaar1d634542020-08-18 13:41:50 +0200510 If {msg} is empty then it is not used. Do this to get the
511 default message when passing the {lnum} argument.
Bram Moolenaarf10911e2022-01-29 22:20:48 +0000512 *E1115*
Bram Moolenaar1d634542020-08-18 13:41:50 +0200513 When {lnum} is present and not negative, and the {error}
514 argument is present and matches, then this is compared with
515 the line number at which the error was reported. That can be
516 the line number in a function or in a script.
Bram Moolenaarf10911e2022-01-29 22:20:48 +0000517 *E1116*
Bram Moolenaar9bd5d872020-09-06 21:47:48 +0200518 When {context} is present it is used as a pattern and matched
519 against the context (script name or function name) where
520 {lnum} is located in.
521
Bram Moolenaared997ad2019-07-21 16:42:00 +0200522 Note that beeping is not considered an error, and some failing
523 commands only beep. Use |assert_beeps()| for those.
524
Bram Moolenaar24278d22019-08-16 21:49:22 +0200525 Can also be used as a |method|: >
526 GetCmd()->assert_fails('E99:')
527
Bram Moolenaar1d634542020-08-18 13:41:50 +0200528assert_false({actual} [, {msg}]) *assert_false()*
Bram Moolenaared997ad2019-07-21 16:42:00 +0200529 When {actual} is not false an error message is added to
530 |v:errors|, like with |assert_equal()|.
531 Also see |assert-return|.
532 A value is false when it is zero. When {actual} is not a
533 number the assert fails.
534 When {msg} is omitted an error in the form
535 "Expected False but got {actual}" is produced.
536
Bram Moolenaar24278d22019-08-16 21:49:22 +0200537 Can also be used as a |method|: >
538 GetResult()->assert_false()
539
Bram Moolenaared997ad2019-07-21 16:42:00 +0200540assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
541 This asserts number and |Float| values. When {actual} is lower
542 than {lower} or higher than {upper} an error message is added
543 to |v:errors|. Also see |assert-return|.
544 When {msg} is omitted an error in the form
545 "Expected range {lower} - {upper}, but got {actual}" is
546 produced.
547
548 *assert_match()*
549assert_match({pattern}, {actual} [, {msg}])
550 When {pattern} does not match {actual} an error message is
551 added to |v:errors|. Also see |assert-return|.
552
553 {pattern} is used as with |=~|: The matching is always done
554 like 'magic' was set and 'cpoptions' is empty, no matter what
555 the actual value of 'magic' or 'cpoptions' is.
556
557 {actual} is used as a string, automatic conversion applies.
558 Use "^" and "$" to match with the start and end of the text.
559 Use both to match the whole text.
560
561 When {msg} is omitted an error in the form
562 "Pattern {pattern} does not match {actual}" is produced.
563 Example: >
564 assert_match('^f.*o$', 'foobar')
565< Will result in a string to be added to |v:errors|:
566 test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~
567
Bram Moolenaar24278d22019-08-16 21:49:22 +0200568 Can also be used as a |method|: >
569 getFile()->assert_match('foo.*')
570<
Bram Moolenaar5b8cabf2021-04-02 18:55:57 +0200571assert_nobeep({cmd}) *assert_nobeep()*
572 Run {cmd} and add an error message to |v:errors| if it
573 produces a beep or visual bell.
574 Also see |assert_beeps()|.
575
576 Can also be used as a |method|: >
577 GetCmd()->assert_nobeep()
578<
Bram Moolenaared997ad2019-07-21 16:42:00 +0200579 *assert_notequal()*
580assert_notequal({expected}, {actual} [, {msg}])
581 The opposite of `assert_equal()`: add an error message to
582 |v:errors| when {expected} and {actual} are equal.
583 Also see |assert-return|.
584
Bram Moolenaar25e42232019-08-04 15:04:10 +0200585 Can also be used as a |method|: >
586 mylist->assert_notequal([1, 2, 3])
587
588< *assert_notmatch()*
Bram Moolenaared997ad2019-07-21 16:42:00 +0200589assert_notmatch({pattern}, {actual} [, {msg}])
590 The opposite of `assert_match()`: add an error message to
591 |v:errors| when {pattern} matches {actual}.
592 Also see |assert-return|.
593
Bram Moolenaar24278d22019-08-16 21:49:22 +0200594 Can also be used as a |method|: >
595 getFile()->assert_notmatch('bar.*')
596
Bram Moolenaare49fbff2019-08-21 22:50:07 +0200597
Bram Moolenaared997ad2019-07-21 16:42:00 +0200598assert_report({msg}) *assert_report()*
Bram Moolenaar6aa57292021-08-14 21:25:52 +0200599 Report a test failure directly, using String {msg}.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200600 Always returns one.
601
Bram Moolenaare49fbff2019-08-21 22:50:07 +0200602 Can also be used as a |method|: >
603 GetMessage()->assert_report()
604
605
Bram Moolenaared997ad2019-07-21 16:42:00 +0200606assert_true({actual} [, {msg}]) *assert_true()*
607 When {actual} is not true an error message is added to
608 |v:errors|, like with |assert_equal()|.
609 Also see |assert-return|.
610 A value is TRUE when it is a non-zero number. When {actual}
611 is not a number the assert fails.
612 When {msg} is omitted an error in the form "Expected True but
613 got {actual}" is produced.
614
Bram Moolenaar24278d22019-08-16 21:49:22 +0200615 Can also be used as a |method|: >
616 GetResult()->assert_true()
617<
Bram Moolenaared997ad2019-07-21 16:42:00 +0200618
619 vim:tw=78:ts=8:noet:ft=help:norl: