blob: 7628ef149e7f50144860d9c5b149d4cfd39f12fd [file] [log] [blame]
Bram Moolenaar46acad72023-06-11 19:04:18 +01001Tests for syntax highlighting plugins
2=====================================
3
4Summary: Files in the "input" directory are edited by Vim with syntax
5highlighting enabled. Screendumps are generated and compared with the
6expected screendumps in the "dumps" directory. This will uncover any
7character attributes that differ.
8
9Without any further setup a screendump is made at the top of the file (using
10_00.dump) and another one at the end of the file (using _99.dump). The dumps
11are normally 20 screen lines tall.
12
13When the screendumps are OK an empty "done/{name}" file is created. This
14avoids running the test again until "make clean" is used. Thus you can run
15"make test", see one test fail, try to fix the problem, then run "make test"
16again to only repeat the failing test.
17
18When a screendump differs it is stored in the "failed" directory. This allows
19for comparing it with the expected screendump, using a command like:
20
21 let fname = '{name}_99.dump'
22 call term_dumpdiff('failed/' .. fname, 'dumps/' .. fname)
23
24
25Creating a syntax plugin test
26-----------------------------
27
28Create a source file in the language you want to test in the "input"
Aliaksei Budavei93edd252024-03-05 22:34:36 +030029directory. Use the filetype name as the base and a file name extension
30matching the filetype. Let's use Java as an example. The file would then be
Bram Moolenaar46acad72023-06-11 19:04:18 +010031"input/java.java".
32
Aliaksei Budavei93edd252024-03-05 22:34:36 +030033Make sure to include some interesting constructs with plenty of complicated
34highlighting. Optionally, pre-configure the testing environment by including
35setup commands at the top of the input file. The format for these lines is:
36
37 TEST_SETUP {command}
38
39where {command} is any valid Ex command, which extends to the end of the line.
40The first 20 lines of the input file are ALWAYS scanned for setup commands and
41these will be executed before the syntax highlighting is enabled. Typically,
42these lines would be included as comments so as not to introduce any syntax
43errors in the input file but this is not required.
44
45Continuing the Java example:
46
47 // TEST_SETUP let g:java_space_errors = 1
48 // TEST_SETUP let g:java_minlines = 5
49 class Test { }
50
Bram Moolenaar46acad72023-06-11 19:04:18 +010051If there is no further setup required, you can now run the tests:
Aliaksei Budavei93edd252024-03-05 22:34:36 +030052
Bram Moolenaar46acad72023-06-11 19:04:18 +010053 make test
54
55The first time this will fail with an error for a missing screendump. The
56newly created screendumps will be "failed/java_00.dump",
57"failed/java_01.dump", etc. You can inspect each with:
58
59 call term_dumpload('failed/java_00.dump')
60 call term_dumpload('failed/java_01.dump')
61 ...
62 call term_dumpload('failed/java_99.dump')
63
64If they look OK, move them to the "dumps" directory:
65
66 :!mv failed/java_00.dump dumps
67 :!mv failed/java_01.dump dumps
68 ...
69 :!mv failed/java_99.dump dumps
70
71If you now run the test again, it will succeed.
72
73
74Adjusting a syntax plugin test
75------------------------------
76
77If you make changes to the syntax plugin, you should add code to the input
78file to see the effect of these changes. So that the effect of the changes
79are covered by the test. You can follow these steps:
80
811. Edit the syntax plugin somewhere in your personal setup. Use a file
82 somewhere to try out the changes.
832. Go to the directory where you have the Vim code checked out and replace the
84 syntax plugin. Run the tests: "make test". Usually the tests will still
85 pass, but if you fixed syntax highlighting that was already visible in the
86 input file, carefully check that the changes in the screendump are
87 intentional:
Aliaksei Budavei93edd252024-03-05 22:34:36 +030088
Bram Moolenaar46acad72023-06-11 19:04:18 +010089 let fname = '{name}_99.dump'
90 call term_dumpdiff('failed/' .. fname, 'dumps/' .. fname)
Aliaksei Budavei93edd252024-03-05 22:34:36 +030091
Bram Moolenaar46acad72023-06-11 19:04:18 +010092 Fix the syntax plugin until the result is good.
932. Edit the input file for your language to add the items you have improved.
94 (TODO: how to add another screendump?).
95 Run the tests and you should get failures. Like with the previous step,
96 carefully check that the new screendumps in the "failed" directory are
97 good. Update the syntax plugin and the input file until the highlighting
98 is good and you can see the effect of the syntax plugin improvements. Then
99 move the screendumps from the "failed" to the "dumps" directory. Now "make
100 test" should succeed.
1013. Prepare a pull request with the modified files:
102 - syntax plugin: syntax/{name}.vim
103 - test input file: syntax/testdir/input/{name}.{ext}
104 - test dump files: syntax/testdir/dumps/{name}_99.dump
105
106As an extra check you can temporarily put back the old syntax plugin and
107verify that the tests fail. Then you know your changes are covered by the
108test.
109
110
111
Bram Moolenaar46acad72023-06-11 19:04:18 +0100112
Aliaksei Budavei93edd252024-03-05 22:34:36 +0300113TODO: run test for one specific filetype
Bram Moolenaar46acad72023-06-11 19:04:18 +0100114TODO: test syncing by jumping around