blob: 5878b5ec366081ad4ac4ab37b8be806ba3e0f4d5 [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
88
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010089let ok_count = 0
Bram Moolenaar031d6322023-06-22 22:38:54 +010090let failed_tests = []
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +010091let skipped_count = 0
92let MAX_FAILED_COUNT = 5
Bram Moolenaar46acad72023-06-11 19:04:18 +010093for fname in glob('input/*.*', 1, 1)
94 if fname =~ '\~$'
95 " backup file, skip
96 continue
97 endif
98
99 let linecount = readfile(fname)->len()
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100100 let root = fnamemodify(fname, ':t:r')
101 let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '')
102 let failed_root = 'failed/' .. root
Bram Moolenaar46acad72023-06-11 19:04:18 +0100103
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100104 " Execute the test if the "done" file does not exist or when the input file
Bram Moolenaar46acad72023-06-11 19:04:18 +0100105 " is newer.
106 let in_time = getftime(fname)
107 let out_time = getftime('done/' .. root)
108 if out_time < 0 || in_time > out_time
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100109 call ch_log('running tests for: ' .. fname)
110
111 for dumpname in glob(failed_root .. '_\d*\.dump', 1, 1)
Bram Moolenaar46acad72023-06-11 19:04:18 +0100112 call delete(dumpname)
113 endfor
114 call delete('done/' .. root)
115
116 let lines =<< trim END
117 syntax on
118 END
119 call writefile(lines, 'Xtestscript')
120 let buf = RunVimInTerminal('-S Xtestscript ' .. fname, {})
121
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100122 " Screendump at the start of the file: failed/filetype_00.dump
123 let root_00 = root .. '_00'
124 call ch_log('First screendump for ' .. fname .. ': failed/' .. root_00 .. '.dump')
125 let fail = VerifyScreenDump(buf, root_00, {})
Bram Moolenaar46acad72023-06-11 19:04:18 +0100126
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100127 " Make a Screendump every 18 lines of the file: failed/root_NN.dump
Bram Moolenaar46acad72023-06-11 19:04:18 +0100128 let topline = 1
129 let nr = 1
130 while linecount - topline > 20
131 let topline += 18
132 call term_sendkeys(buf, printf("%dGzt", topline))
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100133 let root_next = root .. printf('_%02d', nr)
134 call ch_log('Next screendump for ' .. fname .. ': failed/' .. root_next .. '.dump')
135 let fail += VerifyScreenDump(buf, root_next, {})
Bram Moolenaar46acad72023-06-11 19:04:18 +0100136 let nr += 1
137 endwhile
138
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100139 " Screendump at the end of the file: failed/root_99.dump
Bram Moolenaar46acad72023-06-11 19:04:18 +0100140 call term_sendkeys(buf, 'Gzb')
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100141 let root_last = root .. '_99'
142 call ch_log('Last screendump for ' .. fname .. ': failed/' .. root_last .. '.dump')
143 let fail += VerifyScreenDump(buf, root_last, {})
Bram Moolenaar46acad72023-06-11 19:04:18 +0100144
145 call StopVimInTerminal(buf)
146 call delete('Xtestscript')
147
Bram Moolenaarbd32e8a2023-06-23 21:36:31 +0100148 " redraw here to avoid the following messages to get mixed up with screen
149 " output.
150 redraw
151
152 " Add any assert errors to s:messages.
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100153 if len(v:errors) > 0
154 call extend(s:messages, v:errors)
Bram Moolenaarbd32e8a2023-06-23 21:36:31 +0100155 " Echo the errors here, in case the script aborts or the "messages" file
156 " is not displayed later.
157 echomsg v:errors
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100158 let v:errors = []
159 let fail += 1
Bram Moolenaar46acad72023-06-11 19:04:18 +0100160 endif
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100161
162 if fail == 0
163 call Message("Test " .. root .. " OK")
164
165 call writefile(['OK'], 'done/' .. root)
166
167 let ok_count += 1
168 else
169 call Message("Test " .. root .. " FAILED")
170
171 call delete('done/' .. root)
172
Bram Moolenaarc6530c92023-06-22 23:04:11 +0100173 eval failed_tests->add(root)
Bram Moolenaar031d6322023-06-22 22:38:54 +0100174 if len(failed_tests) > MAX_FAILED_COUNT
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100175 call Message('')
176 call Message('Too many errors, aborting')
177 endif
178 endif
179 else
Bram Moolenaar031d6322023-06-22 22:38:54 +0100180 call Message("Test " .. root .. " skipped")
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100181 let skipped_count += 1
182 endif
183
184 " Append messages to the file "testdir/messages"
185 call AppendMessages('Input file ' .. fname .. ':')
186
Bram Moolenaar031d6322023-06-22 22:38:54 +0100187 if len(failed_tests) > MAX_FAILED_COUNT
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100188 break
Bram Moolenaar46acad72023-06-11 19:04:18 +0100189 endif
190endfor
191
192" Matching "if 1" at the start.
193endif
194
Bram Moolenaar031d6322023-06-22 22:38:54 +0100195call Message(s:test_run_message)
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100196call Message('OK: ' .. ok_count)
Bram Moolenaar031d6322023-06-22 22:38:54 +0100197call Message('FAILED: ' .. len(failed_tests) .. ': ' .. string(failed_tests))
Bram Moolenaar1aa5f1c2023-06-22 21:57:51 +0100198call Message('skipped: ' .. skipped_count)
199call AppendMessages('== SUMMARY ==')
200
Bram Moolenaar031d6322023-06-22 22:38:54 +0100201if len(failed_tests) > 0
Bram Moolenaar46acad72023-06-11 19:04:18 +0100202 " have make report an error
203 cquit
204endif
205qall!