mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 10:26:31 +00:00
vim-patch:8.0.1523: cannot write and read terminal screendumps
Problem: Cannot write and read terminal screendumps.
Solution: Add term_dumpwrite(), term_dumpread() and term_dumpdiff().
Also add assert_equalfile().
d96ff16511
This commit is contained in:
@@ -6961,6 +6961,56 @@ static void assert_equal_common(typval_T *argvars, assert_type_T atype)
|
||||
}
|
||||
}
|
||||
|
||||
static void assert_equalfile(typval_T *argvars)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
char buf1[NUMBUFLEN];
|
||||
char buf2[NUMBUFLEN];
|
||||
const char *const fname1 = tv_get_string_buf_chk(&argvars[0], buf1);
|
||||
const char *const fname2 = tv_get_string_buf_chk(&argvars[1], buf2);
|
||||
garray_T ga;
|
||||
|
||||
if (fname1 == NULL || fname2 == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
IObuff[0] = NUL;
|
||||
FILE *const fd1 = os_fopen(fname1, READBIN);
|
||||
if (fd1 == NULL) {
|
||||
snprintf((char *)IObuff, IOSIZE, (char *)e_notread, fname1);
|
||||
} else {
|
||||
FILE *const fd2 = os_fopen(fname2, READBIN);
|
||||
if (fd2 == NULL) {
|
||||
fclose(fd1);
|
||||
snprintf((char *)IObuff, IOSIZE, (char *)e_notread, fname2);
|
||||
} else {
|
||||
for (int64_t count = 0; ; count++) {
|
||||
const int c1 = fgetc(fd1);
|
||||
const int c2 = fgetc(fd2);
|
||||
if (c1 == EOF) {
|
||||
if (c2 != EOF) {
|
||||
STRCPY(IObuff, "first file is shorter");
|
||||
}
|
||||
break;
|
||||
} else if (c2 == EOF) {
|
||||
STRCPY(IObuff, "second file is shorter");
|
||||
break;
|
||||
} else if (c1 != c2) {
|
||||
snprintf((char *)IObuff, IOSIZE,
|
||||
"difference at byte %" PRId64, count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (IObuff[0] != NUL) {
|
||||
prepare_assert_error(&ga);
|
||||
ga_concat(&ga, IObuff);
|
||||
assert_error(&ga);
|
||||
ga_clear(&ga);
|
||||
}
|
||||
}
|
||||
|
||||
static void f_assert_beeps(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
const char *const cmd = tv_get_string_chk(&argvars[0]);
|
||||
@@ -6988,6 +7038,12 @@ static void f_assert_equal(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
assert_equal_common(argvars, ASSERT_EQUAL);
|
||||
}
|
||||
|
||||
// "assert_equalfile(fname-one, fname-two)" function
|
||||
static void f_assert_equalfile(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
assert_equalfile(argvars);
|
||||
}
|
||||
|
||||
// "assert_notequal(expected, actual[, msg])" function
|
||||
static void f_assert_notequal(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
|
@@ -28,6 +28,7 @@ return {
|
||||
asin={args=1, func="float_op_wrapper", data="&asin"}, -- WJMc
|
||||
assert_beeps={args={1, 2}},
|
||||
assert_equal={args={2, 3}},
|
||||
assert_equalfile={args=2},
|
||||
assert_exception={args={1, 2}},
|
||||
assert_fails={args={1, 2}},
|
||||
assert_false={args={1, 2}},
|
||||
|
@@ -1,5 +1,40 @@
|
||||
" Test that the methods used for testing work.
|
||||
|
||||
func Test_assert_equalfile()
|
||||
call assert_equalfile('abcabc', 'xyzxyz')
|
||||
call assert_match("E485: Can't read file abcabc", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
|
||||
let goodtext = ["one", "two", "three"]
|
||||
call writefile(goodtext, 'Xone')
|
||||
call assert_equalfile('Xone', 'xyzxyz')
|
||||
call assert_match("E485: Can't read file xyzxyz", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
|
||||
call writefile(goodtext, 'Xtwo')
|
||||
call assert_equalfile('Xone', 'Xtwo')
|
||||
|
||||
call writefile([goodtext[0]], 'Xone')
|
||||
call assert_equalfile('Xone', 'Xtwo')
|
||||
call assert_match("first file is shorter", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
|
||||
call writefile(goodtext, 'Xone')
|
||||
call writefile([goodtext[0]], 'Xtwo')
|
||||
call assert_equalfile('Xone', 'Xtwo')
|
||||
call assert_match("second file is shorter", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
|
||||
call writefile(['1234X89'], 'Xone')
|
||||
call writefile(['1234Y89'], 'Xtwo')
|
||||
call assert_equalfile('Xone', 'Xtwo')
|
||||
call assert_match("difference at byte 4", v:errors[0])
|
||||
call remove(v:errors, 0)
|
||||
|
||||
call delete('Xone')
|
||||
call delete('Xtwo')
|
||||
endfunc
|
||||
|
||||
func Test_assert_fails_in_try_block()
|
||||
try
|
||||
call assert_equal(0, assert_fails('throw "error"'))
|
||||
|
Reference in New Issue
Block a user