2015-12-12 20:19:54 -07:00
|
|
|
" This script is sourced while editing the .vim file with the tests.
|
|
|
|
" When the script is successful the .res file will be created.
|
|
|
|
" Errors are appended to the test.log file.
|
|
|
|
"
|
2016-07-19 22:40:04 -07:00
|
|
|
" To execute only specific test functions, add a second argument. It will be
|
|
|
|
" matched against the names of the Test_ function. E.g.:
|
|
|
|
" ../vim -u NONE -S runtest.vim test_channel.vim open_delay
|
|
|
|
" The output can be found in the "messages" file.
|
|
|
|
"
|
2015-12-12 20:19:54 -07:00
|
|
|
" The test script may contain anything, only functions that start with
|
|
|
|
" "Test_" are special. These will be invoked and should contain assert
|
|
|
|
" functions. See test_assert.vim for an example.
|
|
|
|
"
|
|
|
|
" It is possible to source other files that contain "Test_" functions. This
|
|
|
|
" can speed up testing, since Vim does not need to restart. But be careful
|
|
|
|
" that the tests do not interfere with each other.
|
|
|
|
"
|
|
|
|
" If an error cannot be detected properly with an assert function add the
|
|
|
|
" error to the v:errors list:
|
|
|
|
" call add(v:errors, 'test foo failed: Cannot find xyz')
|
|
|
|
"
|
|
|
|
" If preparation for each Test_ function is needed, define a SetUp function.
|
|
|
|
" It will be called before each Test_ function.
|
|
|
|
"
|
|
|
|
" If cleanup after each Test_ function is needed, define a TearDown function.
|
|
|
|
" It will be called after each Test_ function.
|
2016-09-21 09:00:50 -07:00
|
|
|
"
|
|
|
|
" When debugging a test it can be useful to add messages to v:errors:
|
|
|
|
" call add(v:errors, "this happened")
|
|
|
|
|
2015-12-12 20:19:54 -07:00
|
|
|
|
|
|
|
" Check that the screen size is at least 24 x 80 characters.
|
|
|
|
if &lines < 24 || &columns < 80
|
|
|
|
let error = 'Screen size too small! Tests require at least 24 lines with 80 characters'
|
|
|
|
echoerr error
|
|
|
|
split test.log
|
|
|
|
$put =error
|
|
|
|
w
|
|
|
|
cquit
|
|
|
|
endif
|
|
|
|
|
2016-04-14 12:14:08 -07:00
|
|
|
" This also enables use of line continuation.
|
|
|
|
set viminfo+=nviminfo
|
|
|
|
|
2016-11-22 13:33:13 -07:00
|
|
|
" Use utf-8 or latin1 be default, instead of whatever the system default
|
|
|
|
" happens to be. Individual tests can overrule this at the top of the file.
|
|
|
|
if has('multi_byte')
|
|
|
|
set encoding=utf-8
|
|
|
|
else
|
|
|
|
set encoding=latin1
|
|
|
|
endif
|
|
|
|
|
2016-04-14 12:14:08 -07:00
|
|
|
" Avoid stopping at the "hit enter" prompt
|
|
|
|
set nomore
|
|
|
|
|
|
|
|
" Output all messages in English.
|
|
|
|
lang mess C
|
|
|
|
|
2016-07-06 06:13:48 -07:00
|
|
|
" Always use forward slashes.
|
|
|
|
set shellslash
|
|
|
|
|
2016-11-21 15:28:50 -07:00
|
|
|
" Make sure $HOME does not get read or written.
|
|
|
|
let $HOME = '/does/not/exist'
|
|
|
|
|
2016-07-11 02:01:22 -07:00
|
|
|
function RunTheTest(test)
|
2016-09-21 09:00:50 -07:00
|
|
|
echo 'Executing ' . a:test
|
2016-07-11 02:01:22 -07:00
|
|
|
if exists("*SetUp")
|
|
|
|
call SetUp()
|
|
|
|
endif
|
|
|
|
|
2016-09-21 09:00:50 -07:00
|
|
|
call add(s:messages, 'Executing ' . a:test)
|
2016-07-11 02:01:22 -07:00
|
|
|
let s:done += 1
|
|
|
|
try
|
2016-09-21 09:00:50 -07:00
|
|
|
exe 'call ' . a:test
|
2016-07-11 02:01:22 -07:00
|
|
|
catch
|
2016-09-21 09:00:50 -07:00
|
|
|
call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
|
2016-07-11 02:01:22 -07:00
|
|
|
endtry
|
|
|
|
|
|
|
|
if exists("*TearDown")
|
|
|
|
call TearDown()
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
|
2015-12-12 20:19:54 -07:00
|
|
|
" Source the test script. First grab the file name, in case the script
|
2016-09-21 09:00:50 -07:00
|
|
|
" navigates away. g:testname can be used by the tests.
|
|
|
|
let g:testname = expand('%')
|
|
|
|
let s:done = 0
|
|
|
|
let s:fail = 0
|
|
|
|
let s:errors = []
|
|
|
|
let s:messages = []
|
2016-04-14 12:43:53 -07:00
|
|
|
if expand('%') =~ 'test_viml.vim'
|
2016-09-21 09:00:50 -07:00
|
|
|
" this test has intentional s:errors, don't use try/catch.
|
2016-01-10 13:31:33 -07:00
|
|
|
source %
|
2016-04-14 12:43:53 -07:00
|
|
|
else
|
|
|
|
try
|
|
|
|
source %
|
|
|
|
catch
|
2016-09-21 09:00:50 -07:00
|
|
|
let s:fail += 1
|
|
|
|
call add(s:errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint)
|
2016-04-14 12:43:53 -07:00
|
|
|
endtry
|
|
|
|
endif
|
2015-12-12 20:19:54 -07:00
|
|
|
|
2016-07-11 02:01:22 -07:00
|
|
|
" Names of flaky tests.
|
|
|
|
let s:flaky = []
|
|
|
|
|
2015-12-12 20:19:54 -07:00
|
|
|
" Locate Test_ functions and execute them.
|
2016-04-26 19:34:12 -07:00
|
|
|
set nomore
|
2015-12-12 20:19:54 -07:00
|
|
|
redir @q
|
2016-06-12 21:05:42 -07:00
|
|
|
silent function /^Test_
|
2015-12-12 20:19:54 -07:00
|
|
|
redir END
|
2016-09-21 09:00:50 -07:00
|
|
|
let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g'))
|
2015-12-12 20:19:54 -07:00
|
|
|
|
2016-07-19 22:40:04 -07:00
|
|
|
" If there is an extra argument filter the function names against it.
|
|
|
|
if argc() > 1
|
2016-09-21 09:00:50 -07:00
|
|
|
let s:tests = filter(s:tests, 'v:val =~ argv(1)')
|
2016-07-19 22:40:04 -07:00
|
|
|
endif
|
|
|
|
|
2016-05-24 16:53:50 -07:00
|
|
|
" Execute the tests in alphabetical order.
|
2016-09-21 09:00:50 -07:00
|
|
|
for s:test in sort(s:tests)
|
|
|
|
call RunTheTest(s:test)
|
2015-12-12 20:19:54 -07:00
|
|
|
|
2016-09-23 11:39:10 -07:00
|
|
|
if len(v:errors) > 0 && index(s:flaky, s:test) >= 0
|
2016-09-21 12:39:18 -07:00
|
|
|
call add(s:messages, 'Flaky test failed, running it again')
|
2016-07-11 02:01:22 -07:00
|
|
|
let v:errors = []
|
2016-09-21 09:00:50 -07:00
|
|
|
call RunTheTest(s:test)
|
2016-07-11 02:01:22 -07:00
|
|
|
endif
|
2015-12-12 20:19:54 -07:00
|
|
|
|
|
|
|
if len(v:errors) > 0
|
2016-09-21 09:00:50 -07:00
|
|
|
let s:fail += 1
|
|
|
|
call add(s:errors, 'Found errors in ' . s:test . ':')
|
|
|
|
call extend(s:errors, v:errors)
|
2015-12-12 20:19:54 -07:00
|
|
|
let v:errors = []
|
|
|
|
endif
|
|
|
|
|
|
|
|
endfor
|
|
|
|
|
2016-11-24 14:39:10 -07:00
|
|
|
" Don't write viminfo on exit.
|
|
|
|
set viminfo=
|
|
|
|
|
2016-09-21 09:00:50 -07:00
|
|
|
if s:fail == 0
|
2015-12-12 20:19:54 -07:00
|
|
|
" Success, create the .res file so that make knows it's done.
|
2016-09-21 09:00:50 -07:00
|
|
|
exe 'split ' . fnamemodify(g:testname, ':r') . '.res'
|
2015-12-12 20:19:54 -07:00
|
|
|
write
|
|
|
|
endif
|
|
|
|
|
2016-09-21 09:00:50 -07:00
|
|
|
if len(s:errors) > 0
|
2015-12-12 20:19:54 -07:00
|
|
|
" Append errors to test.log
|
|
|
|
split test.log
|
|
|
|
call append(line('$'), '')
|
2016-09-21 09:00:50 -07:00
|
|
|
call append(line('$'), 'From ' . g:testname . ':')
|
|
|
|
call append(line('$'), s:errors)
|
2015-12-12 20:19:54 -07:00
|
|
|
write
|
|
|
|
endif
|
|
|
|
|
2016-09-21 09:00:50 -07:00
|
|
|
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests': ' test')
|
2016-01-10 13:38:54 -07:00
|
|
|
echo message
|
2016-09-21 09:00:50 -07:00
|
|
|
call add(s:messages, message)
|
|
|
|
if s:fail > 0
|
|
|
|
let message = s:fail . ' FAILED'
|
2016-01-10 13:38:54 -07:00
|
|
|
echo message
|
2016-09-21 09:00:50 -07:00
|
|
|
call add(s:messages, message)
|
|
|
|
call extend(s:messages, s:errors)
|
2015-12-12 20:19:54 -07:00
|
|
|
endif
|
|
|
|
|
2016-01-10 13:38:54 -07:00
|
|
|
" Append messages to "messages"
|
2016-09-21 12:39:18 -07:00
|
|
|
split messages
|
2016-01-10 13:38:54 -07:00
|
|
|
call append(line('$'), '')
|
2016-09-21 09:00:50 -07:00
|
|
|
call append(line('$'), 'From ' . g:testname . ':')
|
|
|
|
call append(line('$'), s:messages)
|
2016-01-10 13:38:54 -07:00
|
|
|
write
|
|
|
|
|
2015-12-12 20:19:54 -07:00
|
|
|
qall!
|