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 | |
| 8 | let cwd = getcwd() |
| 9 | if cwd !~ '[/\\]runtime[/\\]syntax\>' |
| 10 | echoerr 'Current directory must be "runtime/syntax"' |
| 11 | qall |
| 12 | endif |
| 13 | if !isdirectory('testdir') |
| 14 | echoerr '"testdir" directory not found' |
| 15 | qall |
| 16 | endif |
| 17 | |
| 18 | " Use the script for source code screendump testing. It sources other scripts, |
| 19 | " therefore we must "cd" there. |
| 20 | cd ../../src/testdir |
| 21 | source screendump.vim |
| 22 | exe 'cd ' .. fnameescape(cwd) |
| 23 | |
| 24 | " For these tests we need to be able to run terminal Vim with 256 colors. On |
| 25 | " MS-Windows the console only has 16 colors and the GUI can't run in a |
| 26 | " terminal. |
| 27 | if !CanRunVimInTerminal() |
| 28 | echomsg 'Cannot make screendumps, aborting' |
| 29 | qall |
| 30 | endif |
| 31 | |
| 32 | cd testdir |
| 33 | if !isdirectory('done') |
| 34 | call mkdir('done') |
| 35 | endif |
| 36 | |
| 37 | set nocp |
| 38 | set nowrapscan |
| 39 | set report=9999 |
| 40 | set modeline |
| 41 | set debug=throw |
| 42 | set nomore |
| 43 | |
| 44 | au! SwapExists * call HandleSwapExists() |
| 45 | func HandleSwapExists() |
| 46 | " Ignore finding a swap file for the test input, the user might be editing |
| 47 | " it and that's OK. |
| 48 | if expand('<afile>') =~ 'input[/\\].*\..*' |
| 49 | let v:swapchoice = 'e' |
| 50 | endif |
| 51 | endfunc |
| 52 | |
| 53 | |
| 54 | let failed_count = 0 |
| 55 | for fname in glob('input/*.*', 1, 1) |
| 56 | if fname =~ '\~$' |
| 57 | " backup file, skip |
| 58 | continue |
| 59 | endif |
| 60 | |
| 61 | let linecount = readfile(fname)->len() |
| 62 | let root = substitute(fname, 'input[/\\]\(.*\)\..*', '\1', '') |
| 63 | |
| 64 | " Execute the test if the "done" file does not exist of when the input file |
| 65 | " is newer. |
| 66 | let in_time = getftime(fname) |
| 67 | let out_time = getftime('done/' .. root) |
| 68 | if out_time < 0 || in_time > out_time |
| 69 | for dumpname in glob('failed/' .. root .. '_\d*\.dump', 1, 1) |
| 70 | call delete(dumpname) |
| 71 | endfor |
| 72 | call delete('done/' .. root) |
| 73 | |
| 74 | let lines =<< trim END |
| 75 | syntax on |
| 76 | END |
| 77 | call writefile(lines, 'Xtestscript') |
| 78 | let buf = RunVimInTerminal('-S Xtestscript ' .. fname, {}) |
| 79 | |
| 80 | " Screendump at the start of the file: root_00.dump |
| 81 | let fail = VerifyScreenDump(buf, root .. '_00', {}) |
| 82 | |
| 83 | " Make a Screendump every 18 lines of the file: root_NN.dump |
| 84 | let topline = 1 |
| 85 | let nr = 1 |
| 86 | while linecount - topline > 20 |
| 87 | let topline += 18 |
| 88 | call term_sendkeys(buf, printf("%dGzt", topline)) |
| 89 | let fail += VerifyScreenDump(buf, root .. printf('_%02d', nr), {}) |
| 90 | let nr += 1 |
| 91 | endwhile |
| 92 | |
| 93 | " Screendump at the end of the file: root_99.dump |
| 94 | call term_sendkeys(buf, 'Gzb') |
| 95 | let fail += VerifyScreenDump(buf, root .. '_99', {}) |
| 96 | |
| 97 | call StopVimInTerminal(buf) |
| 98 | call delete('Xtestscript') |
| 99 | |
| 100 | if fail == 0 |
| 101 | call writefile(['OK'], 'done/' . root) |
| 102 | echo "Test " . root . " OK\n" |
| 103 | else |
| 104 | let failed_count += 1 |
| 105 | endif |
| 106 | endif |
| 107 | endfor |
| 108 | |
| 109 | " Matching "if 1" at the start. |
| 110 | endif |
| 111 | |
| 112 | if failed_count > 0 |
| 113 | " have make report an error |
| 114 | cquit |
| 115 | endif |
| 116 | qall! |