Skip to content

Commit 7177da9

Browse files
committed
patch 8.2.1199: not all assert functions are fully tested
Problem: Not all assert functions are fully tested. Solution: Test more assert functions.
1 parent a4b4426 commit 7177da9

3 files changed

Lines changed: 54 additions & 5 deletions

File tree

src/testdir/test_assert.vim

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func Test_assert_equal()
4848
call assert_equal('XxxxxxxxxxxxxxxxxxxxxxX', 'XyyyyyyyyyyyyyyyyyyyyyyyyyX')
4949
call assert_match("Expected 'X\\\\\\[x occurs 21 times]X' but got 'X\\\\\\[y occurs 25 times]X'", v:errors[0])
5050
call remove(v:errors, 0)
51+
52+
" special characters are escaped
53+
call assert_equal("\b\e\f\n\t\r\\\x01\x7f", 'x')
54+
call assert_match('Expected ''\\b\\e\\f\\n\\t\\r\\\\\\x01\\x7f'' but got ''x''', v:errors[0])
55+
call remove(v:errors, 0)
5156
endfunc
5257

5358
func Test_assert_equal_dict()
@@ -143,6 +148,14 @@ func Test_assert_exception()
143148
call assert_equal(0, assert_exception('E492:'))
144149
endtry
145150

151+
try
152+
nocommand
153+
catch
154+
call assert_equal(1, assert_exception('E12345:'))
155+
endtry
156+
call assert_match("Expected 'E12345:' but got 'Vim:E492: ", v:errors[0])
157+
call remove(v:errors, 0)
158+
146159
try
147160
nocommand
148161
catch
@@ -153,6 +166,10 @@ func Test_assert_exception()
153166
call assert_equal(0, assert_exception('E730:'))
154167
endtry
155168
endtry
169+
170+
call assert_equal(1, assert_exception('E492:'))
171+
call assert_match('v:exception is not set', v:errors[0])
172+
call remove(v:errors, 0)
156173
endfunc
157174

158175
func Test_wrong_error_type()
@@ -216,13 +233,42 @@ func Test_assert_fail_fails()
216233
call assert_match("stupid: Expected 'E9876' but got 'E492:", v:errors[0])
217234
call remove(v:errors, 0)
218235

236+
call assert_equal(1, assert_fails('xxx', ['E9876']))
237+
call assert_match("Expected \\['E9876'\\] but got 'E492:", v:errors[0])
238+
call remove(v:errors, 0)
239+
240+
call assert_equal(1, assert_fails('xxx', ['E492:', 'E9876']))
241+
call assert_match("Expected \\['E492:', 'E9876'\\] but got 'E492:", v:errors[0])
242+
call remove(v:errors, 0)
243+
219244
call assert_equal(1, assert_fails('echo', '', 'echo command'))
220245
call assert_match("command did not fail: echo command", v:errors[0])
221246
call remove(v:errors, 0)
222247

223248
call assert_equal(1, 'echo'->assert_fails('', 'echo command'))
224249
call assert_match("command did not fail: echo command", v:errors[0])
225250
call remove(v:errors, 0)
251+
252+
try
253+
call assert_equal(1, assert_fails('xxx', []))
254+
catch
255+
let exp = v:exception
256+
endtry
257+
call assert_match("E856: assert_fails() second argument", exp)
258+
259+
try
260+
call assert_equal(1, assert_fails('xxx', ['1', '2', '3']))
261+
catch
262+
let exp = v:exception
263+
endtry
264+
call assert_match("E856: assert_fails() second argument", exp)
265+
266+
try
267+
call assert_equal(1, assert_fails('xxx', #{one: 1}))
268+
catch
269+
let exp = v:exception
270+
endtry
271+
call assert_match("E856: assert_fails() second argument", exp)
226272
endfunc
227273

228274
func Test_assert_fails_in_try_block()

src/testing.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ga_concat_esc(garray_T *gap, char_u *p, int clen)
6666
case CAR: ga_concat(gap, (char_u *)"\\r"); break;
6767
case '\\': ga_concat(gap, (char_u *)"\\\\"); break;
6868
default:
69-
if (*p < ' ')
69+
if (*p < ' ' || *p == 0x7f)
7070
{
7171
vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p);
7272
ga_concat(gap, buf);
@@ -270,12 +270,12 @@ assert_match_common(typval_T *argvars, assert_type_T atype)
270270
garray_T ga;
271271
char_u buf1[NUMBUFLEN];
272272
char_u buf2[NUMBUFLEN];
273+
int called_emsg_before = called_emsg;
273274
char_u *pat = tv_get_string_buf_chk(&argvars[0], buf1);
274275
char_u *text = tv_get_string_buf_chk(&argvars[1], buf2);
275276

276-
if (pat == NULL || text == NULL)
277-
emsg(_(e_invarg));
278-
else if (pattern_match(pat, text, FALSE) != (atype == ASSERT_MATCH))
277+
if (called_emsg == called_emsg_before
278+
&& pattern_match(pat, text, FALSE) != (atype == ASSERT_MATCH))
279279
{
280280
prepare_assert_error(&ga);
281281
fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1],
@@ -379,6 +379,7 @@ assert_equalfile(typval_T *argvars)
379379
{
380380
char_u buf1[NUMBUFLEN];
381381
char_u buf2[NUMBUFLEN];
382+
int called_emsg_before = called_emsg;
382383
char_u *fname1 = tv_get_string_buf_chk(&argvars[0], buf1);
383384
char_u *fname2 = tv_get_string_buf_chk(&argvars[1], buf2);
384385
garray_T ga;
@@ -388,7 +389,7 @@ assert_equalfile(typval_T *argvars)
388389
char line2[200];
389390
int lineidx = 0;
390391

391-
if (fname1 == NULL || fname2 == NULL)
392+
if (called_emsg > called_emsg_before)
392393
return 0;
393394

394395
IObuff[0] = NUL;

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1199,
757759
/**/
758760
1198,
759761
/**/

0 commit comments

Comments
 (0)