From 3f75f25f9c077a284aedab09c5813d887a62f464 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 22:40:10 +0800 Subject: vim-patch:8.2.2945: some buffer related code is not tested Problem: Some buffer related code is not tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8320) https://github.com/vim/vim/commit/59b262362f26b3aaea1eeb0078adc33eed59863e Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_excmd.vim | 8 +++ src/nvim/testdir/test_recover.vim | 127 ++++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_swap.vim | 75 ++++++++++++++++++++++ 3 files changed, 210 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 42b1f8ca48..44bed890f5 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -78,6 +78,14 @@ func Test_file_cmd() call assert_fails('3file', 'E474:') call assert_fails('0,0file', 'E474:') call assert_fails('0file abc', 'E474:') + if !has('win32') + " Change the name of the buffer to the same name + new Xfile1 + file Xfile1 + call assert_equal('Xfile1', @%) + call assert_equal('Xfile1', @#) + bw! + endif endfunc " Test for the :drop command diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 9de4ddc546..61d8684033 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -138,4 +138,131 @@ func Test_nocatch_process_still_running() call delete(swname) endfunc +" Test for :recover with multiple swap files +func Test_recover_multiple_swap_files() + CheckUnix + new Xfile1 + call setline(1, ['a', 'b', 'c']) + preserve + let b = readblob('.Xfile1.swp') + call writefile(b, '.Xfile1.swm') + call writefile(b, '.Xfile1.swn') + call writefile(b, '.Xfile1.swo') + %bw! + call feedkeys(":recover Xfile1\3\q", 'xt') + call assert_equal(['a', 'b', 'c'], getline(1, '$')) + + call delete('.Xfile1.swm') + call delete('.Xfile1.swn') + call delete('.Xfile1.swo') +endfunc + +" Test for :recover using an empty swap file +func Test_recover_empty_swap_file() + CheckUnix + call writefile([], '.Xfile1.swp') + let msg = execute('recover Xfile1') + call assert_match('Unable to read block 0 from .Xfile1.swp', msg) + call assert_equal('Xfile1', @%) + bw! + " :recover from an empty buffer + call assert_fails('recover', 'E305:') + call delete('.Xfile1.swp') +endfunc + +" Test for :recover using a corrupted swap file +func Test_recover_corrupted_swap_file() + CheckUnix + " recover using a partial swap file + call writefile(0z1234, '.Xfile1.swp') + call assert_fails('recover Xfile1', 'E295:') + bw! + + " recover using invalid content in the swap file + call writefile([repeat('1', 2*1024)], '.Xfile1.swp') + call assert_fails('recover Xfile1', 'E307:') + call delete('.Xfile1.swp') + + " :recover using a swap file with a corrupted header + edit Xfile1 + preserve + let sn = swapname('') + let b = readblob(sn) + bw! + " clear the B0_MAGIC_LONG field + let b[1008:1011] = 0z00000000 + call writefile(b, sn) + let msg = execute('recover Xfile1') + call assert_match('the file has been damaged', msg) + bw! + call delete(sn) +endfunc + +" Test for :recover using an encrypted swap file +func Test_recover_encrypted_swap_file() + CheckUnix + + " Recover an encrypted file from the swap file without the original file + new Xfile1 + call feedkeys(":X\vim\vim\", 'xt') + call setline(1, ['aaa', 'bbb', 'ccc']) + preserve + let b = readblob('.Xfile1.swp') + call writefile(b, '.Xfile1.swm') + bw! + call feedkeys(":recover Xfile1\vim\\", 'xt') + call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$')) + bw! + call delete('.Xfile1.swm') + + " Recover an encrypted file from the swap file with the original file + new Xfile1 + call feedkeys(":X\vim\vim\", 'xt') + call setline(1, ['aaa', 'bbb', 'ccc']) + update + call setline(1, ['111', '222', '333']) + preserve + let b = readblob('.Xfile1.swp') + call writefile(b, '.Xfile1.swm') + bw! + call feedkeys(":recover Xfile1\vim\\", 'xt') + call assert_equal(['111', '222', '333'], getline(1, '$')) + call assert_true(&modified) + bw! + call delete('.Xfile1.swm') + call delete('Xfile1') +endfunc + +" Test for :recover using a unreadable swap file +func Test_recover_unreadble_swap_file() + CheckUnix + CheckNotRoot + new Xfile1 + let b = readblob('.Xfile1.swp') + call writefile(b, '.Xfile1.swm') + bw! + call setfperm('.Xfile1.swm', '-w-------') + call assert_fails('recover Xfile1', 'E306:') + call delete('.Xfile1.swm') +endfunc + +" Test for using :recover when the original file and the swap file have the +" same contents. +func Test_recover_unmodified_file() + CheckUnix + call writefile(['aaa', 'bbb', 'ccc'], 'Xfile1') + edit Xfile1 + preserve + let b = readblob('.Xfile1.swp') + %bw! + call writefile(b, '.Xfile1.swz') + let msg = execute('recover Xfile1') + call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$')) + call assert_false(&modified) + call assert_match('Buffer contents equals file contents', msg) + bw! + call delete('Xfile1') + call delete('.Xfile1.swz') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 284579b084..10c0fed783 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -501,6 +501,81 @@ func Test_swap_auto_delete() augroup! test_swap_recover_ext endfunc +" Test for renaming a buffer when the swap file is deleted out-of-band +func Test_missing_swap_file() + CheckUnix + new Xfile1 + call delete('.Xfile1.swp') + call assert_fails('file Xfile2', 'E301:') + call assert_equal('Xfile2', bufname()) + call assert_true(bufexists('Xfile1')) + call assert_true(bufexists('Xfile2')) + %bw! +endfunc + +" Test for :preserve command +func Test_preserve() + new Xfile1 + setlocal noswapfile + call assert_fails('preserve', 'E313:') + bw! +endfunc + +" Test for the v:swapchoice variable +func Test_swapchoice() + call writefile(['aaa', 'bbb'], 'Xfile1') + edit Xfile1 + preserve + let swapfname = swapname('') + let b = readblob(swapfname) + bw! + call writefile(b, swapfname) + + autocmd! SwapExists + + " Test for v:swapchoice = 'o' (readonly) + augroup test_swapchoice + autocmd! + autocmd SwapExists * let v:swapchoice = 'o' + augroup END + edit Xfile1 + call assert_true(&readonly) + call assert_equal(['aaa', 'bbb'], getline(1, '$')) + %bw! + call assert_true(filereadable(swapfname)) + + " Test for v:swapchoice = 'a' (abort) + augroup test_swapchoice + autocmd! + autocmd SwapExists * let v:swapchoice = 'a' + augroup END + try + edit Xfile1 + catch /^Vim:Interrupt$/ + endtry + call assert_equal('', @%) + call assert_true(bufexists('Xfile1')) + %bw! + call assert_true(filereadable(swapfname)) + + " Test for v:swapchoice = 'd' (delete) + augroup test_swapchoice + autocmd! + autocmd SwapExists * let v:swapchoice = 'd' + augroup END + edit Xfile1 + call assert_equal('Xfile1', @%) + %bw! + call assert_false(filereadable(swapfname)) + + call delete('Xfile1') + call delete(swapfname) + augroup test_swapchoice + autocmd! + augroup END + augroup! test_swapchoice +endfunc + func Test_no_swap_file() call assert_equal("\nNo swap file", execute('swapname')) endfunc -- cgit From 442a7e89b8de0959c41007f42b1a59cf52b814fe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 22:52:58 +0800 Subject: vim-patch:8.2.2952: recover test fails on big endian systems Problem: Recover test fails on big endian systems. Solution: Disable the failing test on big endian systems. (Yegappan Lakshmanan, closes vim/vim#8335) https://github.com/vim/vim/commit/99285550a9957e2c8669f183557944c6513c4875 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_recover.vim | 42 +++++++++++++++++++++++++++++++++------ src/nvim/testdir/test_swap.vim | 2 +- 2 files changed, 37 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 61d8684033..ce9de8b87d 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -144,7 +144,7 @@ func Test_recover_multiple_swap_files() new Xfile1 call setline(1, ['a', 'b', 'c']) preserve - let b = readblob('.Xfile1.swp') + let b = readblob(swapname('')) call writefile(b, '.Xfile1.swm') call writefile(b, '.Xfile1.swn') call writefile(b, '.Xfile1.swo') @@ -173,6 +173,7 @@ endfunc " Test for :recover using a corrupted swap file func Test_recover_corrupted_swap_file() CheckUnix + " recover using a partial swap file call writefile(0z1234, '.Xfile1.swp') call assert_fails('recover Xfile1', 'E295:') @@ -188,12 +189,41 @@ func Test_recover_corrupted_swap_file() preserve let sn = swapname('') let b = readblob(sn) + let save_b = copy(b) bw! - " clear the B0_MAGIC_LONG field - let b[1008:1011] = 0z00000000 - call writefile(b, sn) - let msg = execute('recover Xfile1') - call assert_match('the file has been damaged', msg) + " Run these tests only on little-endian systems. These tests fail on a + " big-endian system (IBM S390x system). + if b[1008:1011] == 0z33323130 + \ && b[4096:4097] == 0z7470 + \ && b[8192:8193] == 0z6164 + + " clear the B0_MAGIC_LONG field + let b[1008:1011] = 0z00000000 + call writefile(b, sn) + let msg = execute('recover Xfile1') + call assert_match('the file has been damaged', msg) + bw! + + " clear the pointer ID + let b = copy(save_b) + let b[4096:4097] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E310:') + bw! + + " clear the data block ID + let b = copy(save_b) + let b[8192:8193] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + bw! + + " remove the data block + let b = copy(save_b) + call writefile(b[:8191], sn) + call assert_fails('recover Xfile1', 'E312:') + endif + bw! call delete(sn) endfunc diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 10c0fed783..024a3b02bc 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -505,7 +505,7 @@ endfunc func Test_missing_swap_file() CheckUnix new Xfile1 - call delete('.Xfile1.swp') + call delete(swapname('')) call assert_fails('file Xfile2', 'E301:') call assert_equal('Xfile2', bufname()) call assert_true(bufexists('Xfile1')) -- cgit From a8f54a94c11d8ff3da299e54de4cbbcfec1fd4ac Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 22:53:40 +0800 Subject: vim-patch:8.2.2960: swap file recovery not sufficiently tested Problem: Swap file recovery not sufficiently tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8339) https://github.com/vim/vim/commit/8cf02e5cf8fb14a5009f12e7af0a47617a0ce88d Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_recover.vim | 100 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index ce9de8b87d..89f894a4bb 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -151,6 +151,16 @@ func Test_recover_multiple_swap_files() %bw! call feedkeys(":recover Xfile1\3\q", 'xt') call assert_equal(['a', 'b', 'c'], getline(1, '$')) + " try using out-of-range number to select a swap file + bw! + call feedkeys(":recover Xfile1\4\q", 'xt') + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + call feedkeys(":recover Xfile1\0\q", 'xt') + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! call delete('.Xfile1.swm') call delete('.Xfile1.swn') @@ -171,6 +181,8 @@ func Test_recover_empty_swap_file() endfunc " Test for :recover using a corrupted swap file +" Refer to the comments in the memline.c file for the swap file headers +" definition. func Test_recover_corrupted_swap_file() CheckUnix @@ -202,6 +214,18 @@ func Test_recover_corrupted_swap_file() call writefile(b, sn) let msg = execute('recover Xfile1') call assert_match('the file has been damaged', msg) + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + + " reduce the page size + let b = copy(save_b) + let b[12:15] = 0z00010000 + call writefile(b, sn) + let msg = execute('recover Xfile1') + call assert_match('page size is smaller than minimum value', msg) + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) bw! " clear the pointer ID @@ -209,6 +233,26 @@ func Test_recover_corrupted_swap_file() let b[4096:4097] = 0z0000 call writefile(b, sn) call assert_fails('recover Xfile1', 'E310:') + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + + " set the number of pointers in a pointer block to zero + let b = copy(save_b) + let b[4098:4099] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???EMPTY BLOCK'], getline(1, '$')) + bw! + + " set the block number in a pointer entry to a negative number + let b = copy(save_b) + let b[4104:4111] = 0z00000000.00000080 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???LINES MISSING'], getline(1, '$')) bw! " clear the data block ID @@ -216,12 +260,45 @@ func Test_recover_corrupted_swap_file() let b[8192:8193] = 0z0000 call writefile(b, sn) call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???BLOCK MISSING'], getline(1, '$')) + bw! + + " set the number of lines in the data block to zero + let b = copy(save_b) + let b[8208:8211] = 0z00000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['??? from here until ???END lines may have been inserted/deleted', + \ '???END'], getline(1, '$')) + bw! + + " use an invalid text start for the lines in a data block + let b = copy(save_b) + let b[8216:8219] = 0z00000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???'], getline(1, '$')) + bw! + + " use an incorrect text end (db_txt_end) for the data block + let b = copy(save_b) + let b[8204:8207] = 0z80000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['??? from here until ???END lines may be messed up', '', + \ '???END'], getline(1, '$')) bw! " remove the data block let b = copy(save_b) call writefile(b[:8191], sn) call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???MANY LINES MISSING'], getline(1, '$')) endif bw! @@ -295,4 +372,27 @@ func Test_recover_unmodified_file() call delete('.Xfile1.swz') endfunc +" Test for recovering a file when editing a symbolically linked file +func Test_recover_symbolic_link() + CheckUnix + call writefile(['aaa', 'bbb', 'ccc'], 'Xfile1') + silent !ln -s Xfile1 Xfile2 + edit Xfile2 + call assert_equal('.Xfile1.swp', fnamemodify(swapname(''), ':t')) + preserve + let b = readblob('.Xfile1.swp') + %bw! + call writefile([], 'Xfile1') + call writefile(b, '.Xfile1.swp') + silent! recover Xfile2 + call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$')) + call assert_true(&modified) + update + %bw! + call assert_equal(['aaa', 'bbb', 'ccc'], readfile('Xfile1')) + call delete('Xfile1') + call delete('Xfile2') + call delete('.Xfile1.swp') +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From f12a45c45eab75578fa18b1c6395f80b8749f7ef Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 22:57:08 +0800 Subject: vim-patch:8.2.2973: fix for recovery and diff mode not tested Problem: Fix for recovery and diff mode not tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8352) https://github.com/vim/vim/commit/3044324e8dccd470bd854cf7d9457232cc9c220e Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_diffmode.vim | 117 ++++++++++++++++++++++++++++++++ src/nvim/testdir/test_prompt_buffer.vim | 2 + src/nvim/testdir/test_recover.vim | 44 ++++++++++++ 3 files changed, 163 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index 0de5310735..d83cd505a6 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -243,6 +243,36 @@ func Test_diffput_two() bwipe! b endfunc +" Test for :diffget/:diffput with a range that is inside a diff chunk +func Test_diffget_diffput_range() + call setline(1, range(1, 10)) + new + call setline(1, range(11, 20)) + windo diffthis + 3,5diffget + call assert_equal(['13', '14', '15'], getline(3, 5)) + call setline(1, range(1, 10)) + 4,8diffput + wincmd p + call assert_equal(['13', '4', '5', '6', '7', '8', '19'], getline(3, 9)) + %bw! +endfunc + +" Test for :diffget/:diffput with an empty buffer and a non-empty buffer +func Test_diffget_diffput_empty_buffer() + %d _ + new + call setline(1, 'one') + windo diffthis + diffget + call assert_equal(['one'], getline(1, '$')) + %d _ + diffput + wincmd p + call assert_equal([''], getline(1, '$')) + %bw! +endfunc + " :diffput and :diffget completes names of buffers which " are in diff mode and which are different then current buffer. " No completion when the current window is not in diff mode. @@ -645,7 +675,11 @@ func Test_diffexpr() call assert_equal(normattr, screenattr(1, 1)) call assert_equal(normattr, screenattr(2, 1)) call assert_notequal(normattr, screenattr(3, 1)) + diffoff! + " Try using an non-existing function for 'diffexpr'. + set diffexpr=NewDiffFunc() + call assert_fails('windo diffthis', ['E117:', 'E97:']) diffoff! %bwipe! set diffexpr& diffopt& @@ -1316,6 +1350,89 @@ func Test_diff_filler_cursorcolumn() call delete('Xtest_diff_cuc') endfunc +" Test for adding/removing lines inside diff chunks, between diff chunks +" and before diff chunks +func Test_diff_modify_chunks() + enew! + let w2_id = win_getid() + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + new + let w1_id = win_getid() + call setline(1, ['a', '2', '3', 'd', 'e', 'f', '7', '8', 'i']) + windo diffthis + + " remove a line between two diff chunks and create a new diff chunk + call win_gotoid(w2_id) + 5d + call win_gotoid(w1_id) + call diff_hlID(5, 1)->synIDattr('name')->assert_equal('DiffAdd') + + " add a line between two diff chunks + call win_gotoid(w2_id) + normal! 4Goe + call win_gotoid(w1_id) + call diff_hlID(4, 1)->synIDattr('name')->assert_equal('') + call diff_hlID(5, 1)->synIDattr('name')->assert_equal('') + + " remove all the lines in a diff chunk. + call win_gotoid(w2_id) + 7,8d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', 'DiffText', 'DiffText', '', '', '', 'DiffAdd', + \ 'DiffAdd', ''], hl) + + " remove lines from one diff chunk to just before the next diff chunk + call win_gotoid(w2_id) + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + 2,6d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', 'DiffText', 'DiffText', 'DiffAdd', 'DiffAdd', + \ 'DiffAdd', 'DiffAdd', 'DiffAdd', ''], hl) + + " remove lines just before the top of a diff chunk + call win_gotoid(w2_id) + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + 5,6d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', 'DiffText', 'DiffText', '', 'DiffText', 'DiffText', + \ 'DiffAdd', 'DiffAdd', ''], hl) + + " remove line after the end of a diff chunk + call win_gotoid(w2_id) + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + 4d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', 'DiffText', 'DiffText', 'DiffAdd', '', '', 'DiffText', + \ 'DiffText', ''], hl) + + " remove lines starting from the end of one diff chunk and ending inside + " another diff chunk + call win_gotoid(w2_id) + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + 4,7d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', 'DiffText', 'DiffText', 'DiffText', 'DiffAdd', + \ 'DiffAdd', 'DiffAdd', 'DiffAdd', ''], hl) + + " removing the only remaining diff chunk should make the files equal + call win_gotoid(w2_id) + call setline(1, ['a', '2', '3', 'x', 'd', 'e', 'f', 'x', '7', '8', 'i']) + 8d + let hl = range(1, 10)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', '', '', 'DiffAdd', '', '', '', '', '', ''], hl) + call win_gotoid(w2_id) + 4d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', '', '', '', '', '', '', '', ''], hl) + + %bw! +endfunc func Test_diff_binary() CheckScreendump diff --git a/src/nvim/testdir/test_prompt_buffer.vim b/src/nvim/testdir/test_prompt_buffer.vim index 9b8a776c95..b8f6c5240c 100644 --- a/src/nvim/testdir/test_prompt_buffer.vim +++ b/src/nvim/testdir/test_prompt_buffer.vim @@ -180,6 +180,8 @@ func Test_prompt_buffer_edit() call assert_beeps('normal! S') call assert_beeps("normal! \") call assert_beeps("normal! \") + call assert_beeps("normal! dp") + call assert_beeps("normal! do") " pressing CTRL-W in the prompt buffer should trigger the window commands call assert_equal(1, winnr()) exe "normal A\\" diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 89f894a4bb..90ee10704c 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -395,4 +395,48 @@ func Test_recover_symbolic_link() call delete('.Xfile1.swp') endfunc +" Test for recovering a file when an autocmd moves the cursor to an invalid +" line. This used to result in an internal error (E315) which is fixed +" by 8.2.2966. +func Test_recover_invalid_cursor_pos() + call writefile([], 'Xfile1') + edit Xfile1 + preserve + let b = readblob('.Xfile1.swp') + bw! + augroup Test + au! + au BufReadPost Xfile1 normal! 3G + augroup END + call writefile(range(1, 3), 'Xfile1') + call writefile(b, '.Xfile1.swp') + try + recover Xfile1 + catch /E308:/ + " this test is for the :E315 internal error. + " ignore the 'E308: Original file may have been changed' error + endtry + redraw! + augroup Test + au! + augroup END + augroup! Test + call delete('Xfile1') + call delete('.Xfile1.swp') +endfunc + +" Test for recovering a buffer without a name +func Test_noname_buffer() + new + call setline(1, ['one', 'two']) + preserve + let sn = swapname('') + let b = readblob(sn) + bw! + call writefile(b, sn) + exe "recover " .. sn + call assert_equal(['one', 'two'], getline(1, '$')) + call delete(sn) +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From fa17dc1e1b893db3320b9b7ae50698c05280df92 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:00:25 +0800 Subject: vim-patch:8.2.2981: recovery test is not run on big-endian systems Problem: Recovery test is not run on big-endian systems. Solution: Make it work on big-endian systems. (James McCoy, closes vim/vim#8368) https://github.com/vim/vim/commit/6654ca702ca64c99965efcad3243ea5f95473252 Co-authored-by: James McCoy --- src/nvim/testdir/test_recover.vim | 193 +++++++++++++++++++------------------- 1 file changed, 96 insertions(+), 97 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 90ee10704c..10a9e7b4f3 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -203,103 +203,102 @@ func Test_recover_corrupted_swap_file() let b = readblob(sn) let save_b = copy(b) bw! - " Run these tests only on little-endian systems. These tests fail on a - " big-endian system (IBM S390x system). - if b[1008:1011] == 0z33323130 - \ && b[4096:4097] == 0z7470 - \ && b[8192:8193] == 0z6164 - - " clear the B0_MAGIC_LONG field - let b[1008:1011] = 0z00000000 - call writefile(b, sn) - let msg = execute('recover Xfile1') - call assert_match('the file has been damaged', msg) - call assert_equal('Xfile1', @%) - call assert_equal([''], getline(1, '$')) - bw! - - " reduce the page size - let b = copy(save_b) - let b[12:15] = 0z00010000 - call writefile(b, sn) - let msg = execute('recover Xfile1') - call assert_match('page size is smaller than minimum value', msg) - call assert_equal('Xfile1', @%) - call assert_equal([''], getline(1, '$')) - bw! - - " clear the pointer ID - let b = copy(save_b) - let b[4096:4097] = 0z0000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E310:') - call assert_equal('Xfile1', @%) - call assert_equal([''], getline(1, '$')) - bw! - - " set the number of pointers in a pointer block to zero - let b = copy(save_b) - let b[4098:4099] = 0z0000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['???EMPTY BLOCK'], getline(1, '$')) - bw! - - " set the block number in a pointer entry to a negative number - let b = copy(save_b) - let b[4104:4111] = 0z00000000.00000080 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['???LINES MISSING'], getline(1, '$')) - bw! - - " clear the data block ID - let b = copy(save_b) - let b[8192:8193] = 0z0000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['???BLOCK MISSING'], getline(1, '$')) - bw! - - " set the number of lines in the data block to zero - let b = copy(save_b) - let b[8208:8211] = 0z00000000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['??? from here until ???END lines may have been inserted/deleted', - \ '???END'], getline(1, '$')) - bw! - - " use an invalid text start for the lines in a data block - let b = copy(save_b) - let b[8216:8219] = 0z00000000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['???'], getline(1, '$')) - bw! - - " use an incorrect text end (db_txt_end) for the data block - let b = copy(save_b) - let b[8204:8207] = 0z80000000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['??? from here until ???END lines may be messed up', '', - \ '???END'], getline(1, '$')) - bw! - - " remove the data block - let b = copy(save_b) - call writefile(b[:8191], sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['???MANY LINES MISSING'], getline(1, '$')) - endif + + " Not all fields are written in a system-independent manner. Detect whether + " the test is running on a little or big-endian system, so the correct + " corruption values can be set. + let little_endian = b[1008:1015] == 0z33323130.00000000 + + " clear the B0_MAGIC_LONG field + let b[1008:1015] = 0z0000000000000000 + call writefile(b, sn) + let msg = execute('recover Xfile1') + call assert_match('the file has been damaged', msg) + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + + " reduce the page size + let b = copy(save_b) + let b[12:15] = 0z00010000 + call writefile(b, sn) + let msg = execute('recover Xfile1') + call assert_match('page size is smaller than minimum value', msg) + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + + " clear the pointer ID + let b = copy(save_b) + let b[4096:4097] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E310:') + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + + " set the number of pointers in a pointer block to zero + let b = copy(save_b) + let b[4098:4099] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???EMPTY BLOCK'], getline(1, '$')) + bw! + + " set the block number in a pointer entry to a negative number + let b = copy(save_b) + let b[4104:4111] = little_endian ? 0z00000000.00000080 : 0z80000000.00000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???LINES MISSING'], getline(1, '$')) + bw! + + " clear the data block ID + let b = copy(save_b) + let b[8192:8193] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???BLOCK MISSING'], getline(1, '$')) + bw! + + " set the number of lines in the data block to zero + let b = copy(save_b) + let b[8208:8215] = 0z00000000.00000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['??? from here until ???END lines may have been inserted/deleted', + \ '???END'], getline(1, '$')) + bw! + + " use an invalid text start for the lines in a data block + let b = copy(save_b) + let b[8216:8219] = 0z00000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???'], getline(1, '$')) + bw! + + " use an incorrect text end (db_txt_end) for the data block + let b = copy(save_b) + let b[8204:8207] = little_endian ? 0z80000000 : 0z00000080 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['??? from here until ???END lines may be messed up', '', + \ '???END'], getline(1, '$')) + bw! + + " remove the data block + let b = copy(save_b) + call writefile(b[:8191], sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???MANY LINES MISSING'], getline(1, '$')) bw! call delete(sn) -- cgit From c1c2c7b3163490b5e4374ee370616ea2581d4fe1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:00:50 +0800 Subject: vim-patch:8.2.3080: recover test fails on 32bit systems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Recover test fails on 32bit systems. (Ondřej Súkup) Solution: Detect 32/64 bit systems. (Yegappan Lakshmanan, closes vim/vim#8485, closes vim/vim#8479) https://github.com/vim/vim/commit/576cb75ceb38ed077938d4a1c1265095050f6105 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_recover.vim | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 10a9e7b4f3..137c73a194 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -207,10 +207,16 @@ func Test_recover_corrupted_swap_file() " Not all fields are written in a system-independent manner. Detect whether " the test is running on a little or big-endian system, so the correct " corruption values can be set. - let little_endian = b[1008:1015] == 0z33323130.00000000 + let little_endian = b[1008:1011] == 0z33323130 + " The swap file header fields can be either 32-bit or 64-bit. + let system_64bit = b[1012:1015] == 0z00000000 " clear the B0_MAGIC_LONG field - let b[1008:1015] = 0z0000000000000000 + if system_64bit + let b[1008:1015] = 0z00000000.00000000 + else + let b[1008:1011] = 0z00000000 + endif call writefile(b, sn) let msg = execute('recover Xfile1') call assert_match('the file has been damaged', msg) @@ -248,7 +254,11 @@ func Test_recover_corrupted_swap_file() " set the block number in a pointer entry to a negative number let b = copy(save_b) - let b[4104:4111] = little_endian ? 0z00000000.00000080 : 0z80000000.00000000 + if system_64bit + let b[4104:4111] = little_endian ? 0z00000000.00000080 : 0z80000000.00000000 + else + let b[4104:4107] = little_endian ? 0z00000080 : 0z80000000 + endif call writefile(b, sn) call assert_fails('recover Xfile1', 'E312:') call assert_equal('Xfile1', @%) @@ -266,7 +276,11 @@ func Test_recover_corrupted_swap_file() " set the number of lines in the data block to zero let b = copy(save_b) - let b[8208:8215] = 0z00000000.00000000 + if system_64bit + let b[8208:8215] = 0z00000000.00000000 + else + let b[8208:8211] = 0z00000000 + endif call writefile(b, sn) call assert_fails('recover Xfile1', 'E312:') call assert_equal('Xfile1', @%) @@ -276,7 +290,11 @@ func Test_recover_corrupted_swap_file() " use an invalid text start for the lines in a data block let b = copy(save_b) - let b[8216:8219] = 0z00000000 + if system_64bit + let b[8216:8219] = 0z00000000 + else + let b[8212:8215] = 0z00000000 + endif call writefile(b, sn) call assert_fails('recover Xfile1', 'E312:') call assert_equal('Xfile1', @%) -- cgit From acfc3d54c6fc5b22adab057962c493b059a91fe7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:02:10 +0800 Subject: vim-patch:8.2.3103: swap test may fail on some systems Problem: Swap test may fail on some systems when jobs take longer to exit. Solution: Use different file names. https://github.com/vim/vim/commit/f33cae605064c8bdb908a8069d936f752572cd76 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_swap.vim | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 024a3b02bc..cf46b4c5bd 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -504,18 +504,18 @@ endfunc " Test for renaming a buffer when the swap file is deleted out-of-band func Test_missing_swap_file() CheckUnix - new Xfile1 + new Xfile2 call delete(swapname('')) - call assert_fails('file Xfile2', 'E301:') - call assert_equal('Xfile2', bufname()) - call assert_true(bufexists('Xfile1')) + call assert_fails('file Xfile3', 'E301:') + call assert_equal('Xfile3', bufname()) call assert_true(bufexists('Xfile2')) + call assert_true(bufexists('Xfile3')) %bw! endfunc " Test for :preserve command func Test_preserve() - new Xfile1 + new Xfile4 setlocal noswapfile call assert_fails('preserve', 'E313:') bw! @@ -523,8 +523,8 @@ endfunc " Test for the v:swapchoice variable func Test_swapchoice() - call writefile(['aaa', 'bbb'], 'Xfile1') - edit Xfile1 + call writefile(['aaa', 'bbb'], 'Xfile5') + edit Xfile5 preserve let swapfname = swapname('') let b = readblob(swapfname) @@ -538,7 +538,7 @@ func Test_swapchoice() autocmd! autocmd SwapExists * let v:swapchoice = 'o' augroup END - edit Xfile1 + edit Xfile5 call assert_true(&readonly) call assert_equal(['aaa', 'bbb'], getline(1, '$')) %bw! @@ -550,11 +550,11 @@ func Test_swapchoice() autocmd SwapExists * let v:swapchoice = 'a' augroup END try - edit Xfile1 + edit Xfile5 catch /^Vim:Interrupt$/ endtry call assert_equal('', @%) - call assert_true(bufexists('Xfile1')) + call assert_true(bufexists('Xfile5')) %bw! call assert_true(filereadable(swapfname)) @@ -563,12 +563,12 @@ func Test_swapchoice() autocmd! autocmd SwapExists * let v:swapchoice = 'd' augroup END - edit Xfile1 - call assert_equal('Xfile1', @%) + edit Xfile5 + call assert_equal('Xfile5', @%) %bw! call assert_false(filereadable(swapfname)) - call delete('Xfile1') + call delete('Xfile5') call delete(swapfname) augroup test_swapchoice autocmd! -- cgit From d8fc390bd04a69f43983fc355026a2f216410318 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:02:47 +0800 Subject: vim-patch:8.2.3440: recover test fails if there is an old swap file Problem: Recover test fails if there is an old swap file. Solution: Delete old swap files. https://github.com/vim/vim/commit/f2a8bafa4b815e5b4e50a25c2b3a8a24fbe8aa11 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_recover.vim | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 137c73a194..9d38b0ebea 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -175,6 +175,12 @@ func Test_recover_empty_swap_file() call assert_match('Unable to read block 0 from .Xfile1.swp', msg) call assert_equal('Xfile1', @%) bw! + + " make sure there are no old swap files laying around + for f in glob('.sw?', 0, 1) + call delete(f) + endfor + " :recover from an empty buffer call assert_fails('recover', 'E305:') call delete('.Xfile1.swp') -- cgit From c269b8dcae08221f1752faf1ecc7dae4d7eed40c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:03:10 +0800 Subject: vim-patch:8.2.3498: recover test may fail on some systems Problem: Recover test may fail on some systems. Solution: Adjust the little endian and 64 bit detection. (James McCoy, closes vim/vim#8941) https://github.com/vim/vim/commit/37f341d7236ff8a1e886bbb0f0ba0700ad589373 Co-authored-by: James McCoy --- src/nvim/testdir/test_recover.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 9d38b0ebea..f4710c4357 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -213,9 +213,11 @@ func Test_recover_corrupted_swap_file() " Not all fields are written in a system-independent manner. Detect whether " the test is running on a little or big-endian system, so the correct " corruption values can be set. - let little_endian = b[1008:1011] == 0z33323130 - " The swap file header fields can be either 32-bit or 64-bit. - let system_64bit = b[1012:1015] == 0z00000000 + " The B0_MAGIC_LONG field may be 32-bit or 64-bit, depending on the system, + " even though the value stored is only 32-bits. Therefore, need to check + " both the high and low 32-bits to compute these values. + let little_endian = (b[1008:1011] == 0z33323130) || (b[1012:1015] == 0z33323130) + let system_64bit = little_endian ? (b[1012:1015] == 0z00000000) : (b[1008:1011] == 0z00000000) " clear the B0_MAGIC_LONG field if system_64bit -- cgit From 7139035bfd90698ce7214b507b2f8a7766398a68 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:30:30 +0800 Subject: vim-patch:9.0.0895: file renamed twice in test, missing feature check Problem: File renamed twice in test; missing feature check. Solution: Remove a rename() call. Add check for cryptv feature. (closes vim/vim#11564) https://github.com/vim/vim/commit/780154bf7a07813e474105837c2b5998009d9c71 Co-authored-by: zeertzjq --- src/nvim/testdir/test_recover.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index f4710c4357..92e22687af 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -126,7 +126,6 @@ func Test_nocatch_process_still_running() call test_override("uptime", 0) sleep 1 - call rename('Xswap', swname) call feedkeys('e', 'tL') redir => editOutput edit Xswaptest @@ -332,6 +331,7 @@ endfunc " Test for :recover using an encrypted swap file func Test_recover_encrypted_swap_file() + CheckFeature cryptv CheckUnix " Recover an encrypted file from the swap file without the original file -- cgit From 4b7aafc2f42e3eee44ae430fcb5e643fb23d7b4b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:27:39 +0800 Subject: fix(memline): use long instead of linenr_T for db_line_count --- src/nvim/memline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 955074e1f2..5f21a3dd0e 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -131,7 +131,8 @@ struct data_block { unsigned db_free; // free space available unsigned db_txt_start; // byte where text starts unsigned db_txt_end; // byte just after data block - linenr_T db_line_count; // number of lines in this block + // linenr_T db_line_count; + long db_line_count; // number of lines in this block unsigned db_index[1]; // index for start of line (actually bigger) // followed by empty space up to db_txt_start // followed by the text in the lines until -- cgit