Mercurial > vim
comparison src/testdir/test_assert.vim @ 30415:56e38195570b v9.0.0543
patch 9.0.0543: insufficient testing for assert and test functions
Commit: https://github.com/vim/vim/commit/e24b5e0b0f5ab015215ef2761baa98ccb1ba8606
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Sep 22 13:44:00 2022 +0100
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 https://github.com/vim/vim/issues/11190)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 22 Sep 2022 14:45:02 +0200 |
parents | 029c59bf78f1 |
children | 9a5e540510cf |
comparison
equal
deleted
inserted
replaced
30414:33e6eb790432 | 30415:56e38195570b |
---|---|
267 let exp = v:exception | 267 let exp = v:exception |
268 endtry | 268 endtry |
269 call assert_match("E856: \"assert_fails()\" second argument", exp) | 269 call assert_match("E856: \"assert_fails()\" second argument", exp) |
270 | 270 |
271 try | 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 | |
285 try | |
272 call assert_equal(1, assert_fails('xxx', #{one: 1})) | 286 call assert_equal(1, assert_fails('xxx', #{one: 1})) |
273 catch | 287 catch |
274 let exp = v:exception | 288 let exp = v:exception |
275 endtry | 289 endtry |
276 call assert_match("E1222: String or List required for argument 2", exp) | 290 call assert_match("E1222: String or List required for argument 2", exp) |
304 endtry | 318 endtry |
305 call assert_match("E1174: String required for argument 5", exp) | 319 call assert_match("E1174: String required for argument 5", exp) |
306 | 320 |
307 call assert_equal(1, assert_fails('c0', ['', '\(.\)\1'])) | 321 call assert_equal(1, assert_fails('c0', ['', '\(.\)\1'])) |
308 call assert_match("Expected '\\\\\\\\(.\\\\\\\\)\\\\\\\\1' but got 'E939: Positive count required: c0': c0", v:errors[0]) | 322 call assert_match("Expected '\\\\\\\\(.\\\\\\\\)\\\\\\\\1' but got 'E939: Positive count required: c0': c0", v:errors[0]) |
323 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]) | |
309 call remove(v:errors, 0) | 332 call remove(v:errors, 0) |
310 endfunc | 333 endfunc |
311 | 334 |
312 func Test_assert_fails_in_try_block() | 335 func Test_assert_fails_in_try_block() |
313 try | 336 try |
327 call assert_equal(1, 'normal 0'->assert_beeps()) | 350 call assert_equal(1, 'normal 0'->assert_beeps()) |
328 call assert_match("command did not beep: normal 0", v:errors[0]) | 351 call assert_match("command did not beep: normal 0", v:errors[0]) |
329 call remove(v:errors, 0) | 352 call remove(v:errors, 0) |
330 | 353 |
331 bwipe | 354 bwipe |
355 endfunc | |
356 | |
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) | |
332 endfunc | 361 endfunc |
333 | 362 |
334 func Test_assert_inrange() | 363 func Test_assert_inrange() |
335 call assert_equal(0, assert_inrange(7, 7, 7)) | 364 call assert_equal(0, assert_inrange(7, 7, 7)) |
336 call assert_equal(0, assert_inrange(5, 7, 5)) | 365 call assert_equal(0, assert_inrange(5, 7, 5)) |
363 call assert_match("Expected range 5.0 - 7.0, but got 4.0", v:errors[0]) | 392 call assert_match("Expected range 5.0 - 7.0, but got 4.0", v:errors[0]) |
364 call remove(v:errors, 0) | 393 call remove(v:errors, 0) |
365 call assert_equal(1, assert_inrange(5, 7, 8.0)) | 394 call assert_equal(1, assert_inrange(5, 7, 8.0)) |
366 call assert_match("Expected range 5.0 - 7.0, but got 8.0", v:errors[0]) | 395 call assert_match("Expected range 5.0 - 7.0, but got 8.0", v:errors[0]) |
367 call remove(v:errors, 0) | 396 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:') | |
368 endfunc | 407 endfunc |
369 | 408 |
370 func Test_assert_with_msg() | 409 func Test_assert_with_msg() |
371 call assert_equal('foo', 'bar', 'testing') | 410 call assert_equal('foo', 'bar', 'testing') |
372 call assert_match("testing: Expected 'foo' but got 'bar'", v:errors[0]) | 411 call assert_match("testing: Expected 'foo' but got 'bar'", v:errors[0]) |
405 func Test_user_is_happy() | 444 func Test_user_is_happy() |
406 smile | 445 smile |
407 sleep 300m | 446 sleep 300m |
408 endfunc | 447 endfunc |
409 | 448 |
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 | |
410 " Must be last. | 462 " Must be last. |
411 func Test_zz_quit_detected() | 463 func Test_zz_quit_detected() |
412 " Verify that if a test function ends Vim the test script detects this. | 464 " Verify that if a test function ends Vim the test script detects this. |
413 quit | 465 quit |
414 endfunc | 466 endfunc |