Merge pull request #20946 from zeertzjq/vim-8.2.1106

vim-patch:8.2.{0883,1106,1366,1383,1417}: Vim script tests
This commit is contained in:
zeertzjq 2022-11-05 21:58:18 +08:00 committed by GitHub
commit 19729e2136
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 5018 additions and 5487 deletions

View File

@ -807,6 +807,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
next = messages->next; next = messages->next;
emsg(messages->msg); emsg(messages->msg);
xfree(messages->msg); xfree(messages->msg);
xfree(messages->sfile);
xfree(messages); xfree(messages);
messages = next; messages = next;
} while (messages != NULL); } while (messages != NULL);

View File

@ -364,4 +364,19 @@ func GetMessages()
return msg_list return msg_list
endfunc endfunc
" Run the list of commands in 'cmds' and look for 'errstr' in exception.
" Note that assert_fails() cannot be used in some places and this function
" can be used.
func AssertException(cmds, errstr)
let save_exception = ''
try
for cmd in a:cmds
exe cmd
endfor
catch
let save_exception = v:exception
endtry
call assert_match(a:errstr, save_exception)
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@ -1,48 +1,4 @@
Results of test49.vim: Results of test49.vim:
*** Test 18: OK (67224583)
*** Test 19: OK (69275973)
*** Test 20: OK (1874575085)
*** Test 21: OK (147932225)
*** Test 22: OK (4161)
*** Test 23: OK (49)
*** Test 24: OK (41)
*** Test 27: OK (1996459)
*** Test 28: OK (1996459)
*** Test 29: OK (170428555)
*** Test 30: OK (190905173)
*** Test 31: OK (190905173)
*** Test 34: OK (2146584868)
*** Test 35: OK (2146584868)
*** Test 36: OK (1071644672)
*** Test 37: OK (1071644672)
*** Test 38: OK (357908480)
*** Test 39: OK (357908480)
*** Test 40: OK (357908480)
*** Test 49: OK (179000669)
*** Test 50: OK (363550045)
*** Test 52: OK (1247112011)
*** Test 53: OK (131071)
*** Test 54: OK (2047)
*** Test 55: OK (1023)
*** Test 56: OK (511)
*** Test 57: OK (2147450880)
*** Test 58: OK (624945)
*** Test 59: OK (2038431743)
*** Test 60: OK (311511339)
*** Test 61: OK (374889517)
*** Test 62: OK (286331153)
*** Test 63: OK (236978127)
*** Test 64: OK (1499645335)
*** Test 65: OK (70187)
*** Test 66: OK (5464)
*** Test 67: OK (212514423)
*** Test 68: OK (212514423)
*** Test 76: OK (1610087935)
*** Test 77: OK (1388671)
*** Test 78: OK (134217728)
*** Test 79: OK (70288929)
*** Test 80: OK (17895765)
*** Test 81: OK (387)
*** Test 82: OK (8454401) *** Test 82: OK (8454401)
*** Test 83: OK (2835) *** Test 83: OK (2835)
*** Test 84: OK (934782101) *** Test 84: OK (934782101)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,90 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local exec = helpers.exec
local feed = helpers.feed
local meths = helpers.meths
before_each(clear)
describe('Vim script', function()
-- oldtest: Test_deep_nest()
it('Error when if/for/while/try/function is nested too deep',function()
local screen = Screen.new(80, 24)
screen:attach()
meths.set_option('laststatus', 2)
exec([[
" Deep nesting of if ... endif
func Test1()
let @a = join(repeat(['if v:true'], 51), "\n")
let @a ..= "\n"
let @a ..= join(repeat(['endif'], 51), "\n")
@a
let @a = ''
endfunc
" Deep nesting of for ... endfor
func Test2()
let @a = join(repeat(['for i in [1]'], 51), "\n")
let @a ..= "\n"
let @a ..= join(repeat(['endfor'], 51), "\n")
@a
let @a = ''
endfunc
" Deep nesting of while ... endwhile
func Test3()
let @a = join(repeat(['while v:true'], 51), "\n")
let @a ..= "\n"
let @a ..= join(repeat(['endwhile'], 51), "\n")
@a
let @a = ''
endfunc
" Deep nesting of try ... endtry
func Test4()
let @a = join(repeat(['try'], 51), "\n")
let @a ..= "\necho v:true\n"
let @a ..= join(repeat(['endtry'], 51), "\n")
@a
let @a = ''
endfunc
" Deep nesting of function ... endfunction
func Test5()
let @a = join(repeat(['function X()'], 51), "\n")
let @a ..= "\necho v:true\n"
let @a ..= join(repeat(['endfunction'], 51), "\n")
@a
let @a = ''
endfunc
]])
screen:expect({any = '%[No Name%]'})
feed(':call Test1()<CR>')
screen:expect({any = 'E579: '})
feed('<C-C>')
screen:expect({any = '%[No Name%]'})
feed(':call Test2()<CR>')
screen:expect({any = 'E585: '})
feed('<C-C>')
screen:expect({any = '%[No Name%]'})
feed(':call Test3()<CR>')
screen:expect({any = 'E585: '})
feed('<C-C>')
screen:expect({any = '%[No Name%]'})
feed(':call Test4()<CR>')
screen:expect({any = 'E601: '})
feed('<C-C>')
screen:expect({any = '%[No Name%]'})
feed(':call Test5()<CR>')
screen:expect({any = 'E1058: '})
end)
-- oldtest: Test_typed_script_var()
it('using s: with a typed command', function()
local screen = Screen.new(80, 24)
screen:attach()
feed(":echo get(s:, 'foo', 'x')\n")
screen:expect({any = 'E116: '})
end)
end)

View File

@ -16,7 +16,6 @@ local lfs = require('lfs')
local clear = helpers.clear local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local exec = helpers.exec
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local eval = helpers.eval local eval = helpers.eval
@ -152,79 +151,6 @@ describe('List support code', function()
end) end)
end) end)
-- oldtest: Test_deep_nest()
it('Error when if/for/while/try/function is nested too deep',function()
clear()
local screen = Screen.new(80, 24)
screen:attach()
meths.set_option('laststatus', 2)
exec([[
" Deep nesting of if ... endif
func Test1()
let @a = join(repeat(['if v:true'], 51), "\n")
let @a ..= "\n"
let @a ..= join(repeat(['endif'], 51), "\n")
@a
let @a = ''
endfunc
" Deep nesting of for ... endfor
func Test2()
let @a = join(repeat(['for i in [1]'], 51), "\n")
let @a ..= "\n"
let @a ..= join(repeat(['endfor'], 51), "\n")
@a
let @a = ''
endfunc
" Deep nesting of while ... endwhile
func Test3()
let @a = join(repeat(['while v:true'], 51), "\n")
let @a ..= "\n"
let @a ..= join(repeat(['endwhile'], 51), "\n")
@a
let @a = ''
endfunc
" Deep nesting of try ... endtry
func Test4()
let @a = join(repeat(['try'], 51), "\n")
let @a ..= "\necho v:true\n"
let @a ..= join(repeat(['endtry'], 51), "\n")
@a
let @a = ''
endfunc
" Deep nesting of function ... endfunction
func Test5()
let @a = join(repeat(['function X()'], 51), "\n")
let @a ..= "\necho v:true\n"
let @a ..= join(repeat(['endfunction'], 51), "\n")
@a
let @a = ''
endfunc
]])
screen:expect({any = '%[No Name%]'})
feed(':call Test1()<CR>')
screen:expect({any = 'E579: '})
feed('<C-C>')
screen:expect({any = '%[No Name%]'})
feed(':call Test2()<CR>')
screen:expect({any = 'E585: '})
feed('<C-C>')
screen:expect({any = '%[No Name%]'})
feed(':call Test3()<CR>')
screen:expect({any = 'E585: '})
feed('<C-C>')
screen:expect({any = '%[No Name%]'})
feed(':call Test4()<CR>')
screen:expect({any = 'E601: '})
feed('<C-C>')
screen:expect({any = '%[No Name%]'})
feed(':call Test5()<CR>')
screen:expect({any = 'E1058: '})
end)
describe("uncaught exception", function() describe("uncaught exception", function()
before_each(clear) before_each(clear)
after_each(function() after_each(function()