Skip to content

Commit 8bea171

Browse files
committed
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.
1 parent cf65d88 commit 8bea171

5 files changed

Lines changed: 31 additions & 12 deletions

File tree

src/indent.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,8 +1781,10 @@ ex_retab(exarg_T *eap)
17811781
if (vcol >= MAXCOL)
17821782
{
17831783
emsg(_(e_resulting_text_too_long));
1784-
// set got_int to break out of any loop
1785-
got_int = TRUE;
1784+
// when not inside a try/catch set got_int to break out of any
1785+
// loop
1786+
if (trylevel == 0)
1787+
got_int = TRUE;
17861788
break;
17871789
}
17881790
if (has_mbyte)

src/testdir/runtest.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func RunTheTest(test)
201201
endtry
202202
endif
203203

204+
au VimLeavePre * call EarlyExit(g:testfunc)
204205
if a:test =~ 'Test_nocatch_'
205206
" Function handles errors itself. This avoids skipping commands after the
206207
" error.
@@ -212,16 +213,15 @@ func RunTheTest(test)
212213
endif
213214
else
214215
try
215-
au VimLeavePre * call EarlyExit(g:testfunc)
216216
exe 'call ' . a:test
217-
au! VimLeavePre
218217
catch /^\cskipped/
219218
call add(s:messages, ' Skipped')
220219
call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', ''))
221220
catch
222221
call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint)
223222
endtry
224223
endif
224+
au! VimLeavePre
225225

226226
" In case 'insertmode' was set and something went wrong, make sure it is
227227
" reset to avoid trouble with anything else.

src/testdir/test_retab.vim

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,34 @@ func Test_retab_error()
8282
call assert_fails('ret 80000000000000000000', 'E475:')
8383
endfunc
8484

85-
" FIXME: the try/catch does not catch the interrupt
86-
func FIXME_Test_retab_endless()
85+
func RetabLoop()
86+
while 1
87+
set ts=4000
88+
retab 4
89+
endwhile
90+
endfunc
91+
92+
func Test_retab_endless()
93+
" inside try/catch we catch the error message
8794
new
8895
call setline(1, "\t0\t")
8996
let caught = 'no'
9097
try
91-
while 1
92-
set ts=4000
93-
retab 4
94-
endwhile
95-
catch
98+
call RetabLoop()
99+
catch /E1240:/
96100
let caught = v:exception
97101
endtry
98-
call assert_notequal('no', caught)
102+
call assert_match('E1240:', caught)
103+
bwipe!
104+
set tabstop&
105+
endfunc
106+
107+
func Test_nocatch_retab_endless()
108+
" not inside try/catch an interrupt is generated to get out of loops
109+
new
110+
call setline(1, "\t0\t")
111+
call assert_fails('call RetabLoop()', ['E1240:', 'Interrupted'])
112+
99113
bwipe!
100114
set tabstop&
101115
endfunc

src/testing.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
742742
suppress_errthrow = FALSE;
743743
in_assert_fails = FALSE;
744744
did_emsg = FALSE;
745+
got_int = FALSE;
745746
msg_col = 0;
746747
need_wait_return = FALSE;
747748
emsg_on_display = FALSE;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
5102,
737739
/**/
738740
5101,
739741
/**/

0 commit comments

Comments
 (0)