0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

runtime(syntax-tests): Improve parts of "runtest.vim"

* Accommodate the calling of "EraseLineAndReturnCarriage()"
  to not interfere with the "skipped" and "failed" reports.

* Create the "failed" directory, if unavailable, without
  relying on "VerifyScreenDump()" to do it so that reporting
  with "Xtestscript#s:AssertCursorForwardProgress()" can be
  uniformly attempted.

* Make an only list copy of the "Xtestscript" contents and
  share it with every syntax test.

* Narrow the scope of the "filetype" and "failed_root" local
  variables.

closes: #16789

Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Aliaksei Budavei 2025-03-08 16:58:17 +01:00 committed by Christian Brabandt
parent dd42b05f8a
commit f63c3467b1
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -15,11 +15,12 @@ let s:messagesFname = fnameescape(syntaxDir .. '/testdir/messages')
let s:messages = []
" Erase the cursor line and do not advance the cursor.
def EraseLineAndReturnCarriage(rname: string)
" Erase the cursor line and do not advance the cursor. (Call the function
" after each passing test report.)
def EraseLineAndReturnCarriage(line: string)
const full_width: number = winwidth(0)
const half_width: number = full_width - (full_width + 1) / 2
if (strlen(rname) + strlen('Test' .. "\x20\x20" .. 'FAILED')) > half_width
if strlen(line) > half_width
echon "\r" .. repeat("\x20", full_width) .. "\r"
else
echon repeat("\x20", half_width) .. "\r"
@ -57,7 +58,6 @@ call append(line('$'), '')
let s:test_run_message = 'Test run on ' .. strftime("%Y %b %d %H:%M:%S")
call append(line('$'), s:test_run_message)
silent wq
echo "\n"
if syntaxDir !~ '[/\\]runtime[/\\]syntax\>'
call Fatal('Current directory must be "runtime/syntax"')
@ -80,10 +80,15 @@ if !CanRunVimInTerminal()
endif
cd testdir
if !isdirectory('done')
call mkdir('done')
endif
if !isdirectory('failed')
call mkdir('failed')
endif
set nocp
set nowrapscan
set report=9999
@ -224,54 +229,7 @@ def s:TermWaitAndPollRuler(buf: number, in_name_and_out_name: string): list<stri
enddef
func RunTest()
let ok_count = 0
let failed_tests = []
let skipped_count = 0
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})}, {})
" Turn a subset of filenames etc. requested for testing into a pattern.
let filter = filereadable('../testdir/Xfilter')
\ ? readfile('../testdir/Xfilter')
\ ->map({_, v -> '^' .. substitute(v, '_$', '', '')})
\ ->join('\|')
\ : ''
" Treat "\.self-testing$" as a string NOT as a regexp.
if filter ==# '\.self-testing$'
let dirpath = 'input/selftestdir/'
let fnames = readdir(dirpath, {fname -> fname !~ '^README\.txt$'})
else
let dirpath = 'input/'
let filter ..= exists("$VIM_SYNTAX_TEST_FILTER") &&
\ !empty($VIM_SYNTAX_TEST_FILTER)
\ ? (empty(filter) ? '' : '\|') .. $VIM_SYNTAX_TEST_FILTER
\ : ''
let fnames = readdir(dirpath,
\ {subset -> {fname -> fname !~ '\~$' && fname =~# subset}}(
\ empty(filter) ? '^.\+\..\+$' : filter))
endif
for fname in fnames
let root = fnamemodify(fname, ':r')
let fname = dirpath .. fname
let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '')
let failed_root = 'failed/' .. root
" Execute the test if the "done" file does not exist or when the input file
" is newer.
let in_time = getftime(fname)
let out_time = getftime('done/' .. root)
if out_time < 0 || in_time > out_time
call ch_log('running tests for: ' .. fname)
for dumpname in glob(failed_root .. '_\d*\.dump', 1, 1)
call delete(dumpname)
endfor
call delete('done/' .. root)
let lines =<< trim END
let XTESTSCRIPT =<< trim END
" Track the cursor progress through a syntax test file so that any
" degenerate input can be reported. Each file will have its own cursor.
let s:cursor = 1
@ -424,7 +382,55 @@ func RunTest()
return AssertCursorForwardProgress()
enddef
END
call writefile(lines, 'Xtestscript')
let MAX_FAILED_COUNT = 5
lockvar MAX_FAILED_COUNT XTESTSCRIPT
let ok_count = 0
let failed_tests = []
let skipped_count = 0
let last_test_status = 'invalid'
" 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})}, {})
" Turn a subset of filenames etc. requested for testing into a pattern.
let filter = filereadable('../testdir/Xfilter')
\ ? readfile('../testdir/Xfilter')
\ ->map({_, v -> '^' .. substitute(v, '_$', '', '')})
\ ->join('\|')
\ : ''
" Treat "\.self-testing$" as a string NOT as a regexp.
if filter ==# '\.self-testing$'
let dirpath = 'input/selftestdir/'
let fnames = readdir(dirpath, {fname -> fname !~ '^README\.txt$'})
else
let dirpath = 'input/'
let filter ..= exists("$VIM_SYNTAX_TEST_FILTER") &&
\ !empty($VIM_SYNTAX_TEST_FILTER)
\ ? (empty(filter) ? '' : '\|') .. $VIM_SYNTAX_TEST_FILTER
\ : ''
let fnames = readdir(dirpath,
\ {subset -> {fname -> fname !~ '\~$' && fname =~# subset}}(
\ empty(filter) ? '^.\+\..\+$' : filter))
endif
for fname in fnames
let root = fnamemodify(fname, ':r')
let fname = dirpath .. fname
" Execute the test if the "done" file does not exist or when the input file
" is newer.
let in_time = getftime(fname)
let out_time = getftime('done/' .. root)
if out_time < 0 || in_time > out_time
call ch_log('running tests for: ' .. fname)
let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '')
let failed_root = 'failed/' .. root
for dumpname in glob(failed_root .. '_\d*\.dump', 1, 1)
call delete(dumpname)
endfor
call delete('done/' .. root)
call writefile(XTESTSCRIPT, 'Xtestscript')
" close all but the last window
while winnr('$') > 1
@ -500,6 +506,11 @@ func RunTest()
" Add any assert errors to s:messages.
if len(v:errors) > 0
call extend(s:messages, v:errors)
if last_test_status == 'passed'
call EraseLineAndReturnCarriage('Test ' .. root .. ' OK')
else
echon "\n"
endif
" Echo the errors here, in case the script aborts or the "messages" file
" is not displayed later.
echomsg v:errors
@ -508,13 +519,21 @@ func RunTest()
endif
if fail == 0
call Message("Test " .. root .. " OK")
if last_test_status == 'skipped'
echon "\n"
endif
let last_test_status = 'passed'
let msg = "Test " .. root .. " OK"
call Message(msg)
call EraseLineAndReturnCarriage(msg)
call writefile(['OK'], 'done/' .. root)
let ok_count += 1
else
let last_test_status = 'failed'
call Message("Test " .. root .. " FAILED")
echon "\n"
call delete('done/' .. root)
@ -525,12 +544,14 @@ func RunTest()
endif
endif
else
if last_test_status == 'passed'
call EraseLineAndReturnCarriage('Test ' .. root .. ' OK')
endif
let last_test_status = 'skipped'
call Message("Test " .. root .. " skipped")
let skipped_count += 1
endif
call EraseLineAndReturnCarriage(root)
" Append messages to the file "testdir/messages"
call AppendMessages('Input file ' .. fname .. ':')
@ -539,7 +560,10 @@ func RunTest()
endif
endfor
call EraseLineAndReturnCarriage('')
if last_test_status == 'passed' && exists('root')
call EraseLineAndReturnCarriage('Test ' .. root .. ' OK')
endif
call Message(s:test_run_message)
call Message('OK: ' .. ok_count)
call Message('FAILED: ' .. len(failed_tests) .. ': ' .. string(failed_tests))