To: vim_dev@googlegroups.com Subject: Patch 8.2.1199 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1199 Problem: Not all assert functions are fully tested. Solution: Test more assert functions. Files: src/testing.c, src/testdir/test_assert.vim *** ../vim-8.2.1198/src/testing.c 2020-07-11 22:14:54.310422225 +0200 --- src/testing.c 2020-07-12 22:47:47.625750459 +0200 *************** *** 66,72 **** case CAR: ga_concat(gap, (char_u *)"\\r"); break; case '\\': ga_concat(gap, (char_u *)"\\\\"); break; default: ! if (*p < ' ') { vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p); ga_concat(gap, buf); --- 66,72 ---- case CAR: ga_concat(gap, (char_u *)"\\r"); break; case '\\': ga_concat(gap, (char_u *)"\\\\"); break; default: ! if (*p < ' ' || *p == 0x7f) { vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p); ga_concat(gap, buf); *************** *** 270,281 **** garray_T ga; char_u buf1[NUMBUFLEN]; char_u buf2[NUMBUFLEN]; char_u *pat = tv_get_string_buf_chk(&argvars[0], buf1); char_u *text = tv_get_string_buf_chk(&argvars[1], buf2); ! if (pat == NULL || text == NULL) ! emsg(_(e_invarg)); ! else if (pattern_match(pat, text, FALSE) != (atype == ASSERT_MATCH)) { prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1], --- 270,281 ---- garray_T ga; char_u buf1[NUMBUFLEN]; char_u buf2[NUMBUFLEN]; + int called_emsg_before = called_emsg; char_u *pat = tv_get_string_buf_chk(&argvars[0], buf1); char_u *text = tv_get_string_buf_chk(&argvars[1], buf2); ! if (called_emsg == called_emsg_before ! && pattern_match(pat, text, FALSE) != (atype == ASSERT_MATCH)) { prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1], *************** *** 379,384 **** --- 379,385 ---- { char_u buf1[NUMBUFLEN]; char_u buf2[NUMBUFLEN]; + int called_emsg_before = called_emsg; char_u *fname1 = tv_get_string_buf_chk(&argvars[0], buf1); char_u *fname2 = tv_get_string_buf_chk(&argvars[1], buf2); garray_T ga; *************** *** 388,394 **** char line2[200]; int lineidx = 0; ! if (fname1 == NULL || fname2 == NULL) return 0; IObuff[0] = NUL; --- 389,395 ---- char line2[200]; int lineidx = 0; ! if (called_emsg > called_emsg_before) return 0; IObuff[0] = NUL; *** ../vim-8.2.1198/src/testdir/test_assert.vim 2020-07-11 22:25:53.403842060 +0200 --- src/testdir/test_assert.vim 2020-07-12 23:05:03.394998543 +0200 *************** *** 48,53 **** --- 48,58 ---- call assert_equal('XxxxxxxxxxxxxxxxxxxxxxX', 'XyyyyyyyyyyyyyyyyyyyyyyyyyX') call assert_match("Expected 'X\\\\\\[x occurs 21 times]X' but got 'X\\\\\\[y occurs 25 times]X'", v:errors[0]) call remove(v:errors, 0) + + " special characters are escaped + call assert_equal("\b\e\f\n\t\r\\\x01\x7f", 'x') + call assert_match('Expected ''\\b\\e\\f\\n\\t\\r\\\\\\x01\\x7f'' but got ''x''', v:errors[0]) + call remove(v:errors, 0) endfunc func Test_assert_equal_dict() *************** *** 146,151 **** --- 151,164 ---- try nocommand catch + call assert_equal(1, assert_exception('E12345:')) + endtry + call assert_match("Expected 'E12345:' but got 'Vim:E492: ", v:errors[0]) + call remove(v:errors, 0) + + try + nocommand + catch try " illegal argument, get NULL for error call assert_equal(1, assert_exception([])) *************** *** 153,158 **** --- 166,175 ---- call assert_equal(0, assert_exception('E730:')) endtry endtry + + call assert_equal(1, assert_exception('E492:')) + call assert_match('v:exception is not set', v:errors[0]) + call remove(v:errors, 0) endfunc func Test_wrong_error_type() *************** *** 216,221 **** --- 233,246 ---- call assert_match("stupid: Expected 'E9876' but got 'E492:", v:errors[0]) call remove(v:errors, 0) + call assert_equal(1, assert_fails('xxx', ['E9876'])) + call assert_match("Expected \\['E9876'\\] but got 'E492:", v:errors[0]) + call remove(v:errors, 0) + + call assert_equal(1, assert_fails('xxx', ['E492:', 'E9876'])) + call assert_match("Expected \\['E492:', 'E9876'\\] but got 'E492:", v:errors[0]) + call remove(v:errors, 0) + call assert_equal(1, assert_fails('echo', '', 'echo command')) call assert_match("command did not fail: echo command", v:errors[0]) call remove(v:errors, 0) *************** *** 223,228 **** --- 248,274 ---- call assert_equal(1, 'echo'->assert_fails('', 'echo command')) call assert_match("command did not fail: echo command", v:errors[0]) call remove(v:errors, 0) + + try + call assert_equal(1, assert_fails('xxx', [])) + catch + let exp = v:exception + endtry + call assert_match("E856: assert_fails() second argument", exp) + + try + call assert_equal(1, assert_fails('xxx', ['1', '2', '3'])) + catch + let exp = v:exception + endtry + call assert_match("E856: assert_fails() second argument", exp) + + try + call assert_equal(1, assert_fails('xxx', #{one: 1})) + catch + let exp = v:exception + endtry + call assert_match("E856: assert_fails() second argument", exp) endfunc func Test_assert_fails_in_try_block() *** ../vim-8.2.1198/src/version.c 2020-07-12 21:38:25.463176446 +0200 --- src/version.c 2020-07-12 23:08:39.738325800 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1199, /**/ -- hundred-and-one symptoms of being an internet addict: 22. You've already visited all the links at Yahoo and you're halfway through Lycos. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///