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. |
| 18 | 3) Also add an entry in src/Makefile. |
| 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 | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 22 | What you can use (see test_assert.vim for an example): |
Bram Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 23 | - Call assert_equal(), assert_true(), assert_false(), etc. |
Bram Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 24 | - Use try/catch to check for exceptions. |
Bram Moolenaar | fd89d7e | 2016-06-04 20:25:05 +0200 | [diff] [blame] | 25 | - Use alloc_fail() to have memory allocation fail. This makes it possible |
Bram Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 26 | to check memory allocation failures are handled gracefully. You need to |
| 27 | change the source code to add an ID to the allocation. Update LAST_ID_USED |
| 28 | above alloc_id() to the highest ID used. |
Bram Moolenaar | 2ab375e | 2016-02-10 22:23:06 +0100 | [diff] [blame] | 29 | - Use disable_char_avail_for_testing(1) if char_avail() must return FALSE for |
| 30 | a while. E.g. to trigger the CursorMovedI autocommand event. |
| 31 | See test_cursor_func.vim for an example |
Bram Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 32 | - If the bug that is being tested isn't fixed yet, you can throw an exception |
| 33 | so that it's clear this still needs work. E.g.: |
| 34 | throw "Skipped: Bug with <c-e> and popupmenu not fixed yet" |
Bram Moolenaar | fd89d7e | 2016-06-04 20:25:05 +0200 | [diff] [blame] | 35 | - See the start of runtest.vim for more help. |
Bram Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 36 | |
| 37 | |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 38 | TO ADD A SCREEN DUMP TEST: |
| 39 | |
| 40 | Mostly the same as writing a new style test. Additonally, see help on |
| 41 | "terminal-dumptest". Put the reference dump in "dumps/Test_func_name.dump". |
| 42 | |
| 43 | |
Bram Moolenaar | 6602af7 | 2016-01-07 22:01:01 +0100 | [diff] [blame] | 44 | TO ADD AN OLD STYLE TEST: |
| 45 | |
| 46 | 1) Create test_<subject>.in and test_<subject>.ok files. |
| 47 | 2) Add test_<subject>.out to SCRIPTS_ALL in Make_all.mak in alphabetical order. |
| 48 | 3) Use make test_<subject>.out to run a single test in src/testdir/. |
| 49 | Use make test_<subject> to run a single test in src/. |
| 50 | 4) Also add an entry in src/Makefile. |
| 51 | |
| 52 | Keep in mind that the files are used as if everything was typed: |
| 53 | - To add comments use: :" (that's an Ex command comment) |
| 54 | - A line break is like pressing Enter. If that happens on the last line |
| 55 | you'll hear a beep! |