| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  | " Runs all the syntax tests for which there is no "done/name" file. | 
					
						
							|  |  |  | " | 
					
						
							|  |  |  | " Current directory must be runtime/syntax. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Only do this with the +eval feature | 
					
						
							|  |  |  | if 1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  | " Remember the directory where we started.  Will change to "testdir" below. | 
					
						
							|  |  |  | let syntaxDir = getcwd() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let s:messagesFname = fnameescape(syntaxDir .. '/testdir/messages') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let s:messages = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Add one message to the list of messages | 
					
						
							|  |  |  | func Message(msg) | 
					
						
							|  |  |  |   echomsg a:msg | 
					
						
							|  |  |  |   call add(s:messages, a:msg) | 
					
						
							|  |  |  | endfunc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Report a fatal message and exit | 
					
						
							|  |  |  | func Fatal(msg) | 
					
						
							|  |  |  |   echoerr a:msg | 
					
						
							|  |  |  |   call AppendMessages(a:msg) | 
					
						
							|  |  |  |   qall! | 
					
						
							|  |  |  | endfunc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Append s:messages to the messages file and make it empty. | 
					
						
							|  |  |  | func AppendMessages(header) | 
					
						
							|  |  |  |   exe 'split ' .. s:messagesFname | 
					
						
							|  |  |  |   call append(line('$'), '') | 
					
						
							|  |  |  |   call append(line('$'), a:header) | 
					
						
							|  |  |  |   call append(line('$'), s:messages) | 
					
						
							|  |  |  |   let s:messages = [] | 
					
						
							|  |  |  |   wq | 
					
						
							|  |  |  | endfunc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Relevant messages are written to the "messages" file. | 
					
						
							|  |  |  | " If the file already exists it is appended to. | 
					
						
							|  |  |  | exe 'split ' .. s:messagesFname | 
					
						
							|  |  |  | call append(line('$'), repeat('=-', 70)) | 
					
						
							|  |  |  | call append(line('$'), '') | 
					
						
							| 
									
										
										
										
											2023-06-22 22:38:54 +01:00
										 |  |  | let s:test_run_message = 'Test run on ' .. strftime("%Y %b %d %H:%M:%S") | 
					
						
							|  |  |  | call append(line('$'), s:test_run_message) | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  | wq | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if syntaxDir !~ '[/\\]runtime[/\\]syntax\>' | 
					
						
							|  |  |  |   call Fatal('Current directory must be "runtime/syntax"') | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  | endif | 
					
						
							|  |  |  | if !isdirectory('testdir') | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |   call Fatal('"testdir" directory not found') | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Use the script for source code screendump testing.  It sources other scripts, | 
					
						
							|  |  |  | " therefore we must "cd" there. | 
					
						
							|  |  |  | cd ../../src/testdir | 
					
						
							|  |  |  | source screendump.vim | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  | exe 'cd ' .. fnameescape(syntaxDir) | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | " For these tests we need to be able to run terminal Vim with 256 colors.  On | 
					
						
							|  |  |  | " MS-Windows the console only has 16 colors and the GUI can't run in a | 
					
						
							|  |  |  | " terminal. | 
					
						
							|  |  |  | if !CanRunVimInTerminal() | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |   call Fatal('Cannot make screendumps, aborting') | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | cd testdir | 
					
						
							|  |  |  | if !isdirectory('done') | 
					
						
							|  |  |  |   call mkdir('done') | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set nocp | 
					
						
							|  |  |  | set nowrapscan | 
					
						
							|  |  |  | set report=9999 | 
					
						
							|  |  |  | set modeline | 
					
						
							|  |  |  | set debug=throw | 
					
						
							|  |  |  | set nomore | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | au! SwapExists * call HandleSwapExists() | 
					
						
							|  |  |  | func HandleSwapExists() | 
					
						
							|  |  |  |   " Ignore finding a swap file for the test input, the user might be editing | 
					
						
							|  |  |  |   " it and that's OK. | 
					
						
							|  |  |  |   if expand('<afile>') =~ 'input[/\\].*\..*' | 
					
						
							|  |  |  |     let v:swapchoice = 'e' | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endfunc | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  | let ok_count = 0 | 
					
						
							| 
									
										
										
										
											2023-06-22 22:38:54 +01:00
										 |  |  | let failed_tests = [] | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  | let skipped_count = 0 | 
					
						
							|  |  |  | let MAX_FAILED_COUNT = 5 | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  | for fname in glob('input/*.*', 1, 1) | 
					
						
							|  |  |  |   if fname =~ '\~$' | 
					
						
							|  |  |  |     " backup file, skip | 
					
						
							|  |  |  |     continue | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let linecount = readfile(fname)->len() | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |   let root = fnamemodify(fname, ':t:r') | 
					
						
							|  |  |  |   let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '') | 
					
						
							|  |  |  |   let failed_root = 'failed/' .. root | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |   " Execute the test if the "done" file does not exist or when the input file | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |   " is newer. | 
					
						
							|  |  |  |   let in_time = getftime(fname) | 
					
						
							|  |  |  |   let out_time = getftime('done/' .. root) | 
					
						
							|  |  |  |   if out_time < 0 || in_time > out_time | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |     call ch_log('running tests for: ' .. fname) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for dumpname in glob(failed_root .. '_\d*\.dump', 1, 1) | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |       call delete(dumpname) | 
					
						
							|  |  |  |     endfor | 
					
						
							|  |  |  |     call delete('done/' .. root) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let lines =<< trim END | 
					
						
							|  |  |  |       syntax on | 
					
						
							| 
									
										
										
										
											2023-06-24 00:56:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       " extra info for shell variables | 
					
						
							|  |  |  |       func ShellInfo() | 
					
						
							|  |  |  | 	let msg = '' | 
					
						
							|  |  |  | 	for [key, val] in items(b:) | 
					
						
							|  |  |  | 	  if key =~ '^is_' | 
					
						
							|  |  |  | 	    let msg ..= key .. ': ' .. val .. ', ' | 
					
						
							|  |  |  | 	  endif | 
					
						
							|  |  |  | 	endfor | 
					
						
							|  |  |  | 	if msg != '' | 
					
						
							|  |  |  | 	  echomsg msg | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  |       endfunc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       au! SwapExists * call HandleSwapExists() | 
					
						
							|  |  |  |       func HandleSwapExists() | 
					
						
							|  |  |  | 	" Ignore finding a swap file for the test input, the user might be | 
					
						
							|  |  |  | 	" editing it and that's OK. | 
					
						
							|  |  |  | 	if expand('<afile>') =~ 'input[/\\].*\..*' | 
					
						
							|  |  |  | 	  let v:swapchoice = 'e' | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  |       endfunc | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |     END | 
					
						
							|  |  |  |     call writefile(lines, 'Xtestscript') | 
					
						
							| 
									
										
										
										
											2023-06-23 22:59:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     " close all but the last window | 
					
						
							|  |  |  |     while winnr('$') > 1 | 
					
						
							|  |  |  |       close | 
					
						
							|  |  |  |     endwhile | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     " Redraw to make sure that messages are cleared and there is enough space | 
					
						
							|  |  |  |     " for the terminal window. | 
					
						
							|  |  |  |     redraw | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-24 00:56:50 +01:00
										 |  |  |     let buf = RunVimInTerminal('-S Xtestscript', {}) | 
					
						
							|  |  |  |     " edit the file only after catching the SwapExists event | 
					
						
							|  |  |  |     call term_sendkeys(buf, ":edit " .. fname .. "\<CR>") | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-24 00:56:50 +01:00
										 |  |  |     if filetype == 'sh' | 
					
						
							|  |  |  |       call term_sendkeys(buf, ":call ShellInfo()\<CR>") | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     " Screendump at the start of the file: failed/root_00.dump | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |     let root_00 = root .. '_00' | 
					
						
							|  |  |  |     call ch_log('First screendump for ' .. fname .. ': failed/' .. root_00 .. '.dump') | 
					
						
							|  |  |  |     let fail = VerifyScreenDump(buf, root_00, {}) | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-24 00:56:50 +01:00
										 |  |  |     " clear the shell info if there are not enough lines to cause a scroll | 
					
						
							|  |  |  |     if filetype == 'sh' && linecount <= 19 | 
					
						
							|  |  |  |       call term_sendkeys(buf, ":redraw\<CR>") | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |     " Make a Screendump every 18 lines of the file: failed/root_NN.dump | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |     let topline = 1 | 
					
						
							|  |  |  |     let nr = 1 | 
					
						
							|  |  |  |     while linecount - topline > 20 | 
					
						
							|  |  |  |       let topline += 18 | 
					
						
							|  |  |  |       call term_sendkeys(buf, printf("%dGzt", topline)) | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |       let root_next = root .. printf('_%02d', nr) | 
					
						
							|  |  |  |       call ch_log('Next screendump for ' .. fname .. ': failed/' .. root_next .. '.dump') | 
					
						
							|  |  |  |       let fail += VerifyScreenDump(buf, root_next, {}) | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |       let nr += 1 | 
					
						
							|  |  |  |     endwhile | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |     " Screendump at the end of the file: failed/root_99.dump | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |     call term_sendkeys(buf, 'Gzb') | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |     let root_last = root .. '_99' | 
					
						
							|  |  |  |     call ch_log('Last screendump for ' .. fname .. ': failed/' .. root_last .. '.dump') | 
					
						
							|  |  |  |     let fail += VerifyScreenDump(buf, root_last, {}) | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     call StopVimInTerminal(buf) | 
					
						
							|  |  |  |     call delete('Xtestscript') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-23 21:36:31 +01:00
										 |  |  |     " redraw here to avoid the following messages to get mixed up with screen | 
					
						
							|  |  |  |     " output. | 
					
						
							|  |  |  |     redraw | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     " Add any assert errors to s:messages. | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |     if len(v:errors) > 0 | 
					
						
							|  |  |  |       call extend(s:messages, v:errors) | 
					
						
							| 
									
										
										
										
											2023-06-23 21:36:31 +01:00
										 |  |  |       " Echo the errors here, in case the script aborts or the "messages" file | 
					
						
							|  |  |  |       " is not displayed later. | 
					
						
							|  |  |  |       echomsg v:errors | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |       let v:errors = [] | 
					
						
							|  |  |  |       let fail += 1 | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |     if fail == 0 | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |       call Message("Test " .. root .. " OK") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       call writefile(['OK'], 'done/' .. root) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       let ok_count += 1 | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |       call Message("Test " .. root .. " FAILED") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       call delete('done/' .. root) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 23:04:11 +01:00
										 |  |  |       eval failed_tests->add(root) | 
					
						
							| 
									
										
										
										
											2023-06-22 22:38:54 +01:00
										 |  |  |       if len(failed_tests) > MAX_FAILED_COUNT | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  | 	call Message('') | 
					
						
							|  |  |  | 	call Message('Too many errors, aborting') | 
					
						
							|  |  |  |       endif | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |     endif | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2023-06-22 22:38:54 +01:00
										 |  |  |     call Message("Test " .. root .. " skipped") | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |     let skipped_count += 1 | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " Append messages to the file "testdir/messages" | 
					
						
							|  |  |  |   call AppendMessages('Input file ' .. fname .. ':') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 22:38:54 +01:00
										 |  |  |   if len(failed_tests) > MAX_FAILED_COUNT | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  |     break | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |   endif | 
					
						
							|  |  |  | endfor | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Matching "if 1" at the start. | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 22:38:54 +01:00
										 |  |  | call Message(s:test_run_message) | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  | call Message('OK: ' .. ok_count) | 
					
						
							| 
									
										
										
										
											2023-06-22 22:38:54 +01:00
										 |  |  | call Message('FAILED: ' .. len(failed_tests) .. ': ' .. string(failed_tests)) | 
					
						
							| 
									
										
										
										
											2023-06-22 21:57:51 +01:00
										 |  |  | call Message('skipped: ' .. skipped_count) | 
					
						
							|  |  |  | call AppendMessages('== SUMMARY ==') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 22:38:54 +01:00
										 |  |  | if len(failed_tests) > 0 | 
					
						
							| 
									
										
										
										
											2023-06-11 19:04:18 +01:00
										 |  |  |   " have make report an error | 
					
						
							|  |  |  |   cquit | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | qall! |