vim-patch:8.2.5102: interrupt not caught in test

Problem:    Interrupt not caught in test.
Solution:   Consider an exception thrown in the current try/catch when got_int
            is set.  Also catch early exit when not using try/catch.

8bea171f15

Cherry-pick test changes from patch 8.2.0557.

bfe13ccc58

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2022-11-30 09:48:10 +08:00
parent f706d24045
commit a7dc48f19d
7 changed files with 42 additions and 25 deletions

View File

@@ -847,8 +847,11 @@ void ex_retab(exarg_T *eap)
vcol += win_chartabsize(curwin, ptr + col, (colnr_T)vcol);
if (vcol >= MAXCOL) {
emsg(_(e_resulting_text_too_long));
// set got_int to break out of any loop
got_int = true;
// when not inside a try/catch set got_int to break out of any
// loop
if (trylevel == 0) {
got_int = true;
}
break;
}
col += utfc_ptr2len(ptr + col);

View File

@@ -171,6 +171,7 @@ func RunTheTest(test)
endtry
endif
au VimLeavePre * call EarlyExit(g:testfunc)
if a:test =~ 'Test_nocatch_'
" Function handles errors itself. This avoids skipping commands after the
" error.
@@ -182,10 +183,7 @@ func RunTheTest(test)
endif
else
try
let s:test = a:test
au VimLeavePre * call EarlyExit(s:test)
exe 'call ' . a:test
au! VimLeavePre
catch /^\cskipped/
call add(s:messages, ' Skipped')
call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', ''))
@@ -193,6 +191,7 @@ func RunTheTest(test)
call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
endtry
endif
au! VimLeavePre
" In case 'insertmode' was set and something went wrong, make sure it is
" reset to avoid trouble with anything else.
@@ -255,11 +254,11 @@ func AfterTheTest(func_name)
if len(v:errors) > 0
if match(s:may_fail_list, '^' .. a:func_name) >= 0
let s:fail_expected += 1
call add(s:errors_expected, 'Found errors in ' . s:test . ':')
call add(s:errors_expected, 'Found errors in ' . g:testfunc . ':')
call extend(s:errors_expected, v:errors)
else
let s:fail += 1
call add(s:errors, 'Found errors in ' . s:test . ':')
call add(s:errors, 'Found errors in ' . g:testfunc . ':')
call extend(s:errors, v:errors)
endif
let v:errors = []
@@ -420,12 +419,12 @@ endif
let s:may_fail_list = []
if $TEST_MAY_FAIL != ''
" Split the list at commas and add () to make it match s:test.
" Split the list at commas and add () to make it match g:testfunc.
let s:may_fail_list = split($TEST_MAY_FAIL, ',')->map({i, v -> v .. '()'})
endif
" Execute the tests in alphabetical order.
for s:test in sort(s:tests)
for g:testfunc in sort(s:tests)
" Silence, please!
set belloff=all
let prev_error = ''
@@ -435,7 +434,7 @@ for s:test in sort(s:tests)
" A test can set g:test_is_flaky to retry running the test.
let g:test_is_flaky = 0
call RunTheTest(s:test)
call RunTheTest(g:testfunc)
" Repeat a flaky test. Give up when:
" - $TEST_NO_RETRY is not empty
@@ -443,10 +442,10 @@ for s:test in sort(s:tests)
" - it fails five times (with a different message)
if len(v:errors) > 0
\ && $TEST_NO_RETRY == ''
\ && (index(s:flaky_tests, s:test) >= 0
\ && (index(s:flaky_tests, g:testfunc) >= 0
\ || g:test_is_flaky)
while 1
call add(s:messages, 'Found errors in ' . s:test . ':')
call add(s:messages, 'Found errors in ' . g:testfunc . ':')
call extend(s:messages, v:errors)
call add(total_errors, 'Run ' . g:run_nr . ':')
@@ -469,7 +468,7 @@ for s:test in sort(s:tests)
let v:errors = []
let g:run_nr += 1
call RunTheTest(s:test)
call RunTheTest(g:testfunc)
if len(v:errors) == 0
" Test passed on rerun.
@@ -478,7 +477,7 @@ for s:test in sort(s:tests)
endwhile
endif
call AfterTheTest(s:test)
call AfterTheTest(g:testfunc)
endfor
call FinishTesting()

View File

@@ -1,7 +1,7 @@
" Test whether glob()/globpath() return correct results with certain escaped
" characters.
function SetUp()
func SetUp()
" consistent sorting of file names
set nofileignorecase
endfunction

View File

@@ -24,7 +24,7 @@ endfunc
" Do all test in a separate window to avoid E211 when we recursively
" delete the Xtopdir directory during cleanup
function SetUp()
func SetUp()
set visualbell
set nocp viminfo+=nviminfo

View File

@@ -1,6 +1,6 @@
" Tests for :hide command/modifier and 'hidden' option
function SetUp()
func SetUp()
let s:save_hidden = &hidden
let s:save_bufhidden = &bufhidden
let s:save_autowrite = &autowrite

View File

@@ -81,20 +81,34 @@ func Test_retab_error()
call assert_fails('ret 80000000000000000000', 'E475:')
endfunc
" FIXME: the try/catch does not catch the interrupt
func FIXME_Test_retab_endless()
func RetabLoop()
while 1
set ts=4000
retab 4
endwhile
endfunc
func Test_retab_endless()
" inside try/catch we catch the error message
new
call setline(1, "\t0\t")
let caught = 'no'
try
while 1
set ts=4000
retab 4
endwhile
catch
call RetabLoop()
catch /E1240:/
let caught = v:exception
endtry
call assert_notequal('no', caught)
call assert_match('E1240:', caught)
bwipe!
set tabstop&
endfunc
func Test_nocatch_retab_endless()
" not inside try/catch an interrupt is generated to get out of loops
new
call setline(1, "\t0\t")
call assert_fails('call RetabLoop()', ['E1240:', 'Interrupted'])
bwipe!
set tabstop&
endfunc

View File

@@ -606,6 +606,7 @@ theend:
suppress_errthrow = false;
in_assert_fails = false;
did_emsg = false;
got_int = false;
msg_col = 0;
no_wait_return--;
need_wait_return = false;