blob: c6492598ce937ab58b5d08ab8ce5dc258b104d4e [file] [log] [blame]
Bram Moolenaara9537d22014-08-29 10:04:47 +02001This directory contains tests for various Vim features.
2
Bram Moolenaar6602af72016-01-07 22:01:01 +01003If it makes sense, add a new test method to an already existing file. You may
4want to separate it from other tests with comment lines.
Bram Moolenaara9537d22014-08-29 10:04:47 +02005
Bram Moolenaar9e4d8212016-08-18 23:04:48 +02006The numbered tests are older, we have switched to named tests. Don't add any
7more numbered tests.
Bram Moolenaara9537d22014-08-29 10:04:47 +02008
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02009And then you can choose between a new style test, which is a Vim script, or an
Bram Moolenaar6602af72016-01-07 22:01:01 +010010old style test, which uses Normal mode commands. Use a new style test if you
Bram Moolenaar9e4d8212016-08-18 23:04:48 +020011can. Use an old style test when it needs to run without the +eval feature.
Bram Moolenaar6602af72016-01-07 22:01:01 +010012
13
14TO ADD A NEW STYLE TEST:
15
161) Create a test_<subject>.vim file.
Bram Moolenaarcaa55b62017-01-10 13:51:09 +0100172) Add test_<subject>.res to NEW_TESTS in Make_all.mak in alphabetical order.
Bram Moolenaar02c97212018-09-09 15:56:06 +0200183) Also add an entry "test_<subject>" in src/Make_all.mak.
Bram Moolenaarcaa55b62017-01-10 13:51:09 +0100194) Use make test_<subject>.res to run a single test in src/testdir/.
Bram Moolenaar6602af72016-01-07 22:01:01 +010020 Use make test_<subject> to run a single test in src/.
Bram Moolenaara9537d22014-08-29 10:04:47 +020021
Bram Moolenaar02c97212018-09-09 15:56:06 +020022At 2), instead of running the test separately, it can be included in
23"test_alot". Do this for quick tests without side effects. The test runs a
24bit faster, because Vim doesn't have to be started, one Vim instance runs many
25tests.
26
27
Bram Moolenaar6602af72016-01-07 22:01:01 +010028What you can use (see test_assert.vim for an example):
Bram Moolenaar02c97212018-09-09 15:56:06 +020029
Bram Moolenaardac19472016-09-03 22:35:40 +020030- Call assert_equal(), assert_true(), assert_false(), etc.
Bram Moolenaar02c97212018-09-09 15:56:06 +020031
32- Use assert_fails() to check for expected errors.
33
34- Use try/catch to avoid an exception aborts the test.
35
36- Use alloc_fail() to have memory allocation fail. This makes it possible to
37 check memory allocation failures are handled gracefully. You need to change
38
39- the source code to add an ID to the allocation. Update LAST_ID_USED above
40 alloc_id() to the highest ID used.
41
42- Use test_override() to make Vim behave differently, e.g. if char_avail()
43 must return FALSE for a while. E.g. to trigger the CursorMovedI autocommand
44 event.
45
46- See test_cursor_func.vim for an example.
47
Bram Moolenaardac19472016-09-03 22:35:40 +020048- If the bug that is being tested isn't fixed yet, you can throw an exception
Bram Moolenaar02c97212018-09-09 15:56:06 +020049 with "Skipped" so that it's clear this still needs work. E.g.: throw
50 "Skipped: Bug with <c-e> and popupmenu not fixed yet"
51
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +020052- See the start of runtest.vim for more help.
Bram Moolenaar6602af72016-01-07 22:01:01 +010053
54
Bram Moolenaarda650582018-02-20 15:51:40 +010055TO ADD A SCREEN DUMP TEST:
56
57Mostly the same as writing a new style test. Additonally, see help on
58"terminal-dumptest". Put the reference dump in "dumps/Test_func_name.dump".
59
60
Bram Moolenaar6602af72016-01-07 22:01:01 +010061TO ADD AN OLD STYLE TEST:
62
631) Create test_<subject>.in and test_<subject>.ok files.
642) Add test_<subject>.out to SCRIPTS_ALL in Make_all.mak in alphabetical order.
653) Use make test_<subject>.out to run a single test in src/testdir/.
66 Use make test_<subject> to run a single test in src/.
674) Also add an entry in src/Makefile.
68
69Keep in mind that the files are used as if everything was typed:
70- To add comments use: :" (that's an Ex command comment)
71- A line break is like pressing Enter. If that happens on the last line
72 you'll hear a beep!