blob: 1ae0d28ae83b259ab03b1df0caf6b09c4948e595 [file] [log] [blame]
Christian Brabandteb380b92025-07-07 20:53:55 +02001This directory contains test cases for various Vim features.
2The auxiliary functions to perform the tests are in the util/ folder.
3
Bram Moolenaarec504012019-01-11 17:30:16 +01004For testing an indent script see runtime/indent/testdir/README.txt.
Christian Brabandteb380b92025-07-07 20:53:55 +02005For testing a syntax script see runtime/syntax/testdir/README.txt.
Bram Moolenaara9537d22014-08-29 10:04:47 +02006
Bram Moolenaar6602af72016-01-07 22:01:01 +01007If it makes sense, add a new test method to an already existing file. You may
8want to separate it from other tests with comment lines.
Bram Moolenaara9537d22014-08-29 10:04:47 +02009
Bram Moolenaar6602af72016-01-07 22:01:01 +010010TO ADD A NEW STYLE TEST:
11
121) Create a test_<subject>.vim file.
Bram Moolenaarec504012019-01-11 17:30:16 +0100132) Add test_<subject>.res to NEW_TESTS_RES in Make_all.mak in alphabetical
14 order.
153) Also add an entry "test_<subject>" to NEW_TESTS in Make_all.mak.
164) Use make test_<subject> to run a single test.
Bram Moolenaara9537d22014-08-29 10:04:47 +020017
Bram Moolenaar02c97212018-09-09 15:56:06 +020018At 2), instead of running the test separately, it can be included in
19"test_alot". Do this for quick tests without side effects. The test runs a
20bit faster, because Vim doesn't have to be started, one Vim instance runs many
21tests.
22
Bram Moolenaar85683ec2020-02-20 22:35:02 +010023At 4), to run a test in GUI, add "GUI_FLAG=-g" to the make command.
24
Bram Moolenaar02c97212018-09-09 15:56:06 +020025
Bram Moolenaar6602af72016-01-07 22:01:01 +010026What you can use (see test_assert.vim for an example):
Bram Moolenaar02c97212018-09-09 15:56:06 +020027
Bram Moolenaardac19472016-09-03 22:35:40 +020028- Call assert_equal(), assert_true(), assert_false(), etc.
Bram Moolenaar02c97212018-09-09 15:56:06 +020029
30- Use assert_fails() to check for expected errors.
31
32- Use try/catch to avoid an exception aborts the test.
33
Bram Moolenaarb45125b2019-03-24 20:18:40 +010034- Use test_alloc_fail() to have memory allocation fail. This makes it possible
35 to check memory allocation failures are handled gracefully. You need to
36 change the source code to add an ID to the allocation. Add a new one to
37 alloc_id_T, before aid_last.
Bram Moolenaar02c97212018-09-09 15:56:06 +020038
39- Use test_override() to make Vim behave differently, e.g. if char_avail()
40 must return FALSE for a while. E.g. to trigger the CursorMovedI autocommand
Bram Moolenaarb45125b2019-03-24 20:18:40 +010041 event. See test_cursor_func.vim for an example.
Bram Moolenaar02c97212018-09-09 15:56:06 +020042
Bram Moolenaardac19472016-09-03 22:35:40 +020043- If the bug that is being tested isn't fixed yet, you can throw an exception
Bram Moolenaar02c97212018-09-09 15:56:06 +020044 with "Skipped" so that it's clear this still needs work. E.g.: throw
45 "Skipped: Bug with <c-e> and popupmenu not fixed yet"
46
Christian Brabandt2c645e82022-04-20 14:52:01 +010047- The following environment variables are recognized and can be set to
48 influence the behavior of the test suite (see runtest.vim for details)
49
50 - $TEST_MAY_FAIL=Test_channel_one - ignore those failing tests
51 - $TEST_FILTER=Test_channel - only run test that match this pattern
52 - $TEST_SKIP_PAT=Test_channel - skip tests that match this pattern
53 - $TEST_NO_RETRY=yes - do not try to re-run failing tests
54 You can also set them in Vim:
55 :let $TEST_MAY_FAIL = 'Test_channel_one'
56 :let $TEST_FILTER = '_set_mode'
57 :let $TEST_SKIP_PAT = 'Test_loop_forever'
58 :let $TEST_NO_RETRY = 'yes'
59 Use an empty string to revert, e.g.:
60 :let $TEST_FILTER = ''
61
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +020062- See the start of runtest.vim for more help.
Bram Moolenaar6602af72016-01-07 22:01:01 +010063
64
Bram Moolenaarda650582018-02-20 15:51:40 +010065TO ADD A SCREEN DUMP TEST:
66
Bram Moolenaarc4568ab2018-11-16 16:21:05 +010067Mostly the same as writing a new style test. Additionally, see help on
Bram Moolenaarda650582018-02-20 15:51:40 +010068"terminal-dumptest". Put the reference dump in "dumps/Test_func_name.dump".
69
Bram Moolenaar02c037a2020-08-30 19:26:45 +020070
71OLD STYLE TESTS:
72
73There are a few tests that are used when Vim was built without the +eval
74feature. These cannot use the "assert" functions, therefore they consist of a
75.in file that contains Normal mode commands between STARTTEST and ENDTEST.
Bram Moolenaarf10911e2022-01-29 22:20:48 +000076They modify the file and the result gets written in the test.out file. This
Bram Moolenaar02c037a2020-08-30 19:26:45 +020077is then compared with the .ok file. If they are equal the test passed. If
78they differ the test failed.
Bram Moolenaar0e6adf82021-12-16 14:41:10 +000079
80
81RUNNING THE TESTS:
82
83To run a single test from the src directory:
84
85 $ make test_<name>
86
87The below commands should be run from the src/testdir directory.
88
89To run a single test:
90
91 $ make test_<name>.res
92
93The file 'messages' contains the messages generated by the test script. If a
94test fails, then the test.log file contains the error messages. If all the
95tests are successful, then this file will be an empty file.
96
Christian Brabandt2c645e82022-04-20 14:52:01 +010097- To run a single test function from a test script:
Bram Moolenaar0e6adf82021-12-16 14:41:10 +000098
99 $ ../vim -u NONE -S runtest.vim <test_file>.vim <function_name>
100
Christian Brabandt2c645e82022-04-20 14:52:01 +0100101- To execute only specific test functions, add a second argument:
102
Aliaksei Budavei6bff6a22024-08-19 21:33:26 +0200103 $ ../vim -u NONE -S runtest.vim test_channel.vim open_delay
Christian Brabandt2c645e82022-04-20 14:52:01 +0100104
105- To run all the tests:
Bram Moolenaar0e6adf82021-12-16 14:41:10 +0000106
107 $ make
108
Christian Brabandt2c645e82022-04-20 14:52:01 +0100109- To run the test on MS-Windows using the MSVC nmake:
Bram Moolenaar0e6adf82021-12-16 14:41:10 +0000110
K.Takata5bc13452022-09-09 10:52:47 +0100111 > nmake -f Make_mvc.mak
Bram Moolenaar0e6adf82021-12-16 14:41:10 +0000112
Christian Brabandt2c645e82022-04-20 14:52:01 +0100113- To run the tests with GUI Vim:
Bram Moolenaar0e6adf82021-12-16 14:41:10 +0000114
115 $ make GUI_FLAG=-g
116
117 or
118
119 $ make VIMPROG=../gvim
120
Christian Brabandt2c645e82022-04-20 14:52:01 +0100121- To cleanup the temporary files after running the tests:
Bram Moolenaar0e6adf82021-12-16 14:41:10 +0000122
123 $ make clean
Aliaksei Budaveid33afe12024-08-12 18:37:15 +0200124
Aliaksei Budaveid33afe12024-08-12 18:37:15 +0200125
Aliaksei Budavei6bff6a22024-08-19 21:33:26 +0200126VIEWING GENERATED SCREENDUMPS (local):
127
128You may also wish to look at the whole batch of failed screendumps after
129running "make". Source the "viewdumps.vim" script for this task:
130
131 $ ../vim -u NONE -S viewdumps.vim \
132 [dumps/Test_xxd_*.dump ...]
133
134By default, all screendumps found in the "failed" directory will be added to
135the argument list and then the first one will be loaded. Loaded screendumps
136that bear filenames of screendumps found in the "dumps" directory will be
137rendering the contents of any such pair of files and the difference between
138them (:help term_dumpdiff()); otherwise, they will be rendering own contents
139(:help term_dumpload()). Remember to execute :edit when occasionally you see
140raw file contents instead of rendered.
141
142At any time, you can add, list, and abandon other screendumps:
143
144 :$argedit dumps/Test_spell_*.dump
145 :args
146 :qall
147
148The listing of argument commands can be found under :help buffer-list.
149
150
151VIEWING GENERATED SCREENDUMPS (from a CI-uploaded artifact):
152
153After you have downloaded an artifact archive containing failed screendumps
154and extracted its files in a temporary directory, you need to set up a "dumps"
155directory by creating a symlink:
156
157 $ cd /path/to/fork
158 $ ln -s $(pwd)/src/testdir/dumps /tmp/src/testdir/dumps
159
160You can now examine the extracted screendumps:
161
162 $ ./src/vim -u NONE -S src/testdir/viewdumps.vim \
163 /tmp/src/testdir/failed/*.dump
164
165
166VIEWING GENERATED SCREENDUMPS (submitted for a pull request):
167
Aliaksei Budavei5eaacef2025-01-11 17:10:06 +0100168Note: There is also a "git difftool" extension described in ./commondumps.vim.
169
Aliaksei Budavei6bff6a22024-08-19 21:33:26 +0200170First, you need to check out the topic branch with the proposed changes and
171write down a difference list between the HEAD commit (index) and its parent
172commit with respect to the changed "dumps" filenames:
173
174 $ cd /path/to/fork
175 $ git switch prs/1234
176 $ git diff-index --relative=src/testdir/dumps/ \
177 --name-only prs/1234~1 > /tmp/filelist
178
179Then, you need to check out the master branch, change the current working
180directory to reconcile relative filepaths written in the filenames list,
181possibly create an empty "failed" directory, copy in this directory the old
182"dumps" files, whose names are on the same list, and follow it by checking out
183the topic branch:
184
185 $ git switch master
186 $ cd src/testdir/dumps
187 $ test -d ../failed || mkdir ../failed
188 $ cp -t ../failed $(cat /tmp/filelist)
189 $ git switch prs/1234
190
191Make note of any missing new screendumps. Please remember about the
192introduced INVERTED relation between "dumps" and "failed", i.e. the files to
193be committed are in "dumps" already and their old versions are in "failed".
194Therefore, you need to copy the missing new screendumps from "dumps" to
195"failed":
196
197 $ cp -t ../failed foo_10.dump foo_11.dump foo_12.dump
198
199After you have changed the current working directory to its parent directory,
200you can now examine the screendumps from the "failed" directory (note that new
201screendumps will be shown with no difference between their versions):
202
203 $ cd ..
204 $ ../vim -u NONE -S viewdumps.vim
205