blob: 21e1ae352ad14012ef902de569787ce36f76fb2e [file] [log] [blame]
Bram Moolenaar46acad72023-06-11 19:04:18 +01001" 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
6if 1
7
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +01008" Remember the directory where we started. Will change to "testdir" below.
9let syntaxDir = getcwd()
10
11let s:messagesFname = fnameescape(syntaxDir .. '/testdir/messages')
12
13let s:messages = []
14
15" Add one message to the list of messages
16func Message(msg)
17 echomsg a:msg
18 call add(s:messages, a:msg)
19endfunc
20
21" Report a fatal message and exit
22func Fatal(msg)
23 echoerr a:msg
24 call AppendMessages(a:msg)
25 qall!
26endfunc
27
28" Append s:messages to the messages file and make it empty.
29func 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
36endfunc
37
38" Relevant messages are written to the "messages" file.
39" If the file already exists it is appended to.
40exe 'split ' .. s:messagesFname
41call append(line('$'), repeat('=-', 70))
42call append(line('$'), '')
43call append(line('$'), 'Test run on ' .. strftime("%Y %b %d %H:%M:%S"))
44wq
45
46if syntaxDir !~ '[/\\]runtime[/\\]syntax\>'
47 call Fatal('Current directory must be "runtime/syntax"')
Bram Moolenaar46acad72023-06-11 19:04:18 +010048endif
49if !isdirectory('testdir')
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010050 call Fatal('"testdir" directory not found')
Bram Moolenaar46acad72023-06-11 19:04:18 +010051endif
52
53" Use the script for source code screendump testing. It sources other scripts,
54" therefore we must "cd" there.
55cd ../../src/testdir
56source screendump.vim
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010057exe 'cd ' .. fnameescape(syntaxDir)
Bram Moolenaar46acad72023-06-11 19:04:18 +010058
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.
62if !CanRunVimInTerminal()
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010063 call Fatal('Cannot make screendumps, aborting')
Bram Moolenaar46acad72023-06-11 19:04:18 +010064endif
65
66cd testdir
67if !isdirectory('done')
68 call mkdir('done')
69endif
70
71set nocp
72set nowrapscan
73set report=9999
74set modeline
75set debug=throw
76set nomore
77
78au! SwapExists * call HandleSwapExists()
79func 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
85endfunc
86
87
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010088let ok_count = 0
Bram Moolenaar46acad72023-06-11 19:04:18 +010089let failed_count = 0
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010090let skipped_count = 0
91let MAX_FAILED_COUNT = 5
Bram Moolenaar46acad72023-06-11 19:04:18 +010092for 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 Moolenaar1aa5f1c2023-06-22 21:57:51 +010099 let root = fnamemodify(fname, ':t:r')
100 let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '')
101 let failed_root = 'failed/' .. root
Bram Moolenaar46acad72023-06-11 19:04:18 +0100102
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100103 " Execute the test if the "done" file does not exist or when the input file
Bram Moolenaar46acad72023-06-11 19:04:18 +0100104 " 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 Moolenaar1aa5f1c2023-06-22 21:57:51 +0100108 call ch_log('running tests for: ' .. fname)
109
110 for dumpname in glob(failed_root .. '_\d*\.dump', 1, 1)
Bram Moolenaar46acad72023-06-11 19:04:18 +0100111 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 Moolenaar1aa5f1c2023-06-22 21:57:51 +0100121 " 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 Moolenaar46acad72023-06-11 19:04:18 +0100125
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100126 " Make a Screendump every 18 lines of the file: failed/root_NN.dump
Bram Moolenaar46acad72023-06-11 19:04:18 +0100127 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 Moolenaar1aa5f1c2023-06-22 21:57:51 +0100132 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 Moolenaar46acad72023-06-11 19:04:18 +0100135 let nr += 1
136 endwhile
137
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100138 " Screendump at the end of the file: failed/root_99.dump
Bram Moolenaar46acad72023-06-11 19:04:18 +0100139 call term_sendkeys(buf, 'Gzb')
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100140 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 Moolenaar46acad72023-06-11 19:04:18 +0100143
144 call StopVimInTerminal(buf)
145 call delete('Xtestscript')
146
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100147 " 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 Moolenaar46acad72023-06-11 19:04:18 +0100152 endif
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100153
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 Moolenaar46acad72023-06-11 19:04:18 +0100180 endif
181endfor
182
183" Matching "if 1" at the start.
184endif
185
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100186call Message('OK: ' .. ok_count)
187call Message('FAILED: ' .. failed_count)
188call Message('skipped: ' .. skipped_count)
189call AppendMessages('== SUMMARY ==')
190
Bram Moolenaar46acad72023-06-11 19:04:18 +0100191if failed_count > 0
192 " have make report an error
193 cquit
194endif
195qall!