Bram Moolenaar | a9537d2 | 2014-08-29 10:04:47 +0200 | [diff] [blame] | 1 | This directory contains tests for various Vim features. |
| 2 | |
Bram Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 3 | If it makes sense, add a new test method to an already existing file. You may |
| 4 | want to separate it from other tests with comment lines. |
Bram Moolenaar | a9537d2 | 2014-08-29 10:04:47 +0200 | [diff] [blame] | 5 | |
Bram Moolenaar | 9e4d821 | 2016-08-18 23:04:48 +0200 | [diff] [blame] | 6 | The numbered tests are older, we have switched to named tests. Don't add any |
| 7 | more numbered tests. |
Bram Moolenaar | a9537d2 | 2014-08-29 10:04:47 +0200 | [diff] [blame] | 8 | |
Bram Moolenaar | fd89d7e | 2016-06-04 20:25:05 +0200 | [diff] [blame] | 9 | And then you can choose between a new style test, which is a Vim script, or an |
Bram Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 10 | old style test, which uses Normal mode commands. Use a new style test if you |
Bram Moolenaar | 9e4d821 | 2016-08-18 23:04:48 +0200 | [diff] [blame] | 11 | can. Use an old style test when it needs to run without the +eval feature. |
Bram Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 12 | |
| 13 | |
| 14 | TO ADD A NEW STYLE TEST: |
| 15 | |
| 16 | 1) Create a test_<subject>.vim file. |
Bram Moolenaar | caa55b6 | 2017-01-10 13:51:09 +0100 | [diff] [blame] | 17 | 2) Add test_<subject>.res to NEW_TESTS in Make_all.mak in alphabetical order. |
Bram Moolenaar | 02c9721 | 2018-09-09 15:56:06 +0200 | [diff] [blame] | 18 | 3) Also add an entry "test_<subject>" in src/Make_all.mak. |
Bram Moolenaar | caa55b6 | 2017-01-10 13:51:09 +0100 | [diff] [blame] | 19 | 4) Use make test_<subject>.res to run a single test in src/testdir/. |
Bram Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 20 | Use make test_<subject> to run a single test in src/. |
Bram Moolenaar | a9537d2 | 2014-08-29 10:04:47 +0200 | [diff] [blame] | 21 | |
Bram Moolenaar | 02c9721 | 2018-09-09 15:56:06 +0200 | [diff] [blame] | 22 | At 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 |
| 24 | bit faster, because Vim doesn't have to be started, one Vim instance runs many |
| 25 | tests. |
| 26 | |
| 27 | |
Bram Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 28 | What you can use (see test_assert.vim for an example): |
Bram Moolenaar | 02c9721 | 2018-09-09 15:56:06 +0200 | [diff] [blame] | 29 | |
Bram Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 30 | - Call assert_equal(), assert_true(), assert_false(), etc. |
Bram Moolenaar | 02c9721 | 2018-09-09 15:56:06 +0200 | [diff] [blame] | 31 | |
| 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 Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 48 | - If the bug that is being tested isn't fixed yet, you can throw an exception |
Bram Moolenaar | 02c9721 | 2018-09-09 15:56:06 +0200 | [diff] [blame] | 49 | 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 Moolenaar | fd89d7e | 2016-06-04 20:25:05 +0200 | [diff] [blame] | 52 | - See the start of runtest.vim for more help. |
Bram Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 53 | |
| 54 | |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 55 | TO ADD A SCREEN DUMP TEST: |
| 56 | |
| 57 | Mostly 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 Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 61 | TO ADD AN OLD STYLE TEST: |
| 62 | |
| 63 | 1) Create test_<subject>.in and test_<subject>.ok files. |
| 64 | 2) Add test_<subject>.out to SCRIPTS_ALL in Make_all.mak in alphabetical order. |
| 65 | 3) 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/. |
| 67 | 4) Also add an entry in src/Makefile. |
| 68 | |
| 69 | Keep 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! |