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