summaryrefslogtreecommitdiffstats
path: root/runtime/syntax/testdir/runtest.vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/syntax/testdir/runtest.vim')
-rw-r--r--runtime/syntax/testdir/runtest.vim320
1 files changed, 183 insertions, 137 deletions
diff --git a/runtime/syntax/testdir/runtest.vim b/runtime/syntax/testdir/runtest.vim
index 80f1eff..e1cfdcf 100644
--- a/runtime/syntax/testdir/runtest.vim
+++ b/runtime/syntax/testdir/runtest.vim
@@ -85,163 +85,209 @@ func HandleSwapExists()
endif
endfunc
-let ok_count = 0
-let failed_tests = []
-let skipped_count = 0
-let MAX_FAILED_COUNT = 5
-for fname in glob('input/*.*', 1, 1)
- if fname =~ '\~$'
- " backup file, skip
- continue
- endif
-
- let linecount = readfile(fname)->len()
- let root = fnamemodify(fname, ':t:r')
- let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '')
- let failed_root = 'failed/' .. root
-
- " Execute the test if the "done" file does not exist or when the input file
- " is newer.
- let in_time = getftime(fname)
- let out_time = getftime('done/' .. root)
- if out_time < 0 || in_time > out_time
- call ch_log('running tests for: ' .. fname)
-
- for dumpname in glob(failed_root .. '_\d*\.dump', 1, 1)
- call delete(dumpname)
- endfor
- call delete('done/' .. root)
-
- let lines =<< trim END
- syntax on
-
- " extra info for shell variables
- func ShellInfo()
- let msg = ''
- for [key, val] in items(b:)
- if key =~ '^is_'
- let msg ..= key .. ': ' .. val .. ', '
- endif
- endfor
- if msg != ''
- echomsg msg
- endif
- endfunc
-
- au! SwapExists * call HandleSwapExists()
- func HandleSwapExists()
- " Ignore finding a swap file for the test input, the user might be
- " editing it and that's OK.
- if expand('<afile>') =~ 'input[/\\].*\..*'
- let v:swapchoice = 'e'
- endif
- endfunc
- END
- call writefile(lines, 'Xtestscript')
+func RunTest()
+ let ok_count = 0
+ let failed_tests = []
+ let skipped_count = 0
+ let MAX_FAILED_COUNT = 5
+ " Create a map of setup configuration filenames with their basenames as keys.
+ let setup = glob('input/setup/*.vim', 1, 1)
+ \ ->reduce({d, f -> extend(d, {fnamemodify(f, ':t:r'): f})}, {})
+
+ for fname in glob('input/*.*', 1, 1)
+ if fname =~ '\~$'
+ " backup file, skip
+ continue
+ endif
- " close all but the last window
- while winnr('$') > 1
- close
- endwhile
+ let linecount = readfile(fname)->len()
+ let root = fnamemodify(fname, ':t:r')
+ let filetype = substitute(root, '\([^_.]*\)[_.].*', '\1', '')
+ let failed_root = 'failed/' .. root
+
+ " Execute the test if the "done" file does not exist or when the input file
+ " is newer.
+ let in_time = getftime(fname)
+ let out_time = getftime('done/' .. root)
+ if out_time < 0 || in_time > out_time
+ call ch_log('running tests for: ' .. fname)
+
+ for dumpname in glob(failed_root .. '_\d*\.dump', 1, 1)
+ call delete(dumpname)
+ endfor
+ call delete('done/' .. root)
- " Redraw to make sure that messages are cleared and there is enough space
- " for the terminal window.
- redraw
+ let lines =<< trim END
+ " extra info for shell variables
+ func ShellInfo()
+ let msg = ''
+ for [key, val] in items(b:)
+ if key =~ '^is_'
+ let msg ..= key .. ': ' .. val .. ', '
+ endif
+ endfor
+ if msg != ''
+ echomsg msg
+ endif
+ endfunc
+
+ au! SwapExists * call HandleSwapExists()
+ func HandleSwapExists()
+ " Ignore finding a swap file for the test input, the user might be
+ " editing it and that's OK.
+ if expand('<afile>') =~ 'input[/\\].*\..*'
+ let v:swapchoice = 'e'
+ endif
+ endfunc
+
+ func LoadFiletype(type)
+ for file in glob("ftplugin/" .. a:type .. "*.vim", 1, 1)
+ exe "source " .. file
+ endfor
+ redraw!
+ endfunc
+
+ func SetUpVim()
+ call cursor(1, 1)
+ " Defend against rogue VIM_TEST_SETUP commands.
+ for _ in range(20)
+ let lnum = search('\C\<VIM_TEST_SETUP\>', 'eW', 20)
+ if lnum < 1
+ break
+ endif
+ exe substitute(getline(lnum), '\C.*\<VIM_TEST_SETUP\>', '', '')
+ endfor
+ call cursor(1, 1)
+ " BEGIN [runtime/defaults.vim]
+ " Also, disable italic highlighting to avoid issues on some terminals.
+ set display=truncate ruler scrolloff=5 t_ZH= t_ZR=
+ syntax on
+ " END [runtime/defaults.vim]
+ redraw!
+ endfunc
+ END
+ call writefile(lines, 'Xtestscript')
+
+ " close all but the last window
+ while winnr('$') > 1
+ close
+ endwhile
+
+ " Redraw to make sure that messages are cleared and there is enough space
+ " for the terminal window.
+ redraw
+
+ " Let "Xtestscript#SetUpVim()" turn the syntax on.
+ let prefix = '-Nu NONE -S Xtestscript'
+ let path = get(setup, root, '')
+ " Source the found setup configuration file.
+ let args = !empty(path)
+ \ ? prefix .. ' -S ' .. path
+ \ : prefix
+ let buf = RunVimInTerminal(args, {})
+ " edit the file only after catching the SwapExists event
+ call term_sendkeys(buf, ":edit " .. fname .. "\<CR>")
+ " set up the testing environment
+ call term_sendkeys(buf, ":call SetUpVim()\<CR>")
+ " load filetype specific settings
+ call term_sendkeys(buf, ":call LoadFiletype('" .. filetype .. "')\<CR>")
+
+ if filetype == 'sh'
+ call term_sendkeys(buf, ":call ShellInfo()\<CR>")
+ endif
- let buf = RunVimInTerminal('-S Xtestscript', {})
- " edit the file only after catching the SwapExists event
- call term_sendkeys(buf, ":edit " .. fname .. "\<CR>")
+ " Screendump at the start of the file: failed/root_00.dump
+ let root_00 = root .. '_00'
+ call ch_log('First screendump for ' .. fname .. ': failed/' .. root_00 .. '.dump')
+ let fail = VerifyScreenDump(buf, root_00, {})
- if filetype == 'sh'
- call term_sendkeys(buf, ":call ShellInfo()\<CR>")
- endif
+ " clear the shell info if there are not enough lines to cause a scroll
+ if filetype == 'sh' && linecount <= 19
+ call term_sendkeys(buf, ":redraw\<CR>")
+ endif
- " Screendump at the start of the file: failed/root_00.dump
- let root_00 = root .. '_00'
- call ch_log('First screendump for ' .. fname .. ': failed/' .. root_00 .. '.dump')
- let fail = VerifyScreenDump(buf, root_00, {})
+ " Make a Screendump every 18 lines of the file: failed/root_NN.dump
+ let topline = 1
+ let nr = 1
+ while linecount - topline > 20
+ let topline += 18
+ call term_sendkeys(buf, printf("%dGzt", topline))
+ let root_next = root .. printf('_%02d', nr)
+ call ch_log('Next screendump for ' .. fname .. ': failed/' .. root_next .. '.dump')
+ let fail += VerifyScreenDump(buf, root_next, {})
+ let nr += 1
+ endwhile
+
+ " Screendump at the end of the file: failed/root_99.dump
+ call term_sendkeys(buf, 'Gzb')
+ let root_last = root .. '_99'
+ call ch_log('Last screendump for ' .. fname .. ': failed/' .. root_last .. '.dump')
+ let fail += VerifyScreenDump(buf, root_last, {})
+
+ call StopVimInTerminal(buf)
+ call delete('Xtestscript')
+
+ " redraw here to avoid the following messages to get mixed up with screen
+ " output.
+ redraw
+
+ " Add any assert errors to s:messages.
+ if len(v:errors) > 0
+ call extend(s:messages, v:errors)
+ " Echo the errors here, in case the script aborts or the "messages" file
+ " is not displayed later.
+ echomsg v:errors
+ let v:errors = []
+ let fail += 1
+ endif
- " clear the shell info if there are not enough lines to cause a scroll
- if filetype == 'sh' && linecount <= 19
- call term_sendkeys(buf, ":redraw\<CR>")
- endif
+ if fail == 0
+ call Message("Test " .. root .. " OK")
- " Make a Screendump every 18 lines of the file: failed/root_NN.dump
- let topline = 1
- let nr = 1
- while linecount - topline > 20
- let topline += 18
- call term_sendkeys(buf, printf("%dGzt", topline))
- let root_next = root .. printf('_%02d', nr)
- call ch_log('Next screendump for ' .. fname .. ': failed/' .. root_next .. '.dump')
- let fail += VerifyScreenDump(buf, root_next, {})
- let nr += 1
- endwhile
-
- " Screendump at the end of the file: failed/root_99.dump
- call term_sendkeys(buf, 'Gzb')
- let root_last = root .. '_99'
- call ch_log('Last screendump for ' .. fname .. ': failed/' .. root_last .. '.dump')
- let fail += VerifyScreenDump(buf, root_last, {})
-
- call StopVimInTerminal(buf)
- call delete('Xtestscript')
-
- " redraw here to avoid the following messages to get mixed up with screen
- " output.
- redraw
-
- " Add any assert errors to s:messages.
- if len(v:errors) > 0
- call extend(s:messages, v:errors)
- " Echo the errors here, in case the script aborts or the "messages" file
- " is not displayed later.
- echomsg v:errors
- let v:errors = []
- let fail += 1
- endif
+ call writefile(['OK'], 'done/' .. root)
- if fail == 0
- call Message("Test " .. root .. " OK")
+ let ok_count += 1
+ else
+ call Message("Test " .. root .. " FAILED")
- call writefile(['OK'], 'done/' .. root)
+ call delete('done/' .. root)
- let ok_count += 1
+ eval failed_tests->add(root)
+ if len(failed_tests) > MAX_FAILED_COUNT
+ call Message('')
+ call Message('Too many errors, aborting')
+ endif
+ endif
else
- call Message("Test " .. root .. " FAILED")
+ call Message("Test " .. root .. " skipped")
+ let skipped_count += 1
+ endif
- call delete('done/' .. root)
+ " Append messages to the file "testdir/messages"
+ call AppendMessages('Input file ' .. fname .. ':')
- eval failed_tests->add(root)
- if len(failed_tests) > MAX_FAILED_COUNT
- call Message('')
- call Message('Too many errors, aborting')
- endif
+ if len(failed_tests) > MAX_FAILED_COUNT
+ break
endif
- else
- call Message("Test " .. root .. " skipped")
- let skipped_count += 1
- endif
+ endfor
- " Append messages to the file "testdir/messages"
- call AppendMessages('Input file ' .. fname .. ':')
+ call Message(s:test_run_message)
+ call Message('OK: ' .. ok_count)
+ call Message('FAILED: ' .. len(failed_tests) .. ': ' .. string(failed_tests))
+ call Message('skipped: ' .. skipped_count)
+ call AppendMessages('== SUMMARY ==')
- if len(failed_tests) > MAX_FAILED_COUNT
- break
+ if len(failed_tests) > 0
+ " have make report an error
+ cquit
endif
-endfor
+endfunc
-call Message(s:test_run_message)
-call Message('OK: ' .. ok_count)
-call Message('FAILED: ' .. len(failed_tests) .. ': ' .. string(failed_tests))
-call Message('skipped: ' .. skipped_count)
-call AppendMessages('== SUMMARY ==')
+call RunTest()
" Matching "if 1" at the start.
endif
-if len(failed_tests) > 0
- " have make report an error
- cquit
-endif
qall!
+
+" vim:ts=8