Skip to content

Commit 3717540

Browse files
committed
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().
1 parent 4220555 commit 3717540

File tree

12 files changed

+44
-41
lines changed

12 files changed

+44
-41
lines changed

src/testdir/test_assert.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ func Test_assert_notequal()
3636
call remove(v:errors, 0)
3737
endfunc
3838

39+
func Test_assert_report()
40+
call assert_report('something is wrong')
41+
call assert_match('something is wrong', v:errors[0])
42+
call remove(v:errors, 0)
43+
endfunc
44+
3945
func Test_assert_exception()
4046
try
4147
nocommand

src/testdir/test_channel.vim

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ source shared.vim
88

99
let s:python = PythonProg()
1010
if s:python == ''
11-
" Can't run this test.
11+
" Can't run this test without Python.
1212
finish
1313
endif
1414

15+
" Uncomment the next line to see what happens. Output is in
16+
" src/testdir/channellog.
17+
" call ch_logfile('channellog', 'w')
18+
1519
let s:chopt = {}
1620

1721
" Run "testfunc" after sarting the server and stop the server afterwards.
@@ -31,7 +35,7 @@ func Ch_communicate(port)
3135
let handle = ch_open('localhost:' . a:port, s:chopt)
3236
unlet s:chopt.drop
3337
if ch_status(handle) == "fail"
34-
call assert_false(1, "Can't open channel")
38+
call assert_report("Can't open channel")
3539
return
3640
endif
3741
if has('job')
@@ -93,7 +97,7 @@ func Ch_communicate(port)
9397
call ch_sendexpr(handle, 'hello!', {'callback': 'Ch_requestHandler'})
9498
call WaitFor('exists("g:Ch_responseHandle")')
9599
if !exists('g:Ch_responseHandle')
96-
call assert_false(1, 'g:Ch_responseHandle was not set')
100+
call assert_report('g:Ch_responseHandle was not set')
97101
else
98102
call assert_equal(handle, g:Ch_responseHandle)
99103
unlet g:Ch_responseHandle
@@ -104,7 +108,7 @@ func Ch_communicate(port)
104108
call ch_sendexpr(handle, 'hello!', {'callback': function('Ch_requestHandler')})
105109
call WaitFor('exists("g:Ch_responseHandle")')
106110
if !exists('g:Ch_responseHandle')
107-
call assert_false(1, 'g:Ch_responseHandle was not set')
111+
call assert_report('g:Ch_responseHandle was not set')
108112
else
109113
call assert_equal(handle, g:Ch_responseHandle)
110114
unlet g:Ch_responseHandle
@@ -116,7 +120,7 @@ func Ch_communicate(port)
116120
call ch_sendexpr(handle, 'hello!', {'callback': {a, b -> Ch_requestHandler(a, b)}})
117121
call WaitFor('exists("g:Ch_responseHandle")')
118122
if !exists('g:Ch_responseHandle')
119-
call assert_false(1, 'g:Ch_responseHandle was not set')
123+
call assert_report('g:Ch_responseHandle was not set')
120124
else
121125
call assert_equal(handle, g:Ch_responseHandle)
122126
unlet g:Ch_responseHandle
@@ -209,15 +213,15 @@ func Ch_two_channels(port)
209213
let handle = ch_open('localhost:' . a:port, s:chopt)
210214
call assert_equal(v:t_channel, type(handle))
211215
if ch_status(handle) == "fail"
212-
call assert_false(1, "Can't open channel")
216+
call assert_report("Can't open channel")
213217
return
214218
endif
215219

216220
call assert_equal('got it', ch_evalexpr(handle, 'hello!'))
217221

218222
let newhandle = ch_open('localhost:' . a:port, s:chopt)
219223
if ch_status(newhandle) == "fail"
220-
call assert_false(1, "Can't open second channel")
224+
call assert_report("Can't open second channel")
221225
return
222226
endif
223227
call assert_equal('got it', ch_evalexpr(newhandle, 'hello!'))
@@ -238,7 +242,7 @@ endfunc
238242
func Ch_server_crash(port)
239243
let handle = ch_open('localhost:' . a:port, s:chopt)
240244
if ch_status(handle) == "fail"
241-
call assert_false(1, "Can't open channel")
245+
call assert_report("Can't open channel")
242246
return
243247
endif
244248

@@ -263,7 +267,7 @@ endfunc
263267
func Ch_channel_handler(port)
264268
let handle = ch_open('localhost:' . a:port, s:chopt)
265269
if ch_status(handle) == "fail"
266-
call assert_false(1, "Can't open channel")
270+
call assert_report("Can't open channel")
267271
return
268272
endif
269273

@@ -306,7 +310,7 @@ endfunc
306310
func Ch_channel_zero(port)
307311
let handle = ch_open('localhost:' . a:port, s:chopt)
308312
if ch_status(handle) == "fail"
309-
call assert_false(1, "Can't open channel")
313+
call assert_report("Can't open channel")
310314
return
311315
endif
312316

@@ -373,7 +377,7 @@ endfunc
373377
func Ch_raw_one_time_callback(port)
374378
let handle = ch_open('localhost:' . a:port, s:chopt)
375379
if ch_status(handle) == "fail"
376-
call assert_false(1, "Can't open channel")
380+
call assert_report("Can't open channel")
377381
return
378382
endif
379383
call ch_setoptions(handle, {'mode': 'raw'})
@@ -429,7 +433,7 @@ func Test_connect_waittime()
429433
endif
430434
catch
431435
if v:exception !~ 'Connection reset by peer'
432-
call assert_false(1, "Caught exception: " . v:exception)
436+
call assert_report("Caught exception: " . v:exception)
433437
endif
434438
endtry
435439
endfunc
@@ -1343,7 +1347,7 @@ func Ch_open_delay(port)
13431347
let channel = ch_open('localhost:' . a:port, s:chopt)
13441348
unlet s:chopt.waittime
13451349
if ch_status(channel) == "fail"
1346-
call assert_false(1, "Can't open channel")
1350+
call assert_report("Can't open channel")
13471351
return
13481352
endif
13491353
call assert_equal('got it', ch_evalexpr(channel, 'hello!'))
@@ -1365,7 +1369,7 @@ endfunc
13651369
function Ch_test_call(port)
13661370
let handle = ch_open('localhost:' . a:port, s:chopt)
13671371
if ch_status(handle) == "fail"
1368-
call assert_false(1, "Can't open channel")
1372+
call assert_report("Can't open channel")
13691373
return
13701374
endif
13711375

@@ -1463,7 +1467,7 @@ endfunc
14631467
function Ch_test_close_callback(port)
14641468
let handle = ch_open('localhost:' . a:port, s:chopt)
14651469
if ch_status(handle) == "fail"
1466-
call assert_false(1, "Can't open channel")
1470+
call assert_report("Can't open channel")
14671471
return
14681472
endif
14691473
call ch_setoptions(handle, {'close_cb': 'MyCloseCb'})
@@ -1481,7 +1485,7 @@ endfunc
14811485
function Ch_test_close_partial(port)
14821486
let handle = ch_open('localhost:' . a:port, s:chopt)
14831487
if ch_status(handle) == "fail"
1484-
call assert_false(1, "Can't open channel")
1488+
call assert_report("Can't open channel")
14851489
return
14861490
endif
14871491
let g:Ch_d = {}
@@ -1631,7 +1635,7 @@ endfunc
16311635
function Ch_test_close_lambda(port)
16321636
let handle = ch_open('localhost:' . a:port, s:chopt)
16331637
if ch_status(handle) == "fail"
1634-
call assert_false(1, "Can't open channel")
1638+
call assert_report("Can't open channel")
16351639
return
16361640
endif
16371641
let g:Ch_close_ret = ''
@@ -1646,6 +1650,3 @@ func Test_close_lambda()
16461650
call ch_log('Test_close_lambda()')
16471651
call s:run_server('Ch_test_close_lambda')
16481652
endfunc
1649-
1650-
" Uncomment this to see what happens, output is in src/testdir/channellog.
1651-
" call ch_logfile('channellog', 'w')

src/testdir/test_cscope.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Test_cscopeWithCscopeConnections()
2828
cscope add Xcscope.out
2929
set cscopeverbose
3030
catch
31-
call assert_true(0)
31+
call assert_report('exception thrown')
3232
endtry
3333
call assert_fails('cscope add', 'E560')
3434
call assert_fails('cscope add Xcscope.out', 'E568')

src/testdir/test_cursor_func.vim

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
" Tests for cursor().
22

33
func Test_wrong_arguments()
4-
try
5-
call cursor(1. 3)
6-
" not reached
7-
call assert_false(1)
8-
catch
9-
call assert_exception('E474:')
10-
endtry
4+
call assert_fails('call cursor(1. 3)', 'E474:')
115
endfunc
126

137
func Test_move_cursor()

src/testdir/test_expr.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ endfunc
8787
func Test_loop_over_null_list()
8888
let null_list = test_null_list()
8989
for i in null_list
90-
call assert_true(0, 'should not get here')
90+
call assert_report('should not get here')
9191
endfor
9292
endfunc
9393

src/testdir/test_gui.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func Test_set_guifontwide()
505505
" Case 2: guifontset is invalid
506506
try
507507
set guifontset=-*-notexist-*
508-
call assert_false(1, "'set guifontset=-*-notexist-*' should have failed")
508+
call assert_report("'set guifontset=-*-notexist-*' should have failed")
509509
catch
510510
call assert_exception('E598')
511511
endtry

src/testdir/test_menu.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_load_menu()
88
try
99
source $VIMRUNTIME/menu.vim
1010
catch
11-
call assert_false(1, 'error while loading menus: ' . v:exception)
11+
call assert_report('error while loading menus: ' . v:exception)
1212
endtry
1313
call assert_match('browse confirm w', execute(':menu File.Save'))
1414
source $VIMRUNTIME/delmenu.vim

src/testdir/test_perl.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func <SID>catch_peval(expr)
132132
catch
133133
return v:exception
134134
endtry
135-
call assert_true(0, 'no exception for `perleval("'.a:expr.'")`')
135+
call assert_report('no exception for `perleval("'.a:expr.'")`')
136136
return ''
137137
endfunc
138138

src/testdir/test_popup.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ func Test_completion_comment_formatting()
562562
%d
563563
try
564564
call feedkeys("o/*\<cr>\<cr>\<c-x>\<c-u>/\<esc>", 'tx')
565-
call assert_false(1, 'completefunc not set, should have failed')
565+
call assert_report('completefunc not set, should have failed')
566566
catch
567567
call assert_exception('E764:')
568568
endtry

src/testdir/test_viminfo.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,13 @@ func Test_viminfo_file_mark_tabclose()
450450
let lnum = line('.')
451451
while 1
452452
if lnum == line('$')
453-
call assert_false(1, 'mark not found in Xtestfileintab')
453+
call assert_report('mark not found in Xtestfileintab')
454454
break
455455
endif
456456
let lnum += 1
457457
let line = getline(lnum)
458458
if line == ''
459-
call assert_false(1, 'mark not found in Xtestfileintab')
459+
call assert_report('mark not found in Xtestfileintab')
460460
break
461461
endif
462462
if line =~ "^\t\""

0 commit comments

Comments
 (0)