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 | |
| 5 | " Only do this with the +eval feature |
| 6 | if 1 |
| 7 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 8 | " Remember the directory where we started. Will change to "testdir" below. |
| 9 | let syntaxDir = getcwd() |
| 10 | |
| 11 | let s:messagesFname = fnameescape(syntaxDir .. '/testdir/messages') |
| 12 | |
| 13 | let s:messages = [] |
| 14 | |
| 15 | " Add one message to the list of messages |
| 16 | func Message(msg) |
| 17 | echomsg a:msg |
| 18 | call add(s:messages, a:msg) |
| 19 | endfunc |
| 20 | |
| 21 | " Report a fatal message and exit |
| 22 | func Fatal(msg) |
| 23 | echoerr a:msg |
| 24 | call AppendMessages(a:msg) |
| 25 | qall! |
| 26 | endfunc |
| 27 | |
| 28 | " Append s:messages to the messages file and make it empty. |
| 29 | func AppendMessages(header) |
| 30 | exe 'split ' .. s:messagesFname |
| 31 | call append(line('$'), '') |
| 32 | call append(line('$'), a:header) |
| 33 | call append(line('$'), s:messages) |
| 34 | let s:messages = [] |
| 35 | wq |
| 36 | endfunc |
| 37 | |
| 38 | " Relevant messages are written to the "messages" file. |
| 39 | " If the file already exists it is appended to. |
| 40 | exe 'split ' .. s:messagesFname |
| 41 | call append(line('$'), repeat('=-', 70)) |
| 42 | call append(line('$'), '') |
Bram Moolenaar | 031d632 | 2023-06-22 22:38:54 +0100 | [diff] [blame] | 43 | let s:test_run_message = 'Test run on ' .. strftime("%Y %b %d %H:%M:%S") |
| 44 | call append(line('$'), s:test_run_message) |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 45 | wq |
| 46 | |
| 47 | if syntaxDir !~ '[/\\]runtime[/\\]syntax\>' |
| 48 | call Fatal('Current directory must be "runtime/syntax"') |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 49 | endif |
| 50 | if !isdirectory('testdir') |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 51 | call Fatal('"testdir" directory not found') |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 52 | endif |
| 53 | |
| 54 | " Use the script for source code screendump testing. It sources other scripts, |
| 55 | " therefore we must "cd" there. |
| 56 | cd ../../src/testdir |
| 57 | source screendump.vim |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 58 | exe 'cd ' .. fnameescape(syntaxDir) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 59 | |
| 60 | " For these tests we need to be able to run terminal Vim with 256 colors. On |
| 61 | " MS-Windows the console only has 16 colors and the GUI can't run in a |
| 62 | " terminal. |
| 63 | if !CanRunVimInTerminal() |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 64 | call Fatal('Cannot make screendumps, aborting') |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 65 | endif |
| 66 | |
| 67 | cd testdir |
| 68 | if !isdirectory('done') |
| 69 | call mkdir('done') |
| 70 | endif |
| 71 | |
| 72 | set nocp |
| 73 | set nowrapscan |
| 74 | set report=9999 |
| 75 | set modeline |
| 76 | set debug=throw |
| 77 | set nomore |
| 78 | |
| 79 | au! SwapExists * call HandleSwapExists() |
| 80 | func HandleSwapExists() |
| 81 | " Ignore finding a swap file for the test input, the user might be editing |
| 82 | " it and that's OK. |
| 83 | if expand('<afile>') =~ 'input[/\\].*\..*' |
| 84 | let v:swapchoice = 'e' |
| 85 | endif |
| 86 | endfunc |
| 87 | |
| 88 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 89 | let ok_count = 0 |
Bram Moolenaar | 031d632 | 2023-06-22 22:38:54 +0100 | [diff] [blame] | 90 | let failed_tests = [] |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 91 | let skipped_count = 0 |
| 92 | let MAX_FAILED_COUNT = 5 |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 93 | for fname in glob('input/*.*', 1, 1) |
| 94 | if fname =~ '\~$' |
| 95 | " backup file, skip |
| 96 | continue |
| 97 | endif |
| 98 | |
| 99 | let linecount = readfile(fname)->len() |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 100 | let root = fnamemodify(fname, ':t:r') |
| 101 | let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '') |
| 102 | let failed_root = 'failed/' .. root |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 103 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 104 | " Execute the test if the "done" file does not exist or when the input file |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 105 | " is newer. |
| 106 | let in_time = getftime(fname) |
| 107 | let out_time = getftime('done/' .. root) |
| 108 | if out_time < 0 || in_time > out_time |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 109 | call ch_log('running tests for: ' .. fname) |
| 110 | |
| 111 | for dumpname in glob(failed_root .. '_\d*\.dump', 1, 1) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 112 | call delete(dumpname) |
| 113 | endfor |
| 114 | call delete('done/' .. root) |
| 115 | |
| 116 | let lines =<< trim END |
| 117 | syntax on |
| 118 | END |
| 119 | call writefile(lines, 'Xtestscript') |
Bram Moolenaar | 2f43ec9 | 2023-06-23 22:59:26 +0100 | [diff] [blame^] | 120 | |
| 121 | " close all but the last window |
| 122 | while winnr('$') > 1 |
| 123 | close |
| 124 | endwhile |
| 125 | |
| 126 | " Redraw to make sure that messages are cleared and there is enough space |
| 127 | " for the terminal window. |
| 128 | redraw |
| 129 | |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 130 | let buf = RunVimInTerminal('-S Xtestscript ' .. fname, {}) |
| 131 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 132 | " Screendump at the start of the file: failed/filetype_00.dump |
| 133 | let root_00 = root .. '_00' |
| 134 | call ch_log('First screendump for ' .. fname .. ': failed/' .. root_00 .. '.dump') |
| 135 | let fail = VerifyScreenDump(buf, root_00, {}) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 136 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 137 | " Make a Screendump every 18 lines of the file: failed/root_NN.dump |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 138 | let topline = 1 |
| 139 | let nr = 1 |
| 140 | while linecount - topline > 20 |
| 141 | let topline += 18 |
| 142 | call term_sendkeys(buf, printf("%dGzt", topline)) |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 143 | let root_next = root .. printf('_%02d', nr) |
| 144 | call ch_log('Next screendump for ' .. fname .. ': failed/' .. root_next .. '.dump') |
| 145 | let fail += VerifyScreenDump(buf, root_next, {}) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 146 | let nr += 1 |
| 147 | endwhile |
| 148 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 149 | " Screendump at the end of the file: failed/root_99.dump |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 150 | call term_sendkeys(buf, 'Gzb') |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 151 | let root_last = root .. '_99' |
| 152 | call ch_log('Last screendump for ' .. fname .. ': failed/' .. root_last .. '.dump') |
| 153 | let fail += VerifyScreenDump(buf, root_last, {}) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 154 | |
| 155 | call StopVimInTerminal(buf) |
| 156 | call delete('Xtestscript') |
| 157 | |
Bram Moolenaar | bd32e8a | 2023-06-23 21:36:31 +0100 | [diff] [blame] | 158 | " redraw here to avoid the following messages to get mixed up with screen |
| 159 | " output. |
| 160 | redraw |
| 161 | |
| 162 | " Add any assert errors to s:messages. |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 163 | if len(v:errors) > 0 |
| 164 | call extend(s:messages, v:errors) |
Bram Moolenaar | bd32e8a | 2023-06-23 21:36:31 +0100 | [diff] [blame] | 165 | " Echo the errors here, in case the script aborts or the "messages" file |
| 166 | " is not displayed later. |
| 167 | echomsg v:errors |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 168 | let v:errors = [] |
| 169 | let fail += 1 |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 170 | endif |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 171 | |
| 172 | if fail == 0 |
| 173 | call Message("Test " .. root .. " OK") |
| 174 | |
| 175 | call writefile(['OK'], 'done/' .. root) |
| 176 | |
| 177 | let ok_count += 1 |
| 178 | else |
| 179 | call Message("Test " .. root .. " FAILED") |
| 180 | |
| 181 | call delete('done/' .. root) |
| 182 | |
Bram Moolenaar | c6530c9 | 2023-06-22 23:04:11 +0100 | [diff] [blame] | 183 | eval failed_tests->add(root) |
Bram Moolenaar | 031d632 | 2023-06-22 22:38:54 +0100 | [diff] [blame] | 184 | if len(failed_tests) > MAX_FAILED_COUNT |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 185 | call Message('') |
| 186 | call Message('Too many errors, aborting') |
| 187 | endif |
| 188 | endif |
| 189 | else |
Bram Moolenaar | 031d632 | 2023-06-22 22:38:54 +0100 | [diff] [blame] | 190 | call Message("Test " .. root .. " skipped") |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 191 | let skipped_count += 1 |
| 192 | endif |
| 193 | |
| 194 | " Append messages to the file "testdir/messages" |
| 195 | call AppendMessages('Input file ' .. fname .. ':') |
| 196 | |
Bram Moolenaar | 031d632 | 2023-06-22 22:38:54 +0100 | [diff] [blame] | 197 | if len(failed_tests) > MAX_FAILED_COUNT |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 198 | break |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 199 | endif |
| 200 | endfor |
| 201 | |
| 202 | " Matching "if 1" at the start. |
| 203 | endif |
| 204 | |
Bram Moolenaar | 031d632 | 2023-06-22 22:38:54 +0100 | [diff] [blame] | 205 | call Message(s:test_run_message) |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 206 | call Message('OK: ' .. ok_count) |
Bram Moolenaar | 031d632 | 2023-06-22 22:38:54 +0100 | [diff] [blame] | 207 | call Message('FAILED: ' .. len(failed_tests) .. ': ' .. string(failed_tests)) |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame] | 208 | call Message('skipped: ' .. skipped_count) |
| 209 | call AppendMessages('== SUMMARY ==') |
| 210 | |
Bram Moolenaar | 031d632 | 2023-06-22 22:38:54 +0100 | [diff] [blame] | 211 | if len(failed_tests) > 0 |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 212 | " have make report an error |
| 213 | cquit |
| 214 | endif |
| 215 | qall! |