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('$'), '') |
| 43 | call append(line('$'), 'Test run on ' .. strftime("%Y %b %d %H:%M:%S")) |
| 44 | wq |
| 45 | |
| 46 | if syntaxDir !~ '[/\\]runtime[/\\]syntax\>' |
| 47 | call Fatal('Current directory must be "runtime/syntax"') |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 48 | endif |
| 49 | if !isdirectory('testdir') |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 50 | call Fatal('"testdir" directory not found') |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 51 | endif |
| 52 | |
| 53 | " Use the script for source code screendump testing. It sources other scripts, |
| 54 | " therefore we must "cd" there. |
| 55 | cd ../../src/testdir |
| 56 | source screendump.vim |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 57 | exe 'cd ' .. fnameescape(syntaxDir) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 58 | |
| 59 | " For these tests we need to be able to run terminal Vim with 256 colors. On |
| 60 | " MS-Windows the console only has 16 colors and the GUI can't run in a |
| 61 | " terminal. |
| 62 | if !CanRunVimInTerminal() |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 63 | call Fatal('Cannot make screendumps, aborting') |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 64 | endif |
| 65 | |
| 66 | cd testdir |
| 67 | if !isdirectory('done') |
| 68 | call mkdir('done') |
| 69 | endif |
| 70 | |
| 71 | set nocp |
| 72 | set nowrapscan |
| 73 | set report=9999 |
| 74 | set modeline |
| 75 | set debug=throw |
| 76 | set nomore |
| 77 | |
| 78 | au! SwapExists * call HandleSwapExists() |
| 79 | func HandleSwapExists() |
| 80 | " Ignore finding a swap file for the test input, the user might be editing |
| 81 | " it and that's OK. |
| 82 | if expand('<afile>') =~ 'input[/\\].*\..*' |
| 83 | let v:swapchoice = 'e' |
| 84 | endif |
| 85 | endfunc |
| 86 | |
| 87 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 88 | let ok_count = 0 |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 89 | let failed_count = 0 |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 90 | let skipped_count = 0 |
| 91 | let MAX_FAILED_COUNT = 5 |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 92 | for fname in glob('input/*.*', 1, 1) |
| 93 | if fname =~ '\~$' |
| 94 | " backup file, skip |
| 95 | continue |
| 96 | endif |
| 97 | |
| 98 | let linecount = readfile(fname)->len() |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 99 | let root = fnamemodify(fname, ':t:r') |
| 100 | let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '') |
| 101 | let failed_root = 'failed/' .. root |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 102 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 103 | " 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] | 104 | " is newer. |
| 105 | let in_time = getftime(fname) |
| 106 | let out_time = getftime('done/' .. root) |
| 107 | if out_time < 0 || in_time > out_time |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 108 | call ch_log('running tests for: ' .. fname) |
| 109 | |
| 110 | for dumpname in glob(failed_root .. '_\d*\.dump', 1, 1) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 111 | call delete(dumpname) |
| 112 | endfor |
| 113 | call delete('done/' .. root) |
| 114 | |
| 115 | let lines =<< trim END |
| 116 | syntax on |
| 117 | END |
| 118 | call writefile(lines, 'Xtestscript') |
| 119 | let buf = RunVimInTerminal('-S Xtestscript ' .. fname, {}) |
| 120 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 121 | " Screendump at the start of the file: failed/filetype_00.dump |
| 122 | let root_00 = root .. '_00' |
| 123 | call ch_log('First screendump for ' .. fname .. ': failed/' .. root_00 .. '.dump') |
| 124 | let fail = VerifyScreenDump(buf, root_00, {}) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 125 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 126 | " 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] | 127 | let topline = 1 |
| 128 | let nr = 1 |
| 129 | while linecount - topline > 20 |
| 130 | let topline += 18 |
| 131 | call term_sendkeys(buf, printf("%dGzt", topline)) |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 132 | let root_next = root .. printf('_%02d', nr) |
| 133 | call ch_log('Next screendump for ' .. fname .. ': failed/' .. root_next .. '.dump') |
| 134 | let fail += VerifyScreenDump(buf, root_next, {}) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 135 | let nr += 1 |
| 136 | endwhile |
| 137 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 138 | " Screendump at the end of the file: failed/root_99.dump |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 139 | call term_sendkeys(buf, 'Gzb') |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 140 | let root_last = root .. '_99' |
| 141 | call ch_log('Last screendump for ' .. fname .. ': failed/' .. root_last .. '.dump') |
| 142 | let fail += VerifyScreenDump(buf, root_last, {}) |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 143 | |
| 144 | call StopVimInTerminal(buf) |
| 145 | call delete('Xtestscript') |
| 146 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 147 | " Add any assert errors to s:messages |
| 148 | if len(v:errors) > 0 |
| 149 | call extend(s:messages, v:errors) |
| 150 | let v:errors = [] |
| 151 | let fail += 1 |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 152 | endif |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 153 | |
| 154 | if fail == 0 |
| 155 | call Message("Test " .. root .. " OK") |
| 156 | |
| 157 | call writefile(['OK'], 'done/' .. root) |
| 158 | |
| 159 | let ok_count += 1 |
| 160 | else |
| 161 | call Message("Test " .. root .. " FAILED") |
| 162 | |
| 163 | call delete('done/' .. root) |
| 164 | |
| 165 | let failed_count += 1 |
| 166 | if failed_count > MAX_FAILED_COUNT |
| 167 | call Message('') |
| 168 | call Message('Too many errors, aborting') |
| 169 | endif |
| 170 | endif |
| 171 | else |
| 172 | let skipped_count += 1 |
| 173 | endif |
| 174 | |
| 175 | " Append messages to the file "testdir/messages" |
| 176 | call AppendMessages('Input file ' .. fname .. ':') |
| 177 | |
| 178 | if failed_count > MAX_FAILED_COUNT |
| 179 | break |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 180 | endif |
| 181 | endfor |
| 182 | |
| 183 | " Matching "if 1" at the start. |
| 184 | endif |
| 185 | |
Bram Moolenaar | 1aa5f1c | 2023-06-22 21:57:51 +0100 | [diff] [blame^] | 186 | call Message('OK: ' .. ok_count) |
| 187 | call Message('FAILED: ' .. failed_count) |
| 188 | call Message('skipped: ' .. skipped_count) |
| 189 | call AppendMessages('== SUMMARY ==') |
| 190 | |
Bram Moolenaar | 46acad7 | 2023-06-11 19:04:18 +0100 | [diff] [blame] | 191 | if failed_count > 0 |
| 192 | " have make report an error |
| 193 | cquit |
| 194 | endif |
| 195 | qall! |