Skip to content

Commit e24b5e0

Browse files
yegappanbrammool
authored andcommitted
patch 9.0.0543: insufficient testing for assert and test functions
Problem: Insufficient testing for assert and test functions. Solution: Add a few more tests. (Yegappan Lakshmanan, closes #11190)
1 parent f1d2ddc commit e24b5e0

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

src/testdir/test_assert.vim

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,20 @@ func Test_assert_fail_fails()
268268
endtry
269269
call assert_match("E856: \"assert_fails()\" second argument", exp)
270270

271+
try
272+
call assert_equal(1, assert_fails('xxx', test_null_list()))
273+
catch
274+
let exp = v:exception
275+
endtry
276+
call assert_match("E856: \"assert_fails()\" second argument", exp)
277+
278+
try
279+
call assert_equal(1, assert_fails('xxx', []))
280+
catch
281+
let exp = v:exception
282+
endtry
283+
call assert_match("E856: \"assert_fails()\" second argument", exp)
284+
271285
try
272286
call assert_equal(1, assert_fails('xxx', #{one: 1}))
273287
catch
@@ -307,6 +321,15 @@ func Test_assert_fail_fails()
307321
call assert_equal(1, assert_fails('c0', ['', '\(.\)\1']))
308322
call assert_match("Expected '\\\\\\\\(.\\\\\\\\)\\\\\\\\1' but got 'E939: Positive count required: c0': c0", v:errors[0])
309323
call remove(v:errors, 0)
324+
325+
" Test for matching the line number and the script name in an error message
326+
call writefile(['', 'call Xnonexisting()'], 'Xassertfails.vim', 'D')
327+
call assert_fails('source Xassertfails.vim', 'E117:', '', 10)
328+
call assert_match("Expected 10 but got 2", v:errors[0])
329+
call remove(v:errors, 0)
330+
call assert_fails('source Xassertfails.vim', 'E117:', '', 2, 'Xabc')
331+
call assert_match("Expected 'Xabc' but got .*Xassertfails.vim", v:errors[0])
332+
call remove(v:errors, 0)
310333
endfunc
311334

312335
func Test_assert_fails_in_try_block()
@@ -331,6 +354,12 @@ func Test_assert_beeps()
331354
bwipe
332355
endfunc
333356

357+
func Test_assert_nobeep()
358+
call assert_equal(1, assert_nobeep('normal! cr'))
359+
call assert_match("command did beep: normal! cr", v:errors[0])
360+
call remove(v:errors, 0)
361+
endfunc
362+
334363
func Test_assert_inrange()
335364
call assert_equal(0, assert_inrange(7, 7, 7))
336365
call assert_equal(0, assert_inrange(5, 7, 5))
@@ -365,6 +394,16 @@ func Test_assert_inrange()
365394
call assert_equal(1, assert_inrange(5, 7, 8.0))
366395
call assert_match("Expected range 5.0 - 7.0, but got 8.0", v:errors[0])
367396
call remove(v:errors, 0)
397+
398+
" Use a custom message
399+
call assert_equal(1, assert_inrange(5, 7, 8.0, "Higher"))
400+
call assert_match("Higher", v:errors[0])
401+
call remove(v:errors, 0)
402+
403+
" Invalid arguments
404+
call assert_fails("call assert_inrange([], 2, 3)", 'E1219:')
405+
call assert_fails("call assert_inrange(1, [], 3)", 'E1219:')
406+
call assert_fails("call assert_inrange(1, 2, [])", 'E1219:')
368407
endfunc
369408

370409
func Test_assert_with_msg()
@@ -407,6 +446,19 @@ func Test_user_is_happy()
407446
sleep 300m
408447
endfunc
409448

449+
" Test for the test_alloc_fail() function
450+
func Test_test_alloc_fail()
451+
call assert_fails('call test_alloc_fail([], 1, 1)', 'E474:')
452+
call assert_fails('call test_alloc_fail(10, [], 1)', 'E474:')
453+
call assert_fails('call test_alloc_fail(10, 1, [])', 'E474:')
454+
call assert_fails('call test_alloc_fail(999999, 1, 1)', 'E474:')
455+
endfunc
456+
457+
" Test for the test_option_not_set() function
458+
func Test_test_option_not_set()
459+
call assert_fails('call test_option_not_set("Xinvalidopt")', 'E475:')
460+
endfunc
461+
410462
" Must be last.
411463
func Test_zz_quit_detected()
412464
" Verify that if a test function ends Vim the test script detects this.

src/testdir/test_options.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ func Test_shortmess_F2()
815815
call assert_match('file2', execute('bn', ''))
816816
bwipe
817817
bwipe
818+
call assert_fails('call test_getvalue("abc")', 'E475:')
818819
endfunc
819820

820821
func Test_local_scrolloff()

src/testdir/test_vimscript.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7216,6 +7216,14 @@ func Test_refcount()
72167216
call d.Func()
72177217
unlet d
72187218
delfunc DictFunc
7219+
7220+
call assert_equal(-1, test_refcount(test_null_job()))
7221+
call assert_equal(-1, test_refcount(test_null_channel()))
7222+
call assert_equal(-1, test_refcount(test_null_function()))
7223+
call assert_equal(-1, test_refcount(test_null_partial()))
7224+
call assert_equal(-1, test_refcount(test_null_blob()))
7225+
call assert_equal(-1, test_refcount(test_null_list()))
7226+
call assert_equal(-1, test_refcount(test_null_dict()))
72197227
endfunc
72207228

72217229
" Test for missing :endif, :endfor, :endwhile and :endtry {{{1

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ static char *(features[]) =
699699

700700
static int included_patches[] =
701701
{ /* Add new patch number below this line */
702+
/**/
703+
543,
702704
/**/
703705
542,
704706
/**/

0 commit comments

Comments
 (0)