vim-patch:7.4.1309

Problem:    When a test fails not all relevant info is listed.
Solution:   Add the errors to the messages.

00af60bbb6

7.4.1309 was incorrectly marked as applied in #4301.  7.4.1477 relies on
some of the changes that had been made in 7.4.1309, so this fixes the
build after I, pre-emptively, merged #5038.
This commit is contained in:
James McCoy 2016-09-21 12:00:50 -04:00
parent 6cf24be295
commit 7063dd9d64

View File

@ -24,6 +24,10 @@
" "
" If cleanup after each Test_ function is needed, define a TearDown function. " If cleanup after each Test_ function is needed, define a TearDown function.
" It will be called after each Test_ function. " It will be called after each Test_ function.
"
" When debugging a test it can be useful to add messages to v:errors:
" call add(v:errors, "this happened")
" Check that the screen size is at least 24 x 80 characters. " Check that the screen size is at least 24 x 80 characters.
if &lines < 24 || &columns < 80 if &lines < 24 || &columns < 80
@ -48,17 +52,17 @@ lang mess C
set shellslash set shellslash
function RunTheTest(test) function RunTheTest(test)
echo 'Executing ' . test echo 'Executing ' . a:test
if exists("*SetUp") if exists("*SetUp")
call SetUp() call SetUp()
endif endif
call add(s:messages, 'Executing ' . test) call add(s:messages, 'Executing ' . a:test)
let s:done += 1 let s:done += 1
try try
exe 'call ' . test exe 'call ' . a:test
catch catch
call add(v:errors, 'Caught exception in ' . test . ': ' . v:exception . ' @ ' . v:throwpoint) call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
endtry endtry
if exists("*TearDown") if exists("*TearDown")
@ -67,21 +71,21 @@ function RunTheTest(test)
endfunc endfunc
" Source the test script. First grab the file name, in case the script " Source the test script. First grab the file name, in case the script
" navigates away. " navigates away. g:testname can be used by the tests.
let testname = expand('%') let g:testname = expand('%')
let done = 0 let s:done = 0
let fail = 0 let s:fail = 0
let errors = [] let s:errors = []
let messages = [] let s:messages = []
if expand('%') =~ 'test_viml.vim' if expand('%') =~ 'test_viml.vim'
" this test has intentional errors, don't use try/catch. " this test has intentional s:errors, don't use try/catch.
source % source %
else else
try try
source % source %
catch catch
let fail += 1 let s:fail += 1
call add(errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint) call add(s:errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint)
endtry endtry
endif endif
@ -93,61 +97,62 @@ set nomore
redir @q redir @q
silent function /^Test_ silent function /^Test_
redir END redir END
let tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g')) let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g'))
" If there is an extra argument filter the function names against it. " If there is an extra argument filter the function names against it.
if argc() > 1 if argc() > 1
let tests = filter(tests, 'v:val =~ argv(1)') let s:tests = filter(s:tests, 'v:val =~ argv(1)')
endif endif
" Execute the tests in alphabetical order. " Execute the tests in alphabetical order.
for test in sort(tests) for s:test in sort(s:tests)
call RunTheTest(test) call RunTheTest(s:test)
if len(v:errors) > 0 && index(flaky, test) >= 0 if len(v:errors) > 0 && index(flaky, s:test) >= 0
call add(messages, 'Flaky test failed, running it again') call add(messages, 'Flaky test failed, running it again')
let v:errors = [] let v:errors = []
call RunTheTest(test) call RunTheTest(s:test)
endif endif
if len(v:errors) > 0 if len(v:errors) > 0
let fail += 1 let s:fail += 1
call add(errors, 'Found errors in ' . test . ':') call add(s:errors, 'Found errors in ' . s:test . ':')
call extend(errors, v:errors) call extend(s:errors, v:errors)
let v:errors = [] let v:errors = []
endif endif
endfor endfor
if fail == 0 if s:fail == 0
" Success, create the .res file so that make knows it's done. " Success, create the .res file so that make knows it's done.
exe 'split ' . fnamemodify(testname, ':r') . '.res' exe 'split ' . fnamemodify(g:testname, ':r') . '.res'
write write
endif endif
if len(errors) > 0 if len(s:errors) > 0
" Append errors to test.log " Append errors to test.log
split test.log split test.log
call append(line('$'), '') call append(line('$'), '')
call append(line('$'), 'From ' . testname . ':') call append(line('$'), 'From ' . g:testname . ':')
call append(line('$'), errors) call append(line('$'), s:errors)
write write
endif endif
let message = 'Executed ' . done . (done > 1 ? ' tests': ' test') let message = 'Executed ' . s:done . (s:done > 1 ? ' tests': ' test')
echo message echo message
call add(messages, message) call add(s:messages, message)
if fail > 0 if s:fail > 0
let message = fail . ' FAILED' let message = s:fail . ' FAILED'
echo message echo message
call add(messages, message) call add(s:messages, message)
call extend(s:messages, s:errors)
endif endif
" Append messages to "messages" " Append messages to "messages"
split messages split s:messages
call append(line('$'), '') call append(line('$'), '')
call append(line('$'), 'From ' . testname . ':') call append(line('$'), 'From ' . g:testname . ':')
call append(line('$'), messages) call append(line('$'), s:messages)
write write
qall! qall!