summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-06-04 16:52:40 +0200
committerBram Moolenaar <Bram@vim.org>2020-06-04 16:52:40 +0200
commit30cc44a97f0ba1349e1a522dab22b11f47888183 (patch)
tree6d8731ca73501ec931eb83708dc9032a97220797
parent6b0e528368415476bfc3a8414c9c70f9852b1517 (diff)
downloadvim-git-30cc44a97f0ba1349e1a522dab22b11f47888183.tar.gz
patch 8.2.0899: assert_equalfile() does not give a hint about the differencev8.2.0899
Problem: Assert_equalfile() does not give a hint about the difference. Solution: Display the last seen text.
-rw-r--r--src/testdir/test_assert.vim11
-rw-r--r--src/testing.c47
-rw-r--r--src/version.c2
3 files changed, 52 insertions, 8 deletions
diff --git a/src/testdir/test_assert.vim b/src/testdir/test_assert.vim
index 5037d87b8..2147e3de4 100644
--- a/src/testdir/test_assert.vim
+++ b/src/testdir/test_assert.vim
@@ -78,11 +78,18 @@ func Test_assert_equalfile()
call writefile(['1234X89'], 'Xone')
call writefile(['1234Y89'], 'Xtwo')
call assert_equal(1, assert_equalfile('Xone', 'Xtwo'))
- call assert_match("difference at byte 4", v:errors[0])
+ call assert_match('difference at byte 4, line 1 after "1234X" vs "1234Y"', v:errors[0])
+ call remove(v:errors, 0)
+
+ call writefile([repeat('x', 234) .. 'X'], 'Xone')
+ call writefile([repeat('x', 234) .. 'Y'], 'Xtwo')
+ call assert_equal(1, assert_equalfile('Xone', 'Xtwo'))
+ let xes = repeat('x', 134)
+ call assert_match('difference at byte 234, line 1 after "' .. xes .. 'X" vs "' .. xes .. 'Y"', v:errors[0])
call remove(v:errors, 0)
call assert_equal(1, assert_equalfile('Xone', 'Xtwo', 'a message'))
- call assert_match("a message: difference at byte 4", v:errors[0])
+ call assert_match("a message: difference at byte 234, line 1 after", v:errors[0])
call remove(v:errors, 0)
call delete('Xone')
diff --git a/src/testing.c b/src/testing.c
index fa8cc4241..0eee72a83 100644
--- a/src/testing.c
+++ b/src/testing.c
@@ -309,6 +309,9 @@ assert_equalfile(typval_T *argvars)
garray_T ga;
FILE *fd1;
FILE *fd2;
+ char line1[200];
+ char line2[200];
+ int lineidx = 0;
if (fname1 == NULL || fname2 == NULL)
return 0;
@@ -329,8 +332,9 @@ assert_equalfile(typval_T *argvars)
}
else
{
- int c1, c2;
- long count = 0;
+ int c1, c2;
+ long count = 0;
+ long linecount = 1;
for (;;)
{
@@ -347,13 +351,31 @@ assert_equalfile(typval_T *argvars)
STRCPY(IObuff, "second file is shorter");
break;
}
- else if (c1 != c2)
+ else
{
- vim_snprintf((char *)IObuff, IOSIZE,
- "difference at byte %ld", count);
- break;
+ line1[lineidx] = c1;
+ line2[lineidx] = c2;
+ ++lineidx;
+ if (c1 != c2)
+ {
+ vim_snprintf((char *)IObuff, IOSIZE,
+ "difference at byte %ld, line %ld",
+ count, linecount);
+ break;
+ }
}
++count;
+ if (c1 == NL)
+ {
+ ++linecount;
+ lineidx = 0;
+ }
+ else if (lineidx + 2 == (int)sizeof(line1))
+ {
+ mch_memmove(line1, line1 + 100, lineidx - 100);
+ mch_memmove(line2, line2 + 100, lineidx - 100);
+ lineidx -= 100;
+ }
}
fclose(fd1);
fclose(fd2);
@@ -372,6 +394,19 @@ assert_equalfile(typval_T *argvars)
ga_concat(&ga, (char_u *)": ");
}
ga_concat(&ga, IObuff);
+ if (lineidx > 0)
+ {
+ line1[lineidx] = NUL;
+ line2[lineidx] = NUL;
+ ga_concat(&ga, (char_u *)" after \"");
+ ga_concat(&ga, (char_u *)line1);
+ if (STRCMP(line1, line2) != 0)
+ {
+ ga_concat(&ga, (char_u *)"\" vs \"");
+ ga_concat(&ga, (char_u *)line2);
+ }
+ ga_concat(&ga, (char_u *)"\"");
+ }
assert_error(&ga);
ga_clear(&ga);
return 1;
diff --git a/src/version.c b/src/version.c
index ce8bbf14f..462e772ec 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 899,
+/**/
898,
/**/
897,