blob: 80f1eff58a9184378ec7f925860dc6c0956305a5 [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('$'), '')
Bram Moolenaar031d6322023-06-22 22:38:54 +010043let s:test_run_message = 'Test run on ' .. strftime("%Y %b %d %H:%M:%S")
44call append(line('$'), s:test_run_message)
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010045wq
46
47if syntaxDir !~ '[/\\]runtime[/\\]syntax\>'
48 call Fatal('Current directory must be "runtime/syntax"')
Bram Moolenaar46acad72023-06-11 19:04:18 +010049endif
50if !isdirectory('testdir')
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010051 call Fatal('"testdir" directory not found')
Bram Moolenaar46acad72023-06-11 19:04:18 +010052endif
53
54" Use the script for source code screendump testing. It sources other scripts,
55" therefore we must "cd" there.
56cd ../../src/testdir
57source screendump.vim
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010058exe 'cd ' .. fnameescape(syntaxDir)
Bram Moolenaar46acad72023-06-11 19:04:18 +010059
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.
63if !CanRunVimInTerminal()
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010064 call Fatal('Cannot make screendumps, aborting')
Bram Moolenaar46acad72023-06-11 19:04:18 +010065endif
66
67cd testdir
68if !isdirectory('done')
69 call mkdir('done')
70endif
71
72set nocp
73set nowrapscan
74set report=9999
75set modeline
76set debug=throw
77set nomore
78
79au! SwapExists * call HandleSwapExists()
80func 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
86endfunc
87
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010088let ok_count = 0
Bram Moolenaar031d6322023-06-22 22:38:54 +010089let failed_tests = []
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
Bram Moolenaar7d0dbd02023-06-24 00:56:50 +0100117
118 " extra info for shell variables
119 func ShellInfo()
120 let msg = ''
121 for [key, val] in items(b:)
122 if key =~ '^is_'
123 let msg ..= key .. ': ' .. val .. ', '
124 endif
125 endfor
126 if msg != ''
127 echomsg msg
128 endif
129 endfunc
130
131 au! SwapExists * call HandleSwapExists()
132 func HandleSwapExists()
133 " Ignore finding a swap file for the test input, the user might be
134 " editing it and that's OK.
135 if expand('<afile>') =~ 'input[/\\].*\..*'
136 let v:swapchoice = 'e'
137 endif
138 endfunc
Bram Moolenaar46acad72023-06-11 19:04:18 +0100139 END
140 call writefile(lines, 'Xtestscript')
Bram Moolenaar2f43ec92023-06-23 22:59:26 +0100141
142 " close all but the last window
143 while winnr('$') > 1
144 close
145 endwhile
146
147 " Redraw to make sure that messages are cleared and there is enough space
148 " for the terminal window.
149 redraw
150
Bram Moolenaar7d0dbd02023-06-24 00:56:50 +0100151 let buf = RunVimInTerminal('-S Xtestscript', {})
152 " edit the file only after catching the SwapExists event
153 call term_sendkeys(buf, ":edit " .. fname .. "\<CR>")
Bram Moolenaar46acad72023-06-11 19:04:18 +0100154
Bram Moolenaar7d0dbd02023-06-24 00:56:50 +0100155 if filetype == 'sh'
156 call term_sendkeys(buf, ":call ShellInfo()\<CR>")
157 endif
158
159 " Screendump at the start of the file: failed/root_00.dump
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100160 let root_00 = root .. '_00'
161 call ch_log('First screendump for ' .. fname .. ': failed/' .. root_00 .. '.dump')
162 let fail = VerifyScreenDump(buf, root_00, {})
Bram Moolenaar46acad72023-06-11 19:04:18 +0100163
Bram Moolenaar7d0dbd02023-06-24 00:56:50 +0100164 " clear the shell info if there are not enough lines to cause a scroll
165 if filetype == 'sh' && linecount <= 19
166 call term_sendkeys(buf, ":redraw\<CR>")
167 endif
168
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100169 " Make a Screendump every 18 lines of the file: failed/root_NN.dump
Bram Moolenaar46acad72023-06-11 19:04:18 +0100170 let topline = 1
171 let nr = 1
172 while linecount - topline > 20
173 let topline += 18
174 call term_sendkeys(buf, printf("%dGzt", topline))
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100175 let root_next = root .. printf('_%02d', nr)
176 call ch_log('Next screendump for ' .. fname .. ': failed/' .. root_next .. '.dump')
177 let fail += VerifyScreenDump(buf, root_next, {})
Bram Moolenaar46acad72023-06-11 19:04:18 +0100178 let nr += 1
179 endwhile
180
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100181 " Screendump at the end of the file: failed/root_99.dump
Bram Moolenaar46acad72023-06-11 19:04:18 +0100182 call term_sendkeys(buf, 'Gzb')
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100183 let root_last = root .. '_99'
184 call ch_log('Last screendump for ' .. fname .. ': failed/' .. root_last .. '.dump')
185 let fail += VerifyScreenDump(buf, root_last, {})
Bram Moolenaar46acad72023-06-11 19:04:18 +0100186
187 call StopVimInTerminal(buf)
188 call delete('Xtestscript')
189
Bram Moolenaarbd32e8a2023-06-23 21:36:31 +0100190 " redraw here to avoid the following messages to get mixed up with screen
191 " output.
192 redraw
193
194 " Add any assert errors to s:messages.
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100195 if len(v:errors) > 0
196 call extend(s:messages, v:errors)
Bram Moolenaarbd32e8a2023-06-23 21:36:31 +0100197 " Echo the errors here, in case the script aborts or the "messages" file
198 " is not displayed later.
199 echomsg v:errors
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100200 let v:errors = []
201 let fail += 1
Bram Moolenaar46acad72023-06-11 19:04:18 +0100202 endif
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100203
204 if fail == 0
205 call Message("Test " .. root .. " OK")
206
207 call writefile(['OK'], 'done/' .. root)
208
209 let ok_count += 1
210 else
211 call Message("Test " .. root .. " FAILED")
212
213 call delete('done/' .. root)
214
Bram Moolenaarc6530c92023-06-22 23:04:11 +0100215 eval failed_tests->add(root)
Bram Moolenaar031d6322023-06-22 22:38:54 +0100216 if len(failed_tests) > MAX_FAILED_COUNT
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100217 call Message('')
218 call Message('Too many errors, aborting')
219 endif
220 endif
221 else
Bram Moolenaar031d6322023-06-22 22:38:54 +0100222 call Message("Test " .. root .. " skipped")
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100223 let skipped_count += 1
224 endif
225
226 " Append messages to the file "testdir/messages"
227 call AppendMessages('Input file ' .. fname .. ':')
228
Bram Moolenaar031d6322023-06-22 22:38:54 +0100229 if len(failed_tests) > MAX_FAILED_COUNT
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100230 break
Bram Moolenaar46acad72023-06-11 19:04:18 +0100231 endif
232endfor
233
Bram Moolenaar031d6322023-06-22 22:38:54 +0100234call Message(s:test_run_message)
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100235call Message('OK: ' .. ok_count)
Bram Moolenaar031d6322023-06-22 22:38:54 +0100236call Message('FAILED: ' .. len(failed_tests) .. ': ' .. string(failed_tests))
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100237call Message('skipped: ' .. skipped_count)
238call AppendMessages('== SUMMARY ==')
239
Dominique Pellé99c38492023-09-24 16:09:31 +0200240" Matching "if 1" at the start.
241endif
242
Bram Moolenaar031d6322023-06-22 22:38:54 +0100243if len(failed_tests) > 0
Bram Moolenaar46acad72023-06-11 19:04:18 +0100244 " have make report an error
245 cquit
246endif
247qall!