2015-11-29 17:35:35 +01: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-02-20 14:41:40 +01:00
|
|
|
" To execute only specific test functions, add a second argument. It will be
|
|
|
|
" matched against the names of the Test_ funtion. E.g.:
|
|
|
|
" ../vim -u NONE -S runtest.vim test_channel.vim open_delay
|
|
|
|
" The output can be found in the "messages" file.
|
|
|
|
"
|
2015-11-29 17:35:35 +01: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-02-13 14:06:14 +01:00
|
|
|
"
|
|
|
|
" When debugging a test it can be useful to add messages to v:errors:
|
|
|
|
" call add(v:errors, "this happened")
|
|
|
|
|
2015-11-29 17:35:35 +01:00
|
|
|
|
|
|
|
" Without the +eval feature we can't run these tests, bail out.
|
2015-12-28 14:44:10 +01:00
|
|
|
so small.vim
|
2015-11-29 17:35:35 +01: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-07-12 22:51:22 +02:00
|
|
|
" Common with all tests on all systems.
|
|
|
|
source setup.vim
|
|
|
|
|
2015-12-30 15:49:05 +01:00
|
|
|
" For consistency run all tests with 'nocompatible' set.
|
|
|
|
" This also enables use of line continuation.
|
|
|
|
set nocp viminfo+=nviminfo
|
|
|
|
|
2016-07-21 20:33:32 +02: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
|
|
|
|
|
2015-12-30 15:49:05 +01:00
|
|
|
" Avoid stopping at the "hit enter" prompt
|
|
|
|
set nomore
|
|
|
|
|
|
|
|
" Output all messages in English.
|
|
|
|
lang mess C
|
|
|
|
|
2016-01-16 22:47:23 +01:00
|
|
|
" Always use forward slashes.
|
|
|
|
set shellslash
|
|
|
|
|
2016-01-09 22:28:33 +01:00
|
|
|
let s:srcdir = expand('%:p:h:h')
|
|
|
|
|
2016-05-25 21:23:21 +02:00
|
|
|
" Prepare for calling test_garbagecollect_now().
|
2016-04-14 12:46:51 +02:00
|
|
|
let v:testing = 1
|
|
|
|
|
2016-01-09 22:28:33 +01:00
|
|
|
" Support function: get the alloc ID by name.
|
|
|
|
function GetAllocId(name)
|
|
|
|
exe 'split ' . s:srcdir . '/alloc.h'
|
2016-01-15 20:53:38 +01:00
|
|
|
let top = search('typedef enum')
|
|
|
|
if top == 0
|
|
|
|
call add(v:errors, 'typedef not found in alloc.h')
|
|
|
|
endif
|
2016-01-09 22:28:33 +01:00
|
|
|
let lnum = search('aid_' . a:name . ',')
|
|
|
|
if lnum == 0
|
|
|
|
call add(v:errors, 'Alloc ID ' . a:name . ' not defined')
|
|
|
|
endif
|
|
|
|
close
|
2016-01-15 20:53:38 +01:00
|
|
|
return lnum - top - 1
|
2016-01-09 22:28:33 +01:00
|
|
|
endfunc
|
|
|
|
|
2016-03-03 13:10:44 +01:00
|
|
|
function RunTheTest(test)
|
|
|
|
echo 'Executing ' . a:test
|
|
|
|
if exists("*SetUp")
|
|
|
|
call SetUp()
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(s:messages, 'Executing ' . a:test)
|
|
|
|
let s:done += 1
|
|
|
|
try
|
|
|
|
exe 'call ' . a:test
|
|
|
|
catch
|
|
|
|
call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
|
|
|
|
endtry
|
|
|
|
|
|
|
|
if exists("*TearDown")
|
|
|
|
call TearDown()
|
|
|
|
endif
|
2016-08-02 23:04:49 +02:00
|
|
|
|
|
|
|
" Close any extra windows and make the current one not modified.
|
2016-08-24 21:21:26 +02:00
|
|
|
while 1
|
|
|
|
let wincount = winnr('$')
|
|
|
|
if wincount == 1
|
|
|
|
break
|
|
|
|
endif
|
2016-08-02 23:04:49 +02:00
|
|
|
bwipe!
|
2016-08-24 21:21:26 +02:00
|
|
|
if wincount == winnr('$')
|
|
|
|
" Did not manage to close a window.
|
|
|
|
only!
|
|
|
|
break
|
|
|
|
endif
|
2016-08-02 23:04:49 +02:00
|
|
|
endwhile
|
|
|
|
set nomodified
|
2016-03-03 13:10:44 +01:00
|
|
|
endfunc
|
2016-01-09 22:28:33 +01:00
|
|
|
|
2015-11-29 17:35:35 +01:00
|
|
|
" Source the test script. First grab the file name, in case the script
|
2016-02-13 14:06:14 +01: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-01-02 19:50:04 +01:00
|
|
|
if expand('%') =~ 'test_viml.vim'
|
2016-02-13 14:06:14 +01:00
|
|
|
" this test has intentional s:errors, don't use try/catch.
|
2015-12-28 14:44:10 +01:00
|
|
|
source %
|
2016-01-02 19:50:04 +01:00
|
|
|
else
|
|
|
|
try
|
|
|
|
source %
|
|
|
|
catch
|
2016-02-13 14:06:14 +01:00
|
|
|
let s:fail += 1
|
|
|
|
call add(s:errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint)
|
2016-01-02 19:50:04 +01:00
|
|
|
endtry
|
|
|
|
endif
|
2015-11-29 17:35:35 +01:00
|
|
|
|
2016-03-03 13:10:44 +01:00
|
|
|
" Names of flaky tests.
|
2016-08-04 21:11:32 +02:00
|
|
|
let s:flaky = ['Test_reltime()', 'Test_nb_basic()', 'Test_communicate()']
|
2016-03-03 13:10:44 +01:00
|
|
|
|
2015-11-29 17:35:35 +01:00
|
|
|
" Locate Test_ functions and execute them.
|
2016-01-17 17:10:59 +01:00
|
|
|
set nomore
|
2015-11-29 17:35:35 +01:00
|
|
|
redir @q
|
2016-02-18 22:25:47 +01:00
|
|
|
silent function /^Test_
|
2015-11-29 17:35:35 +01:00
|
|
|
redir END
|
2016-02-13 14:06:14 +01:00
|
|
|
let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g'))
|
2015-11-29 17:35:35 +01:00
|
|
|
|
2016-02-20 14:41:40 +01:00
|
|
|
" If there is an extra argument filter the function names against it.
|
|
|
|
if argc() > 1
|
|
|
|
let s:tests = filter(s:tests, 'v:val =~ argv(1)')
|
|
|
|
endif
|
|
|
|
|
2016-01-09 20:23:00 +01:00
|
|
|
" Execute the tests in alphabetical order.
|
2016-02-18 22:25:47 +01:00
|
|
|
for s:test in sort(s:tests)
|
2016-03-03 13:10:44 +01:00
|
|
|
call RunTheTest(s:test)
|
2015-11-29 17:35:35 +01:00
|
|
|
|
2016-03-03 13:10:44 +01:00
|
|
|
if len(v:errors) > 0 && index(s:flaky, s:test) >= 0
|
|
|
|
call add(s:messages, 'Flaky test failed, running it again')
|
|
|
|
let v:errors = []
|
|
|
|
call RunTheTest(s:test)
|
|
|
|
endif
|
2015-11-29 17:35:35 +01:00
|
|
|
|
|
|
|
if len(v:errors) > 0
|
2016-02-13 14:06:14 +01:00
|
|
|
let s:fail += 1
|
|
|
|
call add(s:errors, 'Found errors in ' . s:test . ':')
|
|
|
|
call extend(s:errors, v:errors)
|
2015-11-29 17:35:35 +01:00
|
|
|
let v:errors = []
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2016-07-09 15:38:32 +02:00
|
|
|
" Don't write viminfo on exit.
|
|
|
|
set viminfo=
|
|
|
|
|
2016-02-13 14:06:14 +01:00
|
|
|
if s:fail == 0
|
2015-11-29 17:35:35 +01:00
|
|
|
" Success, create the .res file so that make knows it's done.
|
2016-02-13 14:06:14 +01:00
|
|
|
exe 'split ' . fnamemodify(g:testname, ':r') . '.res'
|
2015-11-29 17:35:35 +01:00
|
|
|
write
|
|
|
|
endif
|
|
|
|
|
2016-02-13 14:06:14 +01:00
|
|
|
if len(s:errors) > 0
|
2015-11-29 17:35:35 +01:00
|
|
|
" Append errors to test.log
|
|
|
|
split test.log
|
|
|
|
call append(line('$'), '')
|
2016-02-13 14:06:14 +01:00
|
|
|
call append(line('$'), 'From ' . g:testname . ':')
|
|
|
|
call append(line('$'), s:errors)
|
2015-11-29 17:35:35 +01:00
|
|
|
write
|
|
|
|
endif
|
|
|
|
|
2016-02-13 14:06:14 +01:00
|
|
|
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test')
|
2015-12-29 14:26:57 +01:00
|
|
|
echo message
|
2016-02-13 14:06:14 +01:00
|
|
|
call add(s:messages, message)
|
|
|
|
if s:fail > 0
|
|
|
|
let message = s:fail . ' FAILED:'
|
2015-12-29 14:26:57 +01:00
|
|
|
echo message
|
2016-02-13 14:06:14 +01:00
|
|
|
call add(s:messages, message)
|
|
|
|
call extend(s:messages, s:errors)
|
2015-11-29 17:35:35 +01:00
|
|
|
endif
|
|
|
|
|
2015-12-29 14:26:57 +01:00
|
|
|
" Append messages to "messages"
|
|
|
|
split messages
|
|
|
|
call append(line('$'), '')
|
2016-02-13 14:06:14 +01:00
|
|
|
call append(line('$'), 'From ' . g:testname . ':')
|
|
|
|
call append(line('$'), s:messages)
|
2015-12-29 14:26:57 +01:00
|
|
|
write
|
|
|
|
|
2015-11-29 17:35:35 +01:00
|
|
|
qall!
|