mirror of
https://github.com/vim/vim.git
synced 2025-08-26 20:03:41 -04:00
runtime(syntax-tests): Support sourceable Vim configuration for syntax tests
Not all programming languages support comments; without such support, the TEST_SETUP functionality that offers embeddable Vim Ex commands may no longer be applicable. We can achieve similar functionality by storing Ex commands in a Vim file with its basename matching the basename of the test file, and having this Vim file sourced, and then having the test file loaded and tested. When such a Vim file would be used for a language that has comments and whose matching test file has embedded TEST_SETUP lines, we will accommodate it by letting the TEST_SETUP lines augment and/or overrule sourced configuration. Further details can be found in the discussion thread at https://github.com/vim/vim/discussions/14117. related: #14215 Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
93edd254d5
commit
f6069a7ddc
@ -48,6 +48,19 @@ Continuing the Java example:
|
|||||||
// TEST_SETUP let g:java_minlines = 5
|
// TEST_SETUP let g:java_minlines = 5
|
||||||
class Test { }
|
class Test { }
|
||||||
|
|
||||||
|
As an alternative, setup commands can be included in an external Vim script
|
||||||
|
file in the "input/setup" directory. This script file must have the same base
|
||||||
|
name as the input file.
|
||||||
|
|
||||||
|
So, the equivalent example configuration using this method would be to create
|
||||||
|
an "input/setup/java.vim" script file with the following lines:
|
||||||
|
|
||||||
|
let g:java_space_errors = 1
|
||||||
|
let g:java_minlines = 5
|
||||||
|
|
||||||
|
Both inline setup commands and setup scripts may be used at the same time, the
|
||||||
|
script file will be sourced before any TEST_SETUP commands are executed.
|
||||||
|
|
||||||
If there is no further setup required, you can now run the tests:
|
If there is no further setup required, you can now run the tests:
|
||||||
|
|
||||||
make test
|
make test
|
||||||
@ -100,6 +113,7 @@ are covered by the test. You can follow these steps:
|
|||||||
test" should succeed.
|
test" should succeed.
|
||||||
3. Prepare a pull request with the modified files:
|
3. Prepare a pull request with the modified files:
|
||||||
- syntax plugin: syntax/{name}.vim
|
- syntax plugin: syntax/{name}.vim
|
||||||
|
- Vim setup file: syntax/testdir/input/setup/{name}.vim (if any)
|
||||||
- test input file: syntax/testdir/input/{name}.{ext}
|
- test input file: syntax/testdir/input/{name}.{ext}
|
||||||
- test dump files: syntax/testdir/dumps/{name}_99.dump
|
- test dump files: syntax/testdir/dumps/{name}_99.dump
|
||||||
|
|
||||||
|
@ -90,6 +90,10 @@ func RunTest()
|
|||||||
let failed_tests = []
|
let failed_tests = []
|
||||||
let skipped_count = 0
|
let skipped_count = 0
|
||||||
let MAX_FAILED_COUNT = 5
|
let MAX_FAILED_COUNT = 5
|
||||||
|
" Create a map of setup configuration filenames with their basenames as keys.
|
||||||
|
let setup = glob('input/setup/*.vim', 1, 1)
|
||||||
|
\ ->reduce({d, f -> extend(d, {fnamemodify(f, ':t:r'): f})}, {})
|
||||||
|
|
||||||
for fname in glob('input/*.*', 1, 1)
|
for fname in glob('input/*.*', 1, 1)
|
||||||
if fname =~ '\~$'
|
if fname =~ '\~$'
|
||||||
" backup file, skip
|
" backup file, skip
|
||||||
@ -175,7 +179,13 @@ func RunTest()
|
|||||||
redraw
|
redraw
|
||||||
|
|
||||||
" Let "Xtestscript#SetUpVim()" turn the syntax on.
|
" Let "Xtestscript#SetUpVim()" turn the syntax on.
|
||||||
let buf = RunVimInTerminal('-Nu NONE -S Xtestscript', {})
|
let prefix = '-Nu NONE -S Xtestscript'
|
||||||
|
let path = get(setup, root, '')
|
||||||
|
" Source the found setup configuration file.
|
||||||
|
let args = !empty(path)
|
||||||
|
\ ? prefix .. ' -S ' .. path
|
||||||
|
\ : prefix
|
||||||
|
let buf = RunVimInTerminal(args, {})
|
||||||
" edit the file only after catching the SwapExists event
|
" edit the file only after catching the SwapExists event
|
||||||
call term_sendkeys(buf, ":edit " .. fname .. "\<CR>")
|
call term_sendkeys(buf, ":edit " .. fname .. "\<CR>")
|
||||||
" set up the testing environment
|
" set up the testing environment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user