Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 1 | " Runs all the syntax tests for which there is no "done/name" file. |
| 2 | " |
| 3 | " Current directory must be runtime/syntax. |
| 4 | |
Christian Brabandt | de79f91 | 2024-10-24 23:03:10 +0200 | [diff] [blame] | 5 | " needed because of line-continuation lines |
| 6 | set cpo&vim |
| 7 | |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 8 | " Only do this with the +eval feature |
| 9 | if 1 |
| 10 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 11 | " Remember the directory where we started. Will change to "testdir" below. |
| 12 | let syntaxDir = getcwd() |
| 13 | |
| 14 | let s:messagesFname = fnameescape(syntaxDir .. '/testdir/messages') |
| 15 | |
| 16 | let s:messages = [] |
| 17 | |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 18 | " Erase the cursor line and do not advance the cursor. (Call the function |
| 19 | " after each passing test report.) |
| 20 | def EraseLineAndReturnCarriage(line: string) |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 21 | const full_width: number = winwidth(0) |
| 22 | const half_width: number = full_width - (full_width + 1) / 2 |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 23 | if strlen(line) > half_width |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 24 | echon "\r" .. repeat("\x20", full_width) .. "\r" |
| 25 | else |
| 26 | echon repeat("\x20", half_width) .. "\r" |
| 27 | endif |
| 28 | enddef |
| 29 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 30 | " Add one message to the list of messages |
| 31 | func Message(msg) |
| 32 | echomsg a:msg |
| 33 | call add(s:messages, a:msg) |
| 34 | endfunc |
| 35 | |
| 36 | " Report a fatal message and exit |
| 37 | func Fatal(msg) |
| 38 | echoerr a:msg |
| 39 | call AppendMessages(a:msg) |
| 40 | qall! |
| 41 | endfunc |
| 42 | |
| 43 | " Append s:messages to the messages file and make it empty. |
| 44 | func AppendMessages(header) |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 45 | silent exe 'split ' .. s:messagesFname |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 46 | call append(line('$'), '') |
| 47 | call append(line('$'), a:header) |
| 48 | call append(line('$'), s:messages) |
| 49 | let s:messages = [] |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 50 | silent wq |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 51 | endfunc |
| 52 | |
| 53 | " Relevant messages are written to the "messages" file. |
| 54 | " If the file already exists it is appended to. |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 55 | silent exe 'split ' .. s:messagesFname |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 56 | call append(line('$'), repeat('=-', 70)) |
| 57 | call append(line('$'), '') |
Bram Moolenaar | 031d632 | 2023-06-22 22:38:54 +0100 | [diff] [blame] | 58 | let s:test_run_message = 'Test run on ' .. strftime("%Y %b %d %H:%M:%S") |
| 59 | call append(line('$'), s:test_run_message) |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 60 | silent wq |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 61 | |
| 62 | if syntaxDir !~ '[/\\]runtime[/\\]syntax\>' |
| 63 | call Fatal('Current directory must be "runtime/syntax"') |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 64 | endif |
| 65 | if !isdirectory('testdir') |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 66 | call Fatal('"testdir" directory not found') |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 67 | endif |
| 68 | |
| 69 | " Use the script for source code screendump testing. It sources other scripts, |
| 70 | " therefore we must "cd" there. |
| 71 | cd ../../src/testdir |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 72 | source util/screendump.vim |
| 73 | source util/term_util.vim |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 74 | exe 'cd ' .. fnameescape(syntaxDir) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 75 | |
| 76 | " For these tests we need to be able to run terminal Vim with 256 colors. On |
| 77 | " MS-Windows the console only has 16 colors and the GUI can't run in a |
| 78 | " terminal. |
| 79 | if !CanRunVimInTerminal() |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 80 | call Fatal('Cannot make screendumps, aborting') |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 81 | endif |
| 82 | |
| 83 | cd testdir |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 84 | |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 85 | if !isdirectory('done') |
| 86 | call mkdir('done') |
| 87 | endif |
| 88 | |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 89 | if !isdirectory('failed') |
| 90 | call mkdir('failed') |
| 91 | endif |
| 92 | |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 93 | set nocp |
| 94 | set nowrapscan |
| 95 | set report=9999 |
| 96 | set modeline |
| 97 | set debug=throw |
| 98 | set nomore |
| 99 | |
| 100 | au! SwapExists * call HandleSwapExists() |
| 101 | func HandleSwapExists() |
| 102 | " Ignore finding a swap file for the test input, the user might be editing |
| 103 | " it and that's OK. |
| 104 | if expand('<afile>') =~ 'input[/\\].*\..*' |
| 105 | let v:swapchoice = 'e' |
| 106 | endif |
| 107 | endfunc |
| 108 | |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 109 | " Trace ruler liveness on demand. |
| 110 | if !empty($VIM_SYNTAX_TEST_LOG) && filewritable($VIM_SYNTAX_TEST_LOG) |
| 111 | def s:TraceRulerLiveness(context: string, times: number, tail: string) |
| 112 | writefile([printf('%s: %4d: %s', context, times, tail)], |
| 113 | $VIM_SYNTAX_TEST_LOG, |
| 114 | 'a') |
| 115 | enddef |
| 116 | else |
| 117 | def s:TraceRulerLiveness(_: string, _: number, _: string) |
| 118 | enddef |
| 119 | endif |
| 120 | |
| 121 | " See ":help 'ruler'". |
| 122 | def s:CannotSeeLastLine(ruler: list<string>): bool |
| 123 | return !(get(ruler, -1, '') ==# 'All' || get(ruler, -1, '') ==# 'Bot') |
| 124 | enddef |
| 125 | |
| 126 | def s:CannotDumpNextPage(buf: number, prev_ruler: list<string>, ruler: list<string>): bool |
| 127 | return !(ruler !=# prev_ruler && |
| 128 | len(ruler) == 2 && |
| 129 | ruler[1] =~# '\%(\d%\|\<Bot\)$' && |
| 130 | get(term_getcursor(buf), 0) != 20) |
| 131 | enddef |
| 132 | |
| 133 | def s:CannotDumpFirstPage(buf: number, _: list<string>, ruler: list<string>): bool |
| 134 | return !(len(ruler) == 2 && |
| 135 | ruler[1] =~# '\%(\<All\|\<Top\)$' && |
| 136 | get(term_getcursor(buf), 0) != 20) |
| 137 | enddef |
| 138 | |
| 139 | def s:CannotDumpShellFirstPage(buf: number, _: list<string>, ruler: list<string>): bool |
| 140 | return !(len(ruler) > 3 && |
| 141 | get(ruler, -1, '') =~# '\%(\<All\|\<Top\)$' && |
| 142 | get(term_getcursor(buf), 0) != 20) |
| 143 | enddef |
| 144 | |
| 145 | " Poll for updates of the cursor position in the terminal buffer occupying the |
| 146 | " first window. (ALWAYS call the function or its equivalent before calling |
| 147 | " "VerifyScreenDump()" *and* after calling any number of "term_sendkeys()".) |
| 148 | def s:TermPollRuler( |
| 149 | CannotDumpPage: func, # (TYPE FOR LEGACY CONTEXT CALL SITES.) |
| 150 | buf: number, |
| 151 | in_name_and_out_name: string): list<string> |
| 152 | # Expect defaults from "term_util#RunVimInTerminal()". |
Aliaksei Budavei | 8418446 | 2024-05-21 01:10:26 +0300 | [diff] [blame] | 153 | if winwidth(1) != 75 || winheight(1) != 20 |
| 154 | ch_log(printf('Aborting for %s: (75 x 20) != (%d x %d)', |
| 155 | in_name_and_out_name, |
| 156 | winwidth(1), |
| 157 | winheight(1))) |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 158 | return ['0,0-1', 'All'] |
Aliaksei Budavei | 8418446 | 2024-05-21 01:10:26 +0300 | [diff] [blame] | 159 | endif |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 160 | # A two-fold role for redrawing: |
| 161 | # (*) in case the terminal buffer cannot redraw itself just yet; |
| 162 | # (*) to avoid extra "real estate" checks. |
Aliaksei Budavei | 8418446 | 2024-05-21 01:10:26 +0300 | [diff] [blame] | 163 | redraw |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 164 | # The contents of "ruler". |
| 165 | var ruler: list<string> = [] |
| 166 | # Attempts at most, targeting ASan-instrumented Vim builds. |
| 167 | var times: number = 2048 |
| 168 | # Check "real estate" of the terminal buffer. Read and compare its ruler |
| 169 | # line and let "Xtestscript#s:AssertCursorForwardProgress()" do the rest. |
| 170 | # Note that the cursor ought to be advanced after each successive call of |
| 171 | # this function yet its relative position need not be changed (e.g. "0%"). |
| 172 | while CannotDumpPage(ruler) && times > 0 |
| 173 | ruler = split(term_getline(buf, 20)) |
| 174 | sleep 1m |
| 175 | times -= 1 |
| 176 | if times % 8 == 0 |
| 177 | redraw |
| 178 | endif |
| 179 | endwhile |
| 180 | TraceRulerLiveness('P', (2048 - times), in_name_and_out_name) |
| 181 | return ruler |
| 182 | enddef |
| 183 | |
| 184 | " Prevent "s:TermPollRuler()" from prematurely reading the cursor position, |
| 185 | " which is available at ":edit", after outracing the loading of syntax etc. in |
| 186 | " the terminal buffer. (Call the function before calling "VerifyScreenDump()" |
| 187 | " for the first time.) |
| 188 | def s:TermWaitAndPollRuler(buf: number, in_name_and_out_name: string): list<string> |
| 189 | # Expect defaults from "term_util#RunVimInTerminal()". |
| 190 | if winwidth(1) != 75 || winheight(1) != 20 |
| 191 | ch_log(printf('Aborting for %s: (75 x 20) != (%d x %d)', |
| 192 | in_name_and_out_name, |
| 193 | winwidth(1), |
| 194 | winheight(1))) |
| 195 | return ['0,0-1', 'All'] |
| 196 | endif |
| 197 | # The contents of "ruler". |
| 198 | var ruler: string = '' |
| 199 | # Attempts at most, targeting ASan-instrumented Vim builds. |
| 200 | var times: number = 32768 |
| 201 | # Check "real estate" of the terminal buffer. Expect a known token to be |
| 202 | # rendered in the terminal buffer; its prefix must be "is_" so that buffer |
| 203 | # variables from "sh.vim" can be matched (see "Xtestscript#ShellInfo()"). |
| 204 | # Verify that the whole line is available! |
| 205 | while ruler !~# '^is_.\+\s\%(All\|Top\)$' && times > 0 |
| 206 | ruler = term_getline(buf, 20) |
| 207 | sleep 1m |
| 208 | times -= 1 |
| 209 | if times % 16 == 0 |
| 210 | redraw |
| 211 | endif |
| 212 | endwhile |
| 213 | TraceRulerLiveness('W', (32768 - times), in_name_and_out_name) |
| 214 | if strpart(ruler, 0, 8) !=# 'is_nonce' |
| 215 | # Retain any of "b:is_(bash|dash|kornshell|posix|sh)" entries and let |
| 216 | # "CannotDumpShellFirstPage()" win the cursor race. |
| 217 | return TermPollRuler( |
| 218 | function(CannotDumpShellFirstPage, [buf, []]), |
| 219 | buf, |
| 220 | in_name_and_out_name) |
| 221 | else |
| 222 | # Clear the "is_nonce" token and let "CannotDumpFirstPage()" win any |
| 223 | # race. |
| 224 | term_sendkeys(buf, ":redraw!\<CR>") |
| 225 | endif |
| 226 | return TermPollRuler( |
| 227 | function(CannotDumpFirstPage, [buf, []]), |
| 228 | buf, |
| 229 | in_name_and_out_name) |
Aliaksei Budavei | 8418446 | 2024-05-21 01:10:26 +0300 | [diff] [blame] | 230 | enddef |
| 231 | |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 232 | func RunTest() |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 233 | let XTESTSCRIPT =<< trim END |
| 234 | " Track the cursor progress through a syntax test file so that any |
| 235 | " degenerate input can be reported. Each file will have its own cursor. |
| 236 | let s:cursor = 1 |
| 237 | |
| 238 | " extra info for shell variables |
| 239 | func ShellInfo() |
| 240 | let msg = '' |
| 241 | for [key, val] in items(b:) |
| 242 | if key =~ '^is_' |
| 243 | let msg ..= key .. ': ' .. val .. ', ' |
| 244 | endif |
| 245 | endfor |
| 246 | if msg != '' |
| 247 | echomsg msg |
| 248 | endif |
| 249 | endfunc |
| 250 | |
| 251 | au! SwapExists * call HandleSwapExists() |
| 252 | func HandleSwapExists() |
| 253 | " Ignore finding a swap file for the test input, the user might be |
| 254 | " editing it and that's OK. |
| 255 | if expand('<afile>') =~ 'input[/\\].*\..*' |
| 256 | let v:swapchoice = 'e' |
| 257 | endif |
| 258 | endfunc |
| 259 | |
| 260 | func LoadFiletype(type) |
| 261 | for file in glob("ftplugin/" .. a:type .. "*.vim", 1, 1) |
| 262 | exe "source " .. file |
| 263 | endfor |
| 264 | redraw! |
| 265 | endfunc |
| 266 | |
| 267 | func SetUpVim() |
| 268 | call cursor(1, 1) |
| 269 | " Defend against rogue VIM_TEST_SETUP commands. |
| 270 | for _ in range(20) |
| 271 | let lnum = search('\C\<VIM_TEST_SETUP\>', 'eW', 20) |
| 272 | if lnum < 1 |
| 273 | break |
| 274 | endif |
| 275 | exe substitute(getline(lnum), '\C.*\<VIM_TEST_SETUP\>', '', '') |
| 276 | endfor |
| 277 | call cursor(1, 1) |
| 278 | " BEGIN [runtime/defaults.vim] |
| 279 | " Also, disable italic highlighting to avoid issues on some terminals. |
| 280 | set display=lastline ruler scrolloff=5 t_ZH= t_ZR= |
| 281 | syntax on |
| 282 | " END [runtime/defaults.vim] |
| 283 | redraw! |
| 284 | endfunc |
| 285 | |
| 286 | def s:AssertCursorForwardProgress(): bool |
| 287 | const curnum: number = line('.') |
| 288 | if curnum <= cursor |
| 289 | # Use "actions/upload-artifact@v4" of ci.yml for delivery. |
| 290 | writefile([printf('No cursor progress: %d <= %d (%s). Please file an issue.', |
| 291 | curnum, |
| 292 | cursor, |
| 293 | bufname('%'))], |
| 294 | 'failed/00-FIXME', |
| 295 | 'a') |
| 296 | bwipeout! |
| 297 | endif |
| 298 | cursor = curnum |
| 299 | return true |
| 300 | enddef |
| 301 | |
| 302 | def ScrollToSecondPage(estate: number, op_wh: number, op_so: number): bool |
| 303 | if line('.') != 1 || line('w$') >= line('$') |
| 304 | return AssertCursorForwardProgress() |
| 305 | endif |
| 306 | try |
| 307 | set scrolloff=0 |
| 308 | # Advance mark "c"[ursor] along with the cursor. |
| 309 | norm! Lmc |
| 310 | if foldclosed('.') < 0 && |
| 311 | (strdisplaywidth(getline('.')) + &l:fdc * winheight(1)) >= estate |
| 312 | # Make for an exit for a screenful long line. |
| 313 | norm! j^ |
| 314 | return AssertCursorForwardProgress() |
| 315 | else |
| 316 | # Place the cursor on the actually last visible line. |
| 317 | while winline() < op_wh |
| 318 | const lastnum: number = winline() |
| 319 | norm! gjmc |
| 320 | if lastnum > winline() |
| 321 | break |
| 322 | endif |
| 323 | endwhile |
| 324 | norm! zt |
| 325 | endif |
| 326 | finally |
| 327 | # COMPATIBILITY: Scroll up around "scrolloff" lines. |
| 328 | &scrolloff = max([1, op_so]) |
| 329 | endtry |
| 330 | norm! ^ |
| 331 | return AssertCursorForwardProgress() |
| 332 | enddef |
| 333 | |
| 334 | def ScrollToNextPage(estate: number, op_wh: number, op_so: number): bool |
| 335 | if line('.') == 1 || line('w$') >= line('$') |
| 336 | return AssertCursorForwardProgress() |
| 337 | endif |
| 338 | try |
| 339 | set scrolloff=0 |
| 340 | # Advance mark "c"[ursor] along with the cursor. |
| 341 | norm! Lmc |
| 342 | if foldclosed('.') < 0 && |
| 343 | (strdisplaywidth(getline('.')) + &l:fdc * winheight(1)) >= estate |
| 344 | # Make for an exit for a screenful long line. |
| 345 | norm! j^ |
| 346 | return AssertCursorForwardProgress() |
| 347 | else |
| 348 | # Place the cursor on the actually last visible line. |
| 349 | while winline() < op_wh |
| 350 | const lastnum: number = winline() |
| 351 | norm! gjmc |
| 352 | if lastnum > winline() |
| 353 | break |
| 354 | endif |
| 355 | endwhile |
| 356 | endif |
| 357 | finally |
| 358 | # COMPATIBILITY: Scroll up/down around "scrolloff" lines. |
| 359 | &scrolloff = max([1, op_so]) |
| 360 | endtry |
| 361 | norm! zt |
| 362 | const marknum: number = line("'c") |
| 363 | # Eschew &smoothscroll since line("`c") is not supported. |
| 364 | # Remember that "w0" can point to the first line of a _closed_ fold |
| 365 | # whereas the last line of a _closed_ fold can be marked. |
| 366 | if line('w0') > marknum |
| 367 | while line('w0') > marknum |
| 368 | exe "norm! \<C-y>" |
| 369 | endwhile |
| 370 | if line('w0') != marknum |
| 371 | exe "norm! \<C-e>H" |
| 372 | endif |
| 373 | # Handle non-wrapped lines. |
| 374 | elseif line('w0') < marknum |
| 375 | while line('w0') < marknum |
| 376 | exe "norm! \<C-e>" |
| 377 | endwhile |
| 378 | if line('w0') != marknum |
| 379 | exe "norm! \<C-y>H" |
| 380 | endif |
| 381 | endif |
| 382 | norm! ^ |
| 383 | return AssertCursorForwardProgress() |
| 384 | enddef |
| 385 | END |
| 386 | let MAX_FAILED_COUNT = 5 |
Aliaksei Budavei | 7ceca3e | 2025-03-16 20:59:28 +0100 | [diff] [blame] | 387 | let DUMP_OPTS = exists("$VIM_SYNTAX_TEST_WAIT_TIME") && |
| 388 | \ !empty($VIM_SYNTAX_TEST_WAIT_TIME) |
| 389 | \ ? {'wait': max([1, str2nr($VIM_SYNTAX_TEST_WAIT_TIME)])} |
| 390 | \ : {} |
| 391 | lockvar DUMP_OPTS MAX_FAILED_COUNT XTESTSCRIPT |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 392 | let ok_count = 0 |
Aliaksei Budavei | b5459ee | 2025-03-23 10:42:23 +0100 | [diff] [blame] | 393 | let disused_pages = [] |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 394 | let failed_tests = [] |
| 395 | let skipped_count = 0 |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 396 | let last_test_status = 'invalid' |
Aliaksei Budavei | b5459ee | 2025-03-23 10:42:23 +0100 | [diff] [blame] | 397 | let filter = '' |
Aliaksei Budavei | f6069a7 | 2024-03-05 22:34:36 +0300 | [diff] [blame] | 398 | " Create a map of setup configuration filenames with their basenames as keys. |
| 399 | let setup = glob('input/setup/*.vim', 1, 1) |
| 400 | \ ->reduce({d, f -> extend(d, {fnamemodify(f, ':t:r'): f})}, {}) |
Aliaksei Budavei | ec02294 | 2024-10-06 16:57:33 +0200 | [diff] [blame] | 401 | " Turn a subset of filenames etc. requested for testing into a pattern. |
Aliaksei Budavei | b5459ee | 2025-03-23 10:42:23 +0100 | [diff] [blame] | 402 | if filereadable('../testdir/Xfilter') |
| 403 | let filter = readfile('../testdir/Xfilter') |
| 404 | \ ->map({_, v -> '^' .. escape(substitute(v, '_$', '', ''), '.')}) |
Aliaksei Budavei | ec02294 | 2024-10-06 16:57:33 +0200 | [diff] [blame] | 405 | \ ->join('\|') |
Aliaksei Budavei | b5459ee | 2025-03-23 10:42:23 +0100 | [diff] [blame] | 406 | call delete('../testdir/Xfilter') |
| 407 | endif |
Aliaksei Budavei | f6069a7 | 2024-03-05 22:34:36 +0300 | [diff] [blame] | 408 | |
Aliaksei Budavei | 7ceca3e | 2025-03-16 20:59:28 +0100 | [diff] [blame] | 409 | " Treat "^self-testing" as a string NOT as a regexp. |
| 410 | if filter ==# '^self-testing' |
Aliaksei Budavei | d2f4987 | 2024-05-24 19:14:16 +0300 | [diff] [blame] | 411 | let dirpath = 'input/selftestdir/' |
Aliaksei Budavei | d33afe1 | 2024-08-12 18:37:15 +0200 | [diff] [blame] | 412 | let fnames = readdir(dirpath, {fname -> fname !~ '^README\.txt$'}) |
Aliaksei Budavei | d2f4987 | 2024-05-24 19:14:16 +0300 | [diff] [blame] | 413 | else |
| 414 | let dirpath = 'input/' |
Aliaksei Budavei | ec02294 | 2024-10-06 16:57:33 +0200 | [diff] [blame] | 415 | let filter ..= exists("$VIM_SYNTAX_TEST_FILTER") && |
| 416 | \ !empty($VIM_SYNTAX_TEST_FILTER) |
| 417 | \ ? (empty(filter) ? '' : '\|') .. $VIM_SYNTAX_TEST_FILTER |
| 418 | \ : '' |
| 419 | let fnames = readdir(dirpath, |
| 420 | \ {subset -> {fname -> fname !~ '\~$' && fname =~# subset}}( |
| 421 | \ empty(filter) ? '^.\+\..\+$' : filter)) |
Aliaksei Budavei | d2f4987 | 2024-05-24 19:14:16 +0300 | [diff] [blame] | 422 | endif |
Bram Moolenaar | 7d0dbd0 | 2023-06-24 00:56:50 +0100 | [diff] [blame] | 423 | |
Aliaksei Budavei | d2f4987 | 2024-05-24 19:14:16 +0300 | [diff] [blame] | 424 | for fname in fnames |
| 425 | let root = fnamemodify(fname, ':r') |
| 426 | let fname = dirpath .. fname |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 427 | |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 428 | " Execute the test if the "done" file does not exist or when the input file |
| 429 | " is newer. |
| 430 | let in_time = getftime(fname) |
| 431 | let out_time = getftime('done/' .. root) |
| 432 | if out_time < 0 || in_time > out_time |
| 433 | call ch_log('running tests for: ' .. fname) |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 434 | let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '') |
| 435 | let failed_root = 'failed/' .. root |
Bram Moolenaar | 7d0dbd0 | 2023-06-24 00:56:50 +0100 | [diff] [blame] | 436 | |
Aliaksei Budavei | b5459ee | 2025-03-23 10:42:23 +0100 | [diff] [blame] | 437 | for pagename in glob(failed_root .. '_\d*\.dump', 1, 1) |
| 438 | call delete(pagename) |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 439 | endfor |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 440 | call delete('done/' .. root) |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 441 | call writefile(XTESTSCRIPT, 'Xtestscript') |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 442 | |
| 443 | " close all but the last window |
| 444 | while winnr('$') > 1 |
| 445 | close |
| 446 | endwhile |
| 447 | |
| 448 | " Redraw to make sure that messages are cleared and there is enough space |
| 449 | " for the terminal window. |
| 450 | redraw |
| 451 | |
Aliaksei Budavei | 93edd25 | 2024-03-05 22:34:36 +0300 | [diff] [blame] | 452 | " Let "Xtestscript#SetUpVim()" turn the syntax on. |
Aliaksei Budavei | f6069a7 | 2024-03-05 22:34:36 +0300 | [diff] [blame] | 453 | let prefix = '-Nu NONE -S Xtestscript' |
| 454 | let path = get(setup, root, '') |
| 455 | " Source the found setup configuration file. |
| 456 | let args = !empty(path) |
| 457 | \ ? prefix .. ' -S ' .. path |
| 458 | \ : prefix |
| 459 | let buf = RunVimInTerminal(args, {}) |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 460 | " edit the file only after catching the SwapExists event |
| 461 | call term_sendkeys(buf, ":edit " .. fname .. "\<CR>") |
Aliaksei Budavei | 93edd25 | 2024-03-05 22:34:36 +0300 | [diff] [blame] | 462 | " set up the testing environment |
| 463 | call term_sendkeys(buf, ":call SetUpVim()\<CR>") |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 464 | " load filetype specific settings |
| 465 | call term_sendkeys(buf, ":call LoadFiletype('" .. filetype .. "')\<CR>") |
| 466 | |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 467 | " Make a synchronisation point between buffers by requesting to echo |
| 468 | " a known token in the terminal buffer and asserting its availability |
| 469 | " with "s:TermWaitAndPollRuler()". |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 470 | if filetype == 'sh' |
| 471 | call term_sendkeys(buf, ":call ShellInfo()\<CR>") |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 472 | else |
| 473 | call term_sendkeys(buf, ":echo 'is_nonce'\<CR>") |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 474 | endif |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 475 | |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 476 | let root_00 = root .. '_00' |
Aliaksei Budavei | 8418446 | 2024-05-21 01:10:26 +0300 | [diff] [blame] | 477 | let in_name_and_out_name = fname .. ': failed/' .. root_00 .. '.dump' |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 478 | " Queue up all "term_sendkeys()"es and let them finish before returning |
| 479 | " from "s:TermWaitAndPollRuler()". |
| 480 | let ruler = s:TermWaitAndPollRuler(buf, in_name_and_out_name) |
Aliaksei Budavei | 8418446 | 2024-05-21 01:10:26 +0300 | [diff] [blame] | 481 | call ch_log('First screendump for ' .. in_name_and_out_name) |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 482 | " Make a screendump at the start of the file: failed/root_00.dump |
Aliaksei Budavei | 7ceca3e | 2025-03-16 20:59:28 +0100 | [diff] [blame] | 483 | let fail = VerifyScreenDump(buf, root_00, DUMP_OPTS) |
Aliaksei Budavei | b5459ee | 2025-03-23 10:42:23 +0100 | [diff] [blame] | 484 | let nr = 0 |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 485 | |
Aliaksei Budavei | 7197143 | 2024-07-05 21:30:02 +0300 | [diff] [blame] | 486 | " Accommodate the next code block to "buf"'s contingency for self |
| 487 | " wipe-out. |
| 488 | try |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 489 | let keys_a = ":call ScrollToSecondPage((18 * 75 + 1), 19, 5) | redraw!\<CR>" |
| 490 | let keys_b = ":call ScrollToNextPage((18 * 75 + 1), 19, 5) | redraw!\<CR>" |
| 491 | while s:CannotSeeLastLine(ruler) |
| 492 | call term_sendkeys(buf, keys_a) |
| 493 | let keys_a = keys_b |
Aliaksei Budavei | 8418446 | 2024-05-21 01:10:26 +0300 | [diff] [blame] | 494 | let nr += 1 |
| 495 | let root_next = printf('%s_%02d', root, nr) |
| 496 | let in_name_and_out_name = fname .. ': failed/' .. root_next .. '.dump' |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 497 | let ruler = s:TermPollRuler( |
| 498 | \ function('s:CannotDumpNextPage', [buf, ruler]), |
| 499 | \ buf, |
| 500 | \ in_name_and_out_name) |
| 501 | call ch_log('Next screendump for ' .. in_name_and_out_name) |
| 502 | " Make a screendump of every 18 lines of the file: failed/root_NN.dump |
Aliaksei Budavei | 7ceca3e | 2025-03-16 20:59:28 +0100 | [diff] [blame] | 503 | let fail += VerifyScreenDump(buf, root_next, DUMP_OPTS) |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 504 | endwhile |
Aliaksei Budavei | 7197143 | 2024-07-05 21:30:02 +0300 | [diff] [blame] | 505 | call StopVimInTerminal(buf) |
| 506 | finally |
| 507 | call delete('Xtestscript') |
| 508 | endtry |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 509 | |
Aliaksei Budavei | b5459ee | 2025-03-23 10:42:23 +0100 | [diff] [blame] | 510 | let nr += 1 |
| 511 | let pagename = printf('dumps/%s_%02d.dump', root, nr) |
| 512 | |
| 513 | while filereadable(pagename) |
| 514 | call add(disused_pages, pagename) |
| 515 | let nr += 1 |
| 516 | let pagename = printf('dumps/%s_%02d.dump', root, nr) |
| 517 | endwhile |
| 518 | |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 519 | " redraw here to avoid the following messages to get mixed up with screen |
| 520 | " output. |
| 521 | redraw |
| 522 | |
| 523 | " Add any assert errors to s:messages. |
| 524 | if len(v:errors) > 0 |
| 525 | call extend(s:messages, v:errors) |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 526 | if last_test_status == 'passed' |
| 527 | call EraseLineAndReturnCarriage('Test ' .. root .. ' OK') |
| 528 | else |
| 529 | echon "\n" |
| 530 | endif |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 531 | " Echo the errors here, in case the script aborts or the "messages" file |
| 532 | " is not displayed later. |
| 533 | echomsg v:errors |
| 534 | let v:errors = [] |
| 535 | let fail += 1 |
| 536 | endif |
| 537 | |
| 538 | if fail == 0 |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 539 | if last_test_status == 'skipped' |
| 540 | echon "\n" |
| 541 | endif |
| 542 | let last_test_status = 'passed' |
| 543 | let msg = "Test " .. root .. " OK" |
| 544 | call Message(msg) |
| 545 | call EraseLineAndReturnCarriage(msg) |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 546 | |
| 547 | call writefile(['OK'], 'done/' .. root) |
| 548 | |
| 549 | let ok_count += 1 |
| 550 | else |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 551 | let last_test_status = 'failed' |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 552 | call Message("Test " .. root .. " FAILED") |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 553 | echon "\n" |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 554 | |
| 555 | call delete('done/' .. root) |
| 556 | |
| 557 | eval failed_tests->add(root) |
| 558 | if len(failed_tests) > MAX_FAILED_COUNT |
| 559 | call Message('') |
| 560 | call Message('Too many errors, aborting') |
| 561 | endif |
| 562 | endif |
| 563 | else |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 564 | if last_test_status == 'passed' |
| 565 | call EraseLineAndReturnCarriage('Test ' .. root .. ' OK') |
| 566 | endif |
| 567 | let last_test_status = 'skipped' |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 568 | call Message("Test " .. root .. " skipped") |
| 569 | let skipped_count += 1 |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 570 | endif |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 571 | |
| 572 | " Append messages to the file "testdir/messages" |
| 573 | call AppendMessages('Input file ' .. fname .. ':') |
| 574 | |
| 575 | if len(failed_tests) > MAX_FAILED_COUNT |
| 576 | break |
| 577 | endif |
| 578 | endfor |
| 579 | |
Aliaksei Budavei | f63c346 | 2025-03-08 16:58:17 +0100 | [diff] [blame] | 580 | if last_test_status == 'passed' && exists('root') |
| 581 | call EraseLineAndReturnCarriage('Test ' .. root .. ' OK') |
| 582 | endif |
| 583 | |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 584 | call Message(s:test_run_message) |
| 585 | call Message('OK: ' .. ok_count) |
| 586 | call Message('FAILED: ' .. len(failed_tests) .. ': ' .. string(failed_tests)) |
| 587 | call Message('skipped: ' .. skipped_count) |
Aliaksei Budavei | d33afe1 | 2024-08-12 18:37:15 +0200 | [diff] [blame] | 588 | |
Aliaksei Budavei | b5459ee | 2025-03-23 10:42:23 +0100 | [diff] [blame] | 589 | for pagename in disused_pages |
| 590 | call Message(printf('No input page found for "%s"', pagename)) |
| 591 | endfor |
| 592 | |
Aliaksei Budavei | d33afe1 | 2024-08-12 18:37:15 +0200 | [diff] [blame] | 593 | if !empty(failed_tests) |
| 594 | call Message('') |
| 595 | call Message('View generated screendumps with "../../src/vim --clean -S testdir/viewdumps.vim"') |
| 596 | endif |
| 597 | |
Christian Brabandt | 203c722 | 2024-10-29 20:21:42 +0100 | [diff] [blame] | 598 | call AppendMessages('== SUMMARY SYNTAX TESTS ==') |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 599 | |
| 600 | if len(failed_tests) > 0 |
| 601 | " have make report an error |
| 602 | cquit |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 603 | endif |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 604 | endfunc |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 605 | |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 606 | call RunTest() |
Christian Brabandt | 627c950 | 2024-02-10 13:02:17 +0100 | [diff] [blame] | 607 | |
| 608 | " Matching "if 1" at the start. |
| 609 | endif |
| 610 | |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 611 | qall! |
Christian Brabandt | 5682443 | 2024-02-28 21:24:25 +0100 | [diff] [blame] | 612 | |
Aliaksei Budavei | 7003a5d | 2025-03-01 16:28:20 +0100 | [diff] [blame] | 613 | " vim:sw=2:ts=8:noet: |