0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors

Problem:    Tests use assert_true(0) and assert_false(1) to report errors.
Solution:   Use assert_report().
This commit is contained in:
Bram Moolenaar
2017-03-18 20:18:45 +01:00
parent 42205551b1
commit 37175409d7
12 changed files with 44 additions and 41 deletions

View File

@@ -36,6 +36,12 @@ func Test_assert_notequal()
call remove(v:errors, 0) call remove(v:errors, 0)
endfunc endfunc
func Test_assert_report()
call assert_report('something is wrong')
call assert_match('something is wrong', v:errors[0])
call remove(v:errors, 0)
endfunc
func Test_assert_exception() func Test_assert_exception()
try try
nocommand nocommand

View File

@@ -8,10 +8,14 @@ source shared.vim
let s:python = PythonProg() let s:python = PythonProg()
if s:python == '' if s:python == ''
" Can't run this test. " Can't run this test without Python.
finish finish
endif endif
" Uncomment the next line to see what happens. Output is in
" src/testdir/channellog.
" call ch_logfile('channellog', 'w')
let s:chopt = {} let s:chopt = {}
" Run "testfunc" after sarting the server and stop the server afterwards. " Run "testfunc" after sarting the server and stop the server afterwards.
@@ -31,7 +35,7 @@ func Ch_communicate(port)
let handle = ch_open('localhost:' . a:port, s:chopt) let handle = ch_open('localhost:' . a:port, s:chopt)
unlet s:chopt.drop unlet s:chopt.drop
if ch_status(handle) == "fail" if ch_status(handle) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
if has('job') if has('job')
@@ -93,7 +97,7 @@ func Ch_communicate(port)
call ch_sendexpr(handle, 'hello!', {'callback': 'Ch_requestHandler'}) call ch_sendexpr(handle, 'hello!', {'callback': 'Ch_requestHandler'})
call WaitFor('exists("g:Ch_responseHandle")') call WaitFor('exists("g:Ch_responseHandle")')
if !exists('g:Ch_responseHandle') if !exists('g:Ch_responseHandle')
call assert_false(1, 'g:Ch_responseHandle was not set') call assert_report('g:Ch_responseHandle was not set')
else else
call assert_equal(handle, g:Ch_responseHandle) call assert_equal(handle, g:Ch_responseHandle)
unlet g:Ch_responseHandle unlet g:Ch_responseHandle
@@ -104,7 +108,7 @@ func Ch_communicate(port)
call ch_sendexpr(handle, 'hello!', {'callback': function('Ch_requestHandler')}) call ch_sendexpr(handle, 'hello!', {'callback': function('Ch_requestHandler')})
call WaitFor('exists("g:Ch_responseHandle")') call WaitFor('exists("g:Ch_responseHandle")')
if !exists('g:Ch_responseHandle') if !exists('g:Ch_responseHandle')
call assert_false(1, 'g:Ch_responseHandle was not set') call assert_report('g:Ch_responseHandle was not set')
else else
call assert_equal(handle, g:Ch_responseHandle) call assert_equal(handle, g:Ch_responseHandle)
unlet g:Ch_responseHandle unlet g:Ch_responseHandle
@@ -116,7 +120,7 @@ func Ch_communicate(port)
call ch_sendexpr(handle, 'hello!', {'callback': {a, b -> Ch_requestHandler(a, b)}}) call ch_sendexpr(handle, 'hello!', {'callback': {a, b -> Ch_requestHandler(a, b)}})
call WaitFor('exists("g:Ch_responseHandle")') call WaitFor('exists("g:Ch_responseHandle")')
if !exists('g:Ch_responseHandle') if !exists('g:Ch_responseHandle')
call assert_false(1, 'g:Ch_responseHandle was not set') call assert_report('g:Ch_responseHandle was not set')
else else
call assert_equal(handle, g:Ch_responseHandle) call assert_equal(handle, g:Ch_responseHandle)
unlet g:Ch_responseHandle unlet g:Ch_responseHandle
@@ -209,7 +213,7 @@ func Ch_two_channels(port)
let handle = ch_open('localhost:' . a:port, s:chopt) let handle = ch_open('localhost:' . a:port, s:chopt)
call assert_equal(v:t_channel, type(handle)) call assert_equal(v:t_channel, type(handle))
if ch_status(handle) == "fail" if ch_status(handle) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
@@ -217,7 +221,7 @@ func Ch_two_channels(port)
let newhandle = ch_open('localhost:' . a:port, s:chopt) let newhandle = ch_open('localhost:' . a:port, s:chopt)
if ch_status(newhandle) == "fail" if ch_status(newhandle) == "fail"
call assert_false(1, "Can't open second channel") call assert_report("Can't open second channel")
return return
endif endif
call assert_equal('got it', ch_evalexpr(newhandle, 'hello!')) call assert_equal('got it', ch_evalexpr(newhandle, 'hello!'))
@@ -238,7 +242,7 @@ endfunc
func Ch_server_crash(port) func Ch_server_crash(port)
let handle = ch_open('localhost:' . a:port, s:chopt) let handle = ch_open('localhost:' . a:port, s:chopt)
if ch_status(handle) == "fail" if ch_status(handle) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
@@ -263,7 +267,7 @@ endfunc
func Ch_channel_handler(port) func Ch_channel_handler(port)
let handle = ch_open('localhost:' . a:port, s:chopt) let handle = ch_open('localhost:' . a:port, s:chopt)
if ch_status(handle) == "fail" if ch_status(handle) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
@@ -306,7 +310,7 @@ endfunc
func Ch_channel_zero(port) func Ch_channel_zero(port)
let handle = ch_open('localhost:' . a:port, s:chopt) let handle = ch_open('localhost:' . a:port, s:chopt)
if ch_status(handle) == "fail" if ch_status(handle) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
@@ -373,7 +377,7 @@ endfunc
func Ch_raw_one_time_callback(port) func Ch_raw_one_time_callback(port)
let handle = ch_open('localhost:' . a:port, s:chopt) let handle = ch_open('localhost:' . a:port, s:chopt)
if ch_status(handle) == "fail" if ch_status(handle) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
call ch_setoptions(handle, {'mode': 'raw'}) call ch_setoptions(handle, {'mode': 'raw'})
@@ -429,7 +433,7 @@ func Test_connect_waittime()
endif endif
catch catch
if v:exception !~ 'Connection reset by peer' if v:exception !~ 'Connection reset by peer'
call assert_false(1, "Caught exception: " . v:exception) call assert_report("Caught exception: " . v:exception)
endif endif
endtry endtry
endfunc endfunc
@@ -1343,7 +1347,7 @@ func Ch_open_delay(port)
let channel = ch_open('localhost:' . a:port, s:chopt) let channel = ch_open('localhost:' . a:port, s:chopt)
unlet s:chopt.waittime unlet s:chopt.waittime
if ch_status(channel) == "fail" if ch_status(channel) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
call assert_equal('got it', ch_evalexpr(channel, 'hello!')) call assert_equal('got it', ch_evalexpr(channel, 'hello!'))
@@ -1365,7 +1369,7 @@ endfunc
function Ch_test_call(port) function Ch_test_call(port)
let handle = ch_open('localhost:' . a:port, s:chopt) let handle = ch_open('localhost:' . a:port, s:chopt)
if ch_status(handle) == "fail" if ch_status(handle) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
@@ -1463,7 +1467,7 @@ endfunc
function Ch_test_close_callback(port) function Ch_test_close_callback(port)
let handle = ch_open('localhost:' . a:port, s:chopt) let handle = ch_open('localhost:' . a:port, s:chopt)
if ch_status(handle) == "fail" if ch_status(handle) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
call ch_setoptions(handle, {'close_cb': 'MyCloseCb'}) call ch_setoptions(handle, {'close_cb': 'MyCloseCb'})
@@ -1481,7 +1485,7 @@ endfunc
function Ch_test_close_partial(port) function Ch_test_close_partial(port)
let handle = ch_open('localhost:' . a:port, s:chopt) let handle = ch_open('localhost:' . a:port, s:chopt)
if ch_status(handle) == "fail" if ch_status(handle) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
let g:Ch_d = {} let g:Ch_d = {}
@@ -1631,7 +1635,7 @@ endfunc
function Ch_test_close_lambda(port) function Ch_test_close_lambda(port)
let handle = ch_open('localhost:' . a:port, s:chopt) let handle = ch_open('localhost:' . a:port, s:chopt)
if ch_status(handle) == "fail" if ch_status(handle) == "fail"
call assert_false(1, "Can't open channel") call assert_report("Can't open channel")
return return
endif endif
let g:Ch_close_ret = '' let g:Ch_close_ret = ''
@@ -1646,6 +1650,3 @@ func Test_close_lambda()
call ch_log('Test_close_lambda()') call ch_log('Test_close_lambda()')
call s:run_server('Ch_test_close_lambda') call s:run_server('Ch_test_close_lambda')
endfunc endfunc
" Uncomment this to see what happens, output is in src/testdir/channellog.
" call ch_logfile('channellog', 'w')

View File

@@ -28,7 +28,7 @@ func Test_cscopeWithCscopeConnections()
cscope add Xcscope.out cscope add Xcscope.out
set cscopeverbose set cscopeverbose
catch catch
call assert_true(0) call assert_report('exception thrown')
endtry endtry
call assert_fails('cscope add', 'E560') call assert_fails('cscope add', 'E560')
call assert_fails('cscope add Xcscope.out', 'E568') call assert_fails('cscope add Xcscope.out', 'E568')

View File

@@ -1,13 +1,7 @@
" Tests for cursor(). " Tests for cursor().
func Test_wrong_arguments() func Test_wrong_arguments()
try call assert_fails('call cursor(1. 3)', 'E474:')
call cursor(1. 3)
" not reached
call assert_false(1)
catch
call assert_exception('E474:')
endtry
endfunc endfunc
func Test_move_cursor() func Test_move_cursor()

View File

@@ -87,7 +87,7 @@ endfunc
func Test_loop_over_null_list() func Test_loop_over_null_list()
let null_list = test_null_list() let null_list = test_null_list()
for i in null_list for i in null_list
call assert_true(0, 'should not get here') call assert_report('should not get here')
endfor endfor
endfunc endfunc

View File

@@ -505,7 +505,7 @@ func Test_set_guifontwide()
" Case 2: guifontset is invalid " Case 2: guifontset is invalid
try try
set guifontset=-*-notexist-* set guifontset=-*-notexist-*
call assert_false(1, "'set guifontset=-*-notexist-*' should have failed") call assert_report("'set guifontset=-*-notexist-*' should have failed")
catch catch
call assert_exception('E598') call assert_exception('E598')
endtry endtry

View File

@@ -8,7 +8,7 @@ func Test_load_menu()
try try
source $VIMRUNTIME/menu.vim source $VIMRUNTIME/menu.vim
catch catch
call assert_false(1, 'error while loading menus: ' . v:exception) call assert_report('error while loading menus: ' . v:exception)
endtry endtry
call assert_match('browse confirm w', execute(':menu File.Save')) call assert_match('browse confirm w', execute(':menu File.Save'))
source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/delmenu.vim

View File

@@ -132,7 +132,7 @@ func <SID>catch_peval(expr)
catch catch
return v:exception return v:exception
endtry endtry
call assert_true(0, 'no exception for `perleval("'.a:expr.'")`') call assert_report('no exception for `perleval("'.a:expr.'")`')
return '' return ''
endfunc endfunc

View File

@@ -562,7 +562,7 @@ func Test_completion_comment_formatting()
%d %d
try try
call feedkeys("o/*\<cr>\<cr>\<c-x>\<c-u>/\<esc>", 'tx') call feedkeys("o/*\<cr>\<cr>\<c-x>\<c-u>/\<esc>", 'tx')
call assert_false(1, 'completefunc not set, should have failed') call assert_report('completefunc not set, should have failed')
catch catch
call assert_exception('E764:') call assert_exception('E764:')
endtry endtry

View File

@@ -450,13 +450,13 @@ func Test_viminfo_file_mark_tabclose()
let lnum = line('.') let lnum = line('.')
while 1 while 1
if lnum == line('$') if lnum == line('$')
call assert_false(1, 'mark not found in Xtestfileintab') call assert_report('mark not found in Xtestfileintab')
break break
endif endif
let lnum += 1 let lnum += 1
let line = getline(lnum) let line = getline(lnum)
if line == '' if line == ''
call assert_false(1, 'mark not found in Xtestfileintab') call assert_report('mark not found in Xtestfileintab')
break break
endif endif
if line =~ "^\t\"" if line =~ "^\t\""

View File

@@ -1256,14 +1256,14 @@ func Test_script_lines()
\ '.', \ '.',
\ ]) \ ])
catch catch
call assert_false(1, "Can't define function") call assert_report("Can't define function")
endtry endtry
try try
call DefineFunction('T_Append', [ call DefineFunction('T_Append', [
\ 'append', \ 'append',
\ 'abc', \ 'abc',
\ ]) \ ])
call assert_false(1, "Shouldn't be able to define function") call assert_report("Shouldn't be able to define function")
catch catch
call assert_exception('Vim(function):E126: Missing :endfunction') call assert_exception('Vim(function):E126: Missing :endfunction')
endtry endtry
@@ -1276,14 +1276,14 @@ func Test_script_lines()
\ '.', \ '.',
\ ]) \ ])
catch catch
call assert_false(1, "Can't define function") call assert_report("Can't define function")
endtry endtry
try try
call DefineFunction('T_Change', [ call DefineFunction('T_Change', [
\ 'change', \ 'change',
\ 'abc', \ 'abc',
\ ]) \ ])
call assert_false(1, "Shouldn't be able to define function") call assert_report("Shouldn't be able to define function")
catch catch
call assert_exception('Vim(function):E126: Missing :endfunction') call assert_exception('Vim(function):E126: Missing :endfunction')
endtry endtry
@@ -1296,14 +1296,14 @@ func Test_script_lines()
\ '.', \ '.',
\ ]) \ ])
catch catch
call assert_false(1, "Can't define function") call assert_report("Can't define function")
endtry endtry
try try
call DefineFunction('T_Insert', [ call DefineFunction('T_Insert', [
\ 'insert', \ 'insert',
\ 'abc', \ 'abc',
\ ]) \ ])
call assert_false(1, "Shouldn't be able to define function") call assert_report("Shouldn't be able to define function")
catch catch
call assert_exception('Vim(function):E126: Missing :endfunction') call assert_exception('Vim(function):E126: Missing :endfunction')
endtry endtry

View File

@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
478,
/**/ /**/
477, 477,
/**/ /**/