blob: ebf562bef4836ae1fd7d65d12ad18b015f8da19f [file] [log] [blame]
h-east84ac2122024-06-17 18:12:30 +02001*testing.txt* For Vim version 9.1. Last change: 2024 Jun 17
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:
RestorerZac9c6d52023-10-05 22:25:12 +020024 test20.in oldest, only for tiny builds
Bram Moolenaarb96a32e2020-08-13 18:59:55 +020025 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()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020048<
49 Return type: |Number|
Bram Moolenaared997ad2019-07-21 16:42:00 +020050
Bram Moolenaar89a9c152021-08-29 21:55:35 +020051
Bram Moolenaared997ad2019-07-21 16:42:00 +020052test_autochdir() *test_autochdir()*
53 Set a flag to enable the effect of 'autochdir' before Vim
54 startup has finished.
55
Christian Brabandt5674c9a2024-06-09 00:13:43 +020056 Return type: |Number|
57
Bram Moolenaared997ad2019-07-21 16:42:00 +020058
59test_feedinput({string}) *test_feedinput()*
60 Characters in {string} are queued for processing as if they
61 were typed by the user. This uses a low level input buffer.
62 This function works only when with |+unix| or GUI is running.
63
Bram Moolenaarce90e362019-09-08 18:58:44 +020064 Can also be used as a |method|: >
65 GetText()->test_feedinput()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020066<
67 Return type: |Number|
Bram Moolenaared997ad2019-07-21 16:42:00 +020068
Bram Moolenaar89a9c152021-08-29 21:55:35 +020069
Bram Moolenaared997ad2019-07-21 16:42:00 +020070test_garbagecollect_now() *test_garbagecollect_now()*
71 Like garbagecollect(), but executed right away. This must
72 only be called directly to avoid any structure to exist
73 internally, and |v:testing| must have been set before calling
Bram Moolenaara2baa732022-02-04 16:09:54 +000074 any function. *E1142*
75 This will not work when called from a :def function, because
76 variables on the stack will be freed.
Bram Moolenaared997ad2019-07-21 16:42:00 +020077
Christian Brabandt5674c9a2024-06-09 00:13:43 +020078 Return type: |Number|
Bram Moolenaared997ad2019-07-21 16:42:00 +020079
80test_garbagecollect_soon() *test_garbagecollect_soon()*
81 Set the flag to call the garbagecollector as if in the main
82 loop. Only to be used in tests.
83
Christian Brabandt5674c9a2024-06-09 00:13:43 +020084 Return type: |Number|
Bram Moolenaared997ad2019-07-21 16:42:00 +020085
86test_getvalue({name}) *test_getvalue()*
87 Get the value of an internal variable. These values for
88 {name} are supported:
89 need_fileinfo
90
Bram Moolenaarce90e362019-09-08 18:58:44 +020091 Can also be used as a |method|: >
92 GetName()->test_getvalue()
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +020093<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020094 Return type: |Number|
95
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +000096 *test_gui_event()*
97test_gui_event({event}, {args})
98 Generate a GUI {event} with arguments {args} for testing Vim
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +000099 functionality. This function works only when the GUI is
100 running.
Bram Moolenaar22863042021-10-16 15:23:36 +0100101
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000102 {event} is a String and the supported values are:
103 "dropfiles" drop one or more files in a window.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +0100104 "findrepl" search and replace text.
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000105 "mouse" mouse button click event.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +0100106 "scrollbar" move or drag the scrollbar.
Christopher Plewright20b795e2022-12-20 20:01:58 +0000107 "key" send a low-level keyboard event.
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000108 "tabline" select a tab page by mouse click.
109 "tabmenu" select a tabline menu entry.
Yegappan Lakshmanan18d46582021-06-23 20:46:52 +0200110
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000111 {args} is a Dict and contains the arguments for the event.
112
113 "dropfiles":
114 Drop one or more files in a specified window. The supported
115 items in {args} are:
116 files: List of file names
117 row: window row number
118 col: window column number
119 modifiers: key modifiers. The supported values are:
120 0x4 Shift
121 0x8 Alt
122 0x10 Ctrl
123 The files are added to the |argument-list| and the first
124 file in {files} is edited in the window. See |drag-n-drop|
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +0000125 for more information. This event works only when the
126 |drop_file| feature is present.
127
128 "findrepl":
Bram Moolenaara2baa732022-02-04 16:09:54 +0000129 {only available when the GUI has a find/replace dialog}
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +0000130 Perform a search and replace of text. The supported items
131 in {args} are:
132 find_text: string to find.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +0100133 repl_text: replacement string.
Yegappan Lakshmananec3637c2022-01-30 18:01:24 +0000134 flags: flags controlling the find/replace. Supported
135 values are:
136 1 search next string (find dialog)
137 2 search next string (replace dialog)
138 3 replace string once
139 4 replace all matches
140 8 match whole words only
141 16 match case
142 forward: set to 1 for forward search.
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000143
144 "mouse":
Ernie Raelc4cb5442022-04-03 15:47:28 +0100145 Inject either a mouse button click, or a mouse move, event.
146 The supported items in {args} are:
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000147 button: mouse button. The supported values are:
Bram Moolenaar86b48162022-12-06 18:20:10 +0000148 0 left mouse button
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000149 1 middle mouse button
Bram Moolenaar86b48162022-12-06 18:20:10 +0000150 2 right mouse button
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000151 3 mouse button release
152 4 scroll wheel down
153 5 scroll wheel up
154 6 scroll wheel left
155 7 scroll wheel right
156 row: mouse click row number. The first row of the
157 Vim window is 1 and the last row is 'lines'.
158 col: mouse click column number. The maximum value
159 of {col} is 'columns'.
160 multiclick: set to 1 to inject a multiclick mouse event.
161 modifiers: key modifiers. The supported values are:
162 4 shift is pressed
163 8 alt is pressed
164 16 ctrl is pressed
Ernie Raelc4cb5442022-04-03 15:47:28 +0100165 move: Optional; if used and TRUE then a mouse move
166 event can be generated.
167 Only {args} row: and col: are used and
Bram Moolenaar7add8d32022-05-16 15:27:46 +0100168 required; they are interpreted as pixels or
169 screen cells, depending on "cell".
Ernie Raelc4cb5442022-04-03 15:47:28 +0100170 Only results in an event when 'mousemoveevent'
171 is set or a popup uses mouse move events.
Bram Moolenaar7add8d32022-05-16 15:27:46 +0100172 cell: Optional: when present and TRUE then "move"
173 uses screen cells instead of pixel positions
Ernie Raelc4cb5442022-04-03 15:47:28 +0100174
175 "scrollbar":
176 Set or drag the left, right or horizontal scrollbar. Only
177 works when the scrollbar actually exists. The supported
178 items in {args} are:
Bram Moolenaar10e8ff92023-06-10 21:40:39 +0100179 which: Selects the scrollbar. The supported values
180 are:
Ernie Raelc4cb5442022-04-03 15:47:28 +0100181 left Left scrollbar of the current window
182 right Right scrollbar of the current window
183 hor Horizontal scrollbar
Bram Moolenaar10e8ff92023-06-10 21:40:39 +0100184 value: Amount to scroll. For the vertical scrollbars
185 the value can be between 0 to the line-count
186 of the buffer minus one. For the horizontal
187 scrollbar the value can be between 1 and the
188 maximum line length, assuming 'wrap' is not
189 set.
Ernie Raelc4cb5442022-04-03 15:47:28 +0100190 dragging: 1 to drag the scrollbar and 0 to click in the
191 scrollbar.
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000192
Christopher Plewright20b795e2022-12-20 20:01:58 +0000193 "key":
194 Send a low-level keyboard event (e.g. key-up or down).
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +0100195 Currently only supported on MS-Windows.
196 The supported items in {args} are:
197 event: The supported string values are:
198 keyup generate a keyup event
199 keydown generate a keydown event
200 keycode: Keycode to use for a keyup or a keydown event.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +0100201 *E1291*
Yegappan Lakshmanan81a3ff92022-07-23 05:04:16 +0100202
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000203 "tabline":
204 Inject a mouse click event on the tabline to select a
205 tabpage. The supported items in {args} are:
206 tabnr: tab page number
207
208 "tabmenu":
209 Inject an event to select a tabline menu entry. The
210 supported items in {args} are:
211 tabnr: tab page number
Bram Moolenaar938ae282023-02-20 20:44:55 +0000212 item: tab page menu item number. 1 for the first
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000213 menu item, 2 for the second item and so on.
214
215 After injecting the GUI events you probably should call
Yegappan Lakshmananf1e74492021-06-21 18:44:26 +0200216 |feedkeys()| to have them processed, e.g.: >
217 call feedkeys("y", 'Lx!')
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000218<
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +0000219 Returns TRUE if the event is successfully added, FALSE if
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000220 there is a failure.
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +0000221
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000222 Can also be used as a |method|: >
223 GetEvent()->test_gui_event({args})
224<
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200225 Return type: |vim9-boolean|
226
Bram Moolenaared997ad2019-07-21 16:42:00 +0200227test_ignore_error({expr}) *test_ignore_error()*
228 Ignore any error containing {expr}. A normal message is given
229 instead.
230 This is only meant to be used in tests, where catching the
231 error with try/catch cannot be used (because it skips over
232 following code).
233 {expr} is used literally, not as a pattern.
234 When the {expr} is the string "RESET" then the list of ignored
235 errors is made empty.
236
Bram Moolenaarce90e362019-09-08 18:58:44 +0200237 Can also be used as a |method|: >
238 GetErrorText()->test_ignore_error()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200239<
240 Return type: |Number|
Bram Moolenaarbe4e0162023-02-02 13:59:48 +0000241
Christopher Plewright20b795e2022-12-20 20:01:58 +0000242test_mswin_event({event}, {args}) *test_mswin_event()*
243 Generate a low-level MS-Windows {event} with arguments {args}
Bram Moolenaarbe4e0162023-02-02 13:59:48 +0000244 for testing Vim functionality. It works for MS-Windows GUI
Christopher Plewright20b795e2022-12-20 20:01:58 +0000245 and for the console.
Bram Moolenaarbe4e0162023-02-02 13:59:48 +0000246
Christopher Plewright20b795e2022-12-20 20:01:58 +0000247 {event} is a String and the supported values are:
248 "mouse" mouse event.
249 "key" keyboard event.
Anton Sharonov68d94722024-01-23 23:19:02 +0100250 "set_keycode_trans_strategy"
h_east026b1742024-02-19 02:51:46 +0900251 Change the key translation method.
Christopher Plewright20b795e2022-12-20 20:01:58 +0000252
253 "mouse":
254 Inject either a mouse button click, or a mouse move, event.
255 The supported items in {args} are:
256 button: mouse button. The supported values are:
257 0 right mouse button
258 1 middle mouse button
259 2 left mouse button
260 3 mouse button release
261 4 scroll wheel down
262 5 scroll wheel up
263 6 scroll wheel left
264 7 scroll wheel right
265 row: mouse click row number. The first row of the
266 Vim window is 1 and the last row is 'lines'.
267 col: mouse click column number. The maximum value
268 of {col} is 'columns'.
269 Note: row and col are always interpreted as
270 screen cells for the console application.
271 But, they may be interpreted as pixels
272 for the GUI, depending on "cell".
273 multiclick: set to 1 to inject a double-click mouse event.
274 modifiers: key modifiers. The supported values are:
275 4 shift is pressed
276 8 alt is pressed
277 16 ctrl is pressed
278 move: Optional; if used and TRUE then a mouse move
279 event can be generated.
280 Only {args} row: and col: are used and
281 required.
282 Only results in an event when 'mousemoveevent'
283 is set or a popup uses mouse move events.
284 cell: Optional for the GUI: when present and TRUE
285 then "move" uses screen cells instead of pixel
286 positions. Not used by the console.
287
288 "key":
289 Send a low-level keyboard event (e.g. keyup or keydown).
290 The supported items in {args} are:
291 event: The supported string values are:
292 keyup generate a keyup event
293 keydown generate a keydown event
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000294 keycode: Keycode to use for a keyup or a keydown event.
Christopher Plewright20b795e2022-12-20 20:01:58 +0000295 modifiers: Optional; key modifiers.
296 The supported values are:
297 2 shift is pressed
298 4 ctrl is pressed
299 8 alt is pressed
300 Note: These values are different from the
301 mouse modifiers.
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000302 execute: Optional. Similar to |feedkeys()| mode x.
303 When this is included and set to true
304 (non-zero) then Vim will process any buffered
305 unprocessed key events. All other {args}
306 items are optional when this is set and true.
307
Anton Sharonov68d94722024-01-23 23:19:02 +0100308 "set_keycode_trans_strategy":
309 |w32-experimental-keycode-trans-strategy|
h_east026b1742024-02-19 02:51:46 +0900310 Switch the keycode translation method. The supported methods
311 are:
Anton Sharonov68d94722024-01-23 23:19:02 +0100312 experimental: The method used after Patch v8.2.4807
313 using ToUnicode() Win API call.
314 classic: The method used pre Patch v8.2.4807
315 using the TranslateMessage() Win API call.
316
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000317 Returns TRUE if the event is successfully added or executed,
318 FALSE if there is a failure.
Christopher Plewright20b795e2022-12-20 20:01:58 +0000319
320 Can also be used as a |method|: >
321 GetEvent()->test_mswin_event({args})
322<
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200323 Return type: |vim9-boolean|
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200324
Bram Moolenaared997ad2019-07-21 16:42:00 +0200325test_null_blob() *test_null_blob()*
326 Return a |Blob| that is null. Only useful for testing.
327
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200328 Return type: |Blob|
Bram Moolenaared997ad2019-07-21 16:42:00 +0200329
330test_null_channel() *test_null_channel()*
331 Return a |Channel| that is null. Only useful for testing.
332 {only available when compiled with the +channel feature}
333
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200334 Return type: |Channel|
Bram Moolenaared997ad2019-07-21 16:42:00 +0200335
336test_null_dict() *test_null_dict()*
337 Return a |Dict| that is null. Only useful for testing.
338
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200339 Return type: dict<any>
Bram Moolenaared997ad2019-07-21 16:42:00 +0200340
Bram Moolenaare69f6d02020-04-01 22:11:01 +0200341test_null_function() *test_null_function()*
Bram Moolenaard1caa942020-04-10 22:10:56 +0200342 Return a |Funcref| that is null. Only useful for testing.
Bram Moolenaare69f6d02020-04-01 22:11:01 +0200343
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200344 Return type: func(...): unknown
Bram Moolenaare69f6d02020-04-01 22:11:01 +0200345
Bram Moolenaared997ad2019-07-21 16:42:00 +0200346test_null_job() *test_null_job()*
347 Return a |Job| that is null. Only useful for testing.
348 {only available when compiled with the +job feature}
349
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200350 Return type: |job|
Bram Moolenaared997ad2019-07-21 16:42:00 +0200351
352test_null_list() *test_null_list()*
353 Return a |List| that is null. Only useful for testing.
354
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200355 Return type: list<any>
Bram Moolenaared997ad2019-07-21 16:42:00 +0200356
357test_null_partial() *test_null_partial()*
358 Return a |Partial| that is null. Only useful for testing.
359
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200360 Return type: func(...): unknown
Bram Moolenaared997ad2019-07-21 16:42:00 +0200361
362test_null_string() *test_null_string()*
363 Return a |String| that is null. Only useful for testing.
364
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200365 Return type: |String|
Bram Moolenaared997ad2019-07-21 16:42:00 +0200366
367test_option_not_set({name}) *test_option_not_set()*
368 Reset the flag that indicates option {name} was set. Thus it
369 looks like it still has the default value. Use like this: >
370 set ambiwidth=double
371 call test_option_not_set('ambiwidth')
372< Now the 'ambiwidth' option behaves like it was never changed,
373 even though the value is "double".
374 Only to be used for testing!
375
Bram Moolenaarce90e362019-09-08 18:58:44 +0200376 Can also be used as a |method|: >
377 GetOptionName()->test_option_not_set()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200378<
379 Return type: |Number|
Bram Moolenaared997ad2019-07-21 16:42:00 +0200380
381test_override({name}, {val}) *test_override()*
382 Overrides certain parts of Vim's internal processing to be able
383 to run tests. Only to be used for testing Vim!
384 The override is enabled when {val} is non-zero and removed
385 when {val} is zero.
Bram Moolenaar3e4fa3d2022-01-13 22:05:09 +0000386 Current supported values for {name} are:
Bram Moolenaared997ad2019-07-21 16:42:00 +0200387
Bram Moolenaar3e4fa3d2022-01-13 22:05:09 +0000388 {name} effect when {val} is non-zero ~
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100389 alloc_lines make a copy of every buffer line into allocated
390 memory, so that memory access errors can be found
h-east53753f62024-05-05 18:42:31 +0200391 by valgrind.
Bram Moolenaar3e4fa3d2022-01-13 22:05:09 +0000392 autoload `import autoload` will load the script right
h-east53753f62024-05-05 18:42:31 +0200393 away, not postponed until an item is used.
394 char_avail disable the char_avail() function.
Yegappan Lakshmanan5715a722024-05-03 18:24:07 +0200395 defcompile all the |:def| functions in a sourced script are
396 compiled when defined. This is similar to using
397 the |:defcompile| command in a script.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200398 nfa_fail makes the NFA regexp engine fail to force a
h-east53753f62024-05-05 18:42:31 +0200399 fallback to the old engine.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200400 no_query_mouse do not query the mouse position for "dec"
h-east53753f62024-05-05 18:42:31 +0200401 terminals.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200402 no_wait_return set the "no_wait_return" flag. Not restored
403 with "ALL".
h-east53753f62024-05-05 18:42:31 +0200404 redraw disable the redrawing() function.
405 redraw_flag ignore the RedrawingDisabled flag.
406 starting reset the "starting" variable, see below.
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +0200407 term_props reset all terminal properties when the version
h-east53753f62024-05-05 18:42:31 +0200408 string is detected.
Bram Moolenaar3e4fa3d2022-01-13 22:05:09 +0000409 ui_delay time in msec to use in ui_delay(); overrules a
h-east53753f62024-05-05 18:42:31 +0200410 wait time of up to 3 seconds for messages.
411 unreachable no error for code after `:throw` and `:return`.
412 uptime overrules sysinfo.uptime.
ichizokae1bd872022-01-20 14:57:29 +0000413 vterm_title setting the window title by a job running in a
h-east53753f62024-05-05 18:42:31 +0200414 terminal window.
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100415 ALL clear all overrides, except alloc_lines ({val} is
h-east53753f62024-05-05 18:42:31 +0200416 not used).
Bram Moolenaared997ad2019-07-21 16:42:00 +0200417
418 "starting" is to be used when a test should behave like
419 startup was done. Since the tests are run by sourcing a
420 script the "starting" variable is non-zero. This is usually a
Bram Moolenaar9d383f32023-05-14 21:38:12 +0100421 good thing (tests run faster), but sometimes this changes
422 behavior in a way that the test doesn't work properly.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200423 When using: >
424 call test_override('starting', 1)
425< The value of "starting" is saved. It is restored by: >
426 call test_override('starting', 0)
427
Bram Moolenaar9d383f32023-05-14 21:38:12 +0100428< To make sure the flag is reset later using `:defer` can be
429 useful: >
430 call test_override('unreachable', 1)
431 defer call test_override('unreachable', 0)
432
Bram Moolenaarce90e362019-09-08 18:58:44 +0200433< Can also be used as a |method|: >
434 GetOverrideVal()-> test_override('starting')
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200435<
436 Return type: |Number|
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200437
Bram Moolenaared997ad2019-07-21 16:42:00 +0200438test_refcount({expr}) *test_refcount()*
439 Return the reference count of {expr}. When {expr} is of a
440 type that does not have a reference count, returns -1. Only
441 to be used for testing.
442
Bram Moolenaarce90e362019-09-08 18:58:44 +0200443 Can also be used as a |method|: >
444 GetVarname()->test_refcount()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200445<
446 Return type: |Number|
Bram Moolenaared997ad2019-07-21 16:42:00 +0200447
Bram Moolenaared997ad2019-07-21 16:42:00 +0200448test_setmouse({row}, {col}) *test_setmouse()*
449 Set the mouse position to be used for the next mouse action.
450 {row} and {col} are one based.
451 For example: >
452 call test_setmouse(4, 20)
453 call feedkeys("\<LeftMouse>", "xt")
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200454<
455 Return type: |Number|
Bram Moolenaared997ad2019-07-21 16:42:00 +0200456
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200457
Bram Moolenaared997ad2019-07-21 16:42:00 +0200458test_settime({expr}) *test_settime()*
459 Set the time Vim uses internally. Currently only used for
460 timestamps in the history, as they are used in viminfo, and
461 for undo.
462 Using a value of 1 makes Vim not sleep after a warning or
463 error message.
464 {expr} must evaluate to a number. When the value is zero the
465 normal behavior is restored.
466
Bram Moolenaarce90e362019-09-08 18:58:44 +0200467 Can also be used as a |method|: >
468 GetTime()->test_settime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200469<
470 Return type: |Number|
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200471
Doug Kearns9cd9e752024-04-07 17:42:17 +0200472test_srand_seed([{seed}]) *test_srand_seed()*
473 When {seed} is given this sets the seed value used by
Bram Moolenaar4f645c52020-02-08 16:40:39 +0100474 `srand()`. When omitted the test seed is removed.
475
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200476 Return type: |Number|
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200477
478test_unknown() *test_unknown()*
479 Return a value with unknown type. Only useful for testing.
480
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200481 Return type: unknown
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200482
483test_void() *test_void()*
484 Return a value with void type. Only useful for testing.
485
h-east84ac2122024-06-17 18:12:30 +0200486 Return type: void
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200487
Bram Moolenaared997ad2019-07-21 16:42:00 +0200488==============================================================================
Bram Moolenaar54775062019-07-31 21:07:14 +02004893. Assert functions *assert-functions-details*
Bram Moolenaared997ad2019-07-21 16:42:00 +0200490
491
492assert_beeps({cmd}) *assert_beeps()*
493 Run {cmd} and add an error message to |v:errors| if it does
494 NOT produce a beep or visual bell.
Bram Moolenaar5b8cabf2021-04-02 18:55:57 +0200495 Also see |assert_fails()|, |assert_nobeep()| and
496 |assert-return|.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200497
Bram Moolenaar24278d22019-08-16 21:49:22 +0200498 Can also be used as a |method|: >
499 GetCmd()->assert_beeps()
500<
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200501 Return type: |Number|
h-east84ac2122024-06-17 18:12:30 +0200502
Bram Moolenaared997ad2019-07-21 16:42:00 +0200503 *assert_equal()*
504assert_equal({expected}, {actual} [, {msg}])
505 When {expected} and {actual} are not equal an error message is
506 added to |v:errors| and 1 is returned. Otherwise zero is
Bram Moolenaarb7398fe2023-05-14 18:50:25 +0100507 returned. |assert-return|
508 The error is in the form "Expected {expected} but got
509 {actual}". When {msg} is present it is prefixed to that.
510
Bram Moolenaared997ad2019-07-21 16:42:00 +0200511 There is no automatic conversion, the String "4" is different
512 from the Number 4. And the number 4 is different from the
513 Float 4.0. The value of 'ignorecase' is not used here, case
514 always matters.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200515 Example: >
516 assert_equal('foo', 'bar')
517< Will result in a string to be added to |v:errors|:
518 test.vim line 12: Expected 'foo' but got 'bar' ~
519
Bram Moolenaar7ff78462020-07-10 22:00:53 +0200520 Can also be used as a |method|, the base is passed as the
521 second argument: >
Bram Moolenaar25e42232019-08-04 15:04:10 +0200522 mylist->assert_equal([1, 2, 3])
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200523<
524 Return type: |Number|
Bram Moolenaar25e42232019-08-04 15:04:10 +0200525
h-east84ac2122024-06-17 18:12:30 +0200526 *assert_equalfile()*
Bram Moolenaarfb517ba2020-06-03 19:55:35 +0200527assert_equalfile({fname-one}, {fname-two} [, {msg}])
Bram Moolenaared997ad2019-07-21 16:42:00 +0200528 When the files {fname-one} and {fname-two} do not contain
529 exactly the same text an error message is added to |v:errors|.
530 Also see |assert-return|.
531 When {fname-one} or {fname-two} does not exist the error will
532 mention that.
533 Mainly useful with |terminal-diff|.
534
Bram Moolenaare49fbff2019-08-21 22:50:07 +0200535 Can also be used as a |method|: >
536 GetLog()->assert_equalfile('expected.log')
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200537<
538 Return type: |Number|
Bram Moolenaare49fbff2019-08-21 22:50:07 +0200539
Bram Moolenaared997ad2019-07-21 16:42:00 +0200540assert_exception({error} [, {msg}]) *assert_exception()*
541 When v:exception does not contain the string {error} an error
542 message is added to |v:errors|. Also see |assert-return|.
543 This can be used to assert that a command throws an exception.
544 Using the error number, followed by a colon, avoids problems
545 with translations: >
546 try
547 commandthatfails
548 call assert_false(1, 'command should have failed')
549 catch
550 call assert_exception('E492:')
551 endtry
Bram Moolenaar1d634542020-08-18 13:41:50 +0200552<
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200553 Return type: |Number|
h-east84ac2122024-06-17 18:12:30 +0200554
Bram Moolenaar1d634542020-08-18 13:41:50 +0200555 *assert_fails()*
Bram Moolenaar9bd5d872020-09-06 21:47:48 +0200556assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
Bram Moolenaared997ad2019-07-21 16:42:00 +0200557 Run {cmd} and add an error message to |v:errors| if it does
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200558 NOT produce an error or when {error} is not found in the
559 error message. Also see |assert-return|.
Bram Moolenaar6f4754b2022-01-23 12:07:04 +0000560 *E856*
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200561 When {error} is a string it must be found literally in the
562 first reported error. Most often this will be the error code,
563 including the colon, e.g. "E123:". >
564 assert_fails('bad cmd', 'E987:')
565<
566 When {error} is a |List| with one or two strings, these are
567 used as patterns. The first pattern is matched against the
568 first reported error: >
569 assert_fails('cmd', ['E987:.*expected bool'])
570< The second pattern, if present, is matched against the last
Bram Moolenaar4072ba52020-12-23 13:56:35 +0100571 reported error.
572 If there is only one error then both patterns must match. This
573 can be used to check that there is only one error.
574 To only match the last error use an empty string for the first
575 error: >
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200576 assert_fails('cmd', ['', 'E987:'])
577<
Bram Moolenaar1d634542020-08-18 13:41:50 +0200578 If {msg} is empty then it is not used. Do this to get the
579 default message when passing the {lnum} argument.
Bram Moolenaarf10911e2022-01-29 22:20:48 +0000580 *E1115*
Bram Moolenaar1d634542020-08-18 13:41:50 +0200581 When {lnum} is present and not negative, and the {error}
582 argument is present and matches, then this is compared with
583 the line number at which the error was reported. That can be
584 the line number in a function or in a script.
Bram Moolenaarf10911e2022-01-29 22:20:48 +0000585 *E1116*
Bram Moolenaar9bd5d872020-09-06 21:47:48 +0200586 When {context} is present it is used as a pattern and matched
587 against the context (script name or function name) where
588 {lnum} is located in.
589
Bram Moolenaared997ad2019-07-21 16:42:00 +0200590 Note that beeping is not considered an error, and some failing
591 commands only beep. Use |assert_beeps()| for those.
592
Bram Moolenaar24278d22019-08-16 21:49:22 +0200593 Can also be used as a |method|: >
594 GetCmd()->assert_fails('E99:')
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200595<
596 Return type: |Number|
Bram Moolenaar24278d22019-08-16 21:49:22 +0200597
Bram Moolenaar1d634542020-08-18 13:41:50 +0200598assert_false({actual} [, {msg}]) *assert_false()*
Bram Moolenaared997ad2019-07-21 16:42:00 +0200599 When {actual} is not false an error message is added to
600 |v:errors|, like with |assert_equal()|.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +0100601 The error is in the form "Expected False but got {actual}".
602 When {msg} is present it is prepended to that.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200603 Also see |assert-return|.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +0100604
Bram Moolenaared997ad2019-07-21 16:42:00 +0200605 A value is false when it is zero. When {actual} is not a
606 number the assert fails.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200607
Bram Moolenaar24278d22019-08-16 21:49:22 +0200608 Can also be used as a |method|: >
609 GetResult()->assert_false()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200610<
611 Return type: |Number|
Bram Moolenaar24278d22019-08-16 21:49:22 +0200612
Bram Moolenaared997ad2019-07-21 16:42:00 +0200613assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
614 This asserts number and |Float| values. When {actual} is lower
615 than {lower} or higher than {upper} an error message is added
616 to |v:errors|. Also see |assert-return|.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +0100617 The error is in the form "Expected range {lower} - {upper},
618 but got {actual}". When {msg} is present it is prefixed to
619 that.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200620
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200621 Return type: |Number|
622
Bram Moolenaared997ad2019-07-21 16:42:00 +0200623 *assert_match()*
624assert_match({pattern}, {actual} [, {msg}])
625 When {pattern} does not match {actual} an error message is
626 added to |v:errors|. Also see |assert-return|.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +0100627 The error is in the form "Pattern {pattern} does not match
628 {actual}". When {msg} is present it is prefixed to that.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200629
630 {pattern} is used as with |=~|: The matching is always done
631 like 'magic' was set and 'cpoptions' is empty, no matter what
632 the actual value of 'magic' or 'cpoptions' is.
633
634 {actual} is used as a string, automatic conversion applies.
635 Use "^" and "$" to match with the start and end of the text.
636 Use both to match the whole text.
637
Bram Moolenaared997ad2019-07-21 16:42:00 +0200638 Example: >
639 assert_match('^f.*o$', 'foobar')
640< Will result in a string to be added to |v:errors|:
641 test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~
642
Bram Moolenaar24278d22019-08-16 21:49:22 +0200643 Can also be used as a |method|: >
644 getFile()->assert_match('foo.*')
645<
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200646 Return type: |Number|
647
Bram Moolenaar5b8cabf2021-04-02 18:55:57 +0200648assert_nobeep({cmd}) *assert_nobeep()*
649 Run {cmd} and add an error message to |v:errors| if it
650 produces a beep or visual bell.
651 Also see |assert_beeps()|.
652
653 Can also be used as a |method|: >
654 GetCmd()->assert_nobeep()
655<
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200656 Return type: |Number|
657
Bram Moolenaared997ad2019-07-21 16:42:00 +0200658 *assert_notequal()*
659assert_notequal({expected}, {actual} [, {msg}])
660 The opposite of `assert_equal()`: add an error message to
661 |v:errors| when {expected} and {actual} are equal.
662 Also see |assert-return|.
663
Bram Moolenaar25e42232019-08-04 15:04:10 +0200664 Can also be used as a |method|: >
665 mylist->assert_notequal([1, 2, 3])
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200666<
667 Return type: |Number|
Bram Moolenaar25e42232019-08-04 15:04:10 +0200668
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200669 *assert_notmatch()*
Bram Moolenaared997ad2019-07-21 16:42:00 +0200670assert_notmatch({pattern}, {actual} [, {msg}])
671 The opposite of `assert_match()`: add an error message to
672 |v:errors| when {pattern} matches {actual}.
673 Also see |assert-return|.
674
Bram Moolenaar24278d22019-08-16 21:49:22 +0200675 Can also be used as a |method|: >
676 getFile()->assert_notmatch('bar.*')
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200677<
678 Return type: |Number|
Bram Moolenaare49fbff2019-08-21 22:50:07 +0200679
Bram Moolenaared997ad2019-07-21 16:42:00 +0200680assert_report({msg}) *assert_report()*
Bram Moolenaar6aa57292021-08-14 21:25:52 +0200681 Report a test failure directly, using String {msg}.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200682 Always returns one.
683
Bram Moolenaare49fbff2019-08-21 22:50:07 +0200684 Can also be used as a |method|: >
685 GetMessage()->assert_report()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200686<
687 Return type: |Number|
Bram Moolenaare49fbff2019-08-21 22:50:07 +0200688
689
Bram Moolenaared997ad2019-07-21 16:42:00 +0200690assert_true({actual} [, {msg}]) *assert_true()*
691 When {actual} is not true an error message is added to
692 |v:errors|, like with |assert_equal()|.
693 Also see |assert-return|.
694 A value is TRUE when it is a non-zero number. When {actual}
695 is not a number the assert fails.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +0100696 When {msg} is given it precedes the default message.
Bram Moolenaared997ad2019-07-21 16:42:00 +0200697
Bram Moolenaar24278d22019-08-16 21:49:22 +0200698 Can also be used as a |method|: >
699 GetResult()->assert_true()
700<
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200701 Return type: |Number|
702
Bram Moolenaared997ad2019-07-21 16:42:00 +0200703
704 vim:tw=78:ts=8:noet:ft=help:norl: