comparison runtime/syntax/testdir/runtest.vim @ 32631:f8a2fc7d823f v9.0.1647

patch 9.0.1647: insufficient testing for syntax plugins Commit: https://github.com/vim/vim/commit/1aa5f1c21fea60fe64cdcdf6990bf43ea5cc78a0 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 22 21:57:51 2023 +0100 patch 9.0.1647: insufficient testing for syntax plugins Problem: Insufficient testing for syntax plugins. Solution: Add shell file examples. (Charles Campbell) Create a messages file for easier debugging and reporting the test results.
author Bram Moolenaar <Bram@vim.org>
date Thu, 22 Jun 2023 23:00:05 +0200
parents 92b93fe443e9
children a8577b9dab80
comparison
equal deleted inserted replaced
32630:7477909c676f 32631:f8a2fc7d823f
3 " Current directory must be runtime/syntax. 3 " Current directory must be runtime/syntax.
4 4
5 " Only do this with the +eval feature 5 " Only do this with the +eval feature
6 if 1 6 if 1
7 7
8 let cwd = getcwd() 8 " Remember the directory where we started. Will change to "testdir" below.
9 if cwd !~ '[/\\]runtime[/\\]syntax\>' 9 let syntaxDir = getcwd()
10 echoerr 'Current directory must be "runtime/syntax"' 10
11 qall 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"')
12 endif 48 endif
13 if !isdirectory('testdir') 49 if !isdirectory('testdir')
14 echoerr '"testdir" directory not found' 50 call Fatal('"testdir" directory not found')
15 qall
16 endif 51 endif
17 52
18 " Use the script for source code screendump testing. It sources other scripts, 53 " Use the script for source code screendump testing. It sources other scripts,
19 " therefore we must "cd" there. 54 " therefore we must "cd" there.
20 cd ../../src/testdir 55 cd ../../src/testdir
21 source screendump.vim 56 source screendump.vim
22 exe 'cd ' .. fnameescape(cwd) 57 exe 'cd ' .. fnameescape(syntaxDir)
23 58
24 " For these tests we need to be able to run terminal Vim with 256 colors. On 59 " 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 60 " MS-Windows the console only has 16 colors and the GUI can't run in a
26 " terminal. 61 " terminal.
27 if !CanRunVimInTerminal() 62 if !CanRunVimInTerminal()
28 echomsg 'Cannot make screendumps, aborting' 63 call Fatal('Cannot make screendumps, aborting')
29 qall
30 endif 64 endif
31 65
32 cd testdir 66 cd testdir
33 if !isdirectory('done') 67 if !isdirectory('done')
34 call mkdir('done') 68 call mkdir('done')
49 let v:swapchoice = 'e' 83 let v:swapchoice = 'e'
50 endif 84 endif
51 endfunc 85 endfunc
52 86
53 87
88 let ok_count = 0
54 let failed_count = 0 89 let failed_count = 0
90 let skipped_count = 0
91 let MAX_FAILED_COUNT = 5
55 for fname in glob('input/*.*', 1, 1) 92 for fname in glob('input/*.*', 1, 1)
56 if fname =~ '\~$' 93 if fname =~ '\~$'
57 " backup file, skip 94 " backup file, skip
58 continue 95 continue
59 endif 96 endif
60 97
61 let linecount = readfile(fname)->len() 98 let linecount = readfile(fname)->len()
62 let root = substitute(fname, 'input[/\\]\(.*\)\..*', '\1', '') 99 let root = fnamemodify(fname, ':t:r')
100 let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '')
101 let failed_root = 'failed/' .. root
63 102
64 " Execute the test if the "done" file does not exist of when the input file 103 " Execute the test if the "done" file does not exist or when the input file
65 " is newer. 104 " is newer.
66 let in_time = getftime(fname) 105 let in_time = getftime(fname)
67 let out_time = getftime('done/' .. root) 106 let out_time = getftime('done/' .. root)
68 if out_time < 0 || in_time > out_time 107 if out_time < 0 || in_time > out_time
69 for dumpname in glob('failed/' .. root .. '_\d*\.dump', 1, 1) 108 call ch_log('running tests for: ' .. fname)
109
110 for dumpname in glob(failed_root .. '_\d*\.dump', 1, 1)
70 call delete(dumpname) 111 call delete(dumpname)
71 endfor 112 endfor
72 call delete('done/' .. root) 113 call delete('done/' .. root)
73 114
74 let lines =<< trim END 115 let lines =<< trim END
75 syntax on 116 syntax on
76 END 117 END
77 call writefile(lines, 'Xtestscript') 118 call writefile(lines, 'Xtestscript')
78 let buf = RunVimInTerminal('-S Xtestscript ' .. fname, {}) 119 let buf = RunVimInTerminal('-S Xtestscript ' .. fname, {})
79 120
80 " Screendump at the start of the file: root_00.dump 121 " Screendump at the start of the file: failed/filetype_00.dump
81 let fail = VerifyScreenDump(buf, root .. '_00', {}) 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, {})
82 125
83 " Make a Screendump every 18 lines of the file: root_NN.dump 126 " Make a Screendump every 18 lines of the file: failed/root_NN.dump
84 let topline = 1 127 let topline = 1
85 let nr = 1 128 let nr = 1
86 while linecount - topline > 20 129 while linecount - topline > 20
87 let topline += 18 130 let topline += 18
88 call term_sendkeys(buf, printf("%dGzt", topline)) 131 call term_sendkeys(buf, printf("%dGzt", topline))
89 let fail += VerifyScreenDump(buf, root .. printf('_%02d', nr), {}) 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, {})
90 let nr += 1 135 let nr += 1
91 endwhile 136 endwhile
92 137
93 " Screendump at the end of the file: root_99.dump 138 " Screendump at the end of the file: failed/root_99.dump
94 call term_sendkeys(buf, 'Gzb') 139 call term_sendkeys(buf, 'Gzb')
95 let fail += VerifyScreenDump(buf, root .. '_99', {}) 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, {})
96 143
97 call StopVimInTerminal(buf) 144 call StopVimInTerminal(buf)
98 call delete('Xtestscript') 145 call delete('Xtestscript')
99 146
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
152 endif
153
100 if fail == 0 154 if fail == 0
101 call writefile(['OK'], 'done/' . root) 155 call Message("Test " .. root .. " OK")
102 echo "Test " . root . " OK\n" 156
157 call writefile(['OK'], 'done/' .. root)
158
159 let ok_count += 1
103 else 160 else
161 call Message("Test " .. root .. " FAILED")
162
163 call delete('done/' .. root)
164
104 let failed_count += 1 165 let failed_count += 1
166 if failed_count > MAX_FAILED_COUNT
167 call Message('')
168 call Message('Too many errors, aborting')
169 endif
105 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
106 endif 180 endif
107 endfor 181 endfor
108 182
109 " Matching "if 1" at the start. 183 " Matching "if 1" at the start.
110 endif 184 endif
111 185
186 call Message('OK: ' .. ok_count)
187 call Message('FAILED: ' .. failed_count)
188 call Message('skipped: ' .. skipped_count)
189 call AppendMessages('== SUMMARY ==')
190
112 if failed_count > 0 191 if failed_count > 0
113 " have make report an error 192 " have make report an error
114 cquit 193 cquit
115 endif 194 endif
116 qall! 195 qall!