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); vcol += win_chartabsize(curwin, ptr + col, (colnr_T)vcol);
if (vcol >= MAXCOL) { if (vcol >= MAXCOL) {
emsg(_(e_resulting_text_too_long)); emsg(_(e_resulting_text_too_long));
// set got_int to break out of any loop // when not inside a try/catch set got_int to break out of any
got_int = true; // loop
if (trylevel == 0) {
got_int = true;
}
break; break;
} }
col += utfc_ptr2len(ptr + col); col += utfc_ptr2len(ptr + col);

View File

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

View File

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

View File

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

View File

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

View File

@@ -81,20 +81,34 @@ func Test_retab_error()
call assert_fails('ret 80000000000000000000', 'E475:') call assert_fails('ret 80000000000000000000', 'E475:')
endfunc endfunc
" FIXME: the try/catch does not catch the interrupt func RetabLoop()
func FIXME_Test_retab_endless() while 1
set ts=4000
retab 4
endwhile
endfunc
func Test_retab_endless()
" inside try/catch we catch the error message
new new
call setline(1, "\t0\t") call setline(1, "\t0\t")
let caught = 'no' let caught = 'no'
try try
while 1 call RetabLoop()
set ts=4000 catch /E1240:/
retab 4
endwhile
catch
let caught = v:exception let caught = v:exception
endtry 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! bwipe!
set tabstop& set tabstop&
endfunc endfunc

View File

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