comparison src/testdir/vim9.vim @ 23247:f2d05fb28e54 v8.2.2169

patch 8.2.2169: Vim9: test leaves file behind Commit: https://github.com/vim/vim/commit/090728ad4d54287c911894ef42bfe92844ce0fa5 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 20 15:43:31 2020 +0100 patch 8.2.2169: Vim9: test leaves file behind Problem: Vim9: test leaves file behind. Solution: Rename script files. (Dominique Pell?, closes https://github.com/vim/vim/issues/7511) Use try/finally.
author Bram Moolenaar <Bram@vim.org>
date Sun, 20 Dec 2020 15:45:05 +0100
parents c713358da074
children e8c379b20765
comparison
equal deleted inserted replaced
23246:f619a77afefe 23247:f2d05fb28e54
3 " Use a different file name for each run. 3 " Use a different file name for each run.
4 let s:sequence = 1 4 let s:sequence = 1
5 5
6 " Check that "lines" inside a ":def" function has no error. 6 " Check that "lines" inside a ":def" function has no error.
7 func CheckDefSuccess(lines) 7 func CheckDefSuccess(lines)
8 let fname = 'Xdef' .. s:sequence 8 let cwd = getcwd()
9 let fname = 'XdefSuccess' .. s:sequence
9 let s:sequence += 1 10 let s:sequence += 1
10 call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname) 11 call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
11 exe 'so ' .. fname 12 try
12 call Func() 13 exe 'so ' .. fname
13 delfunc! Func 14 call Func()
14 call delete(fname) 15 delfunc! Func
16 finally
17 call chdir(cwd)
18 call delete(fname)
19 endtry
15 endfunc 20 endfunc
16 21
17 " Check that "lines" inside ":def" results in an "error" message. 22 " Check that "lines" inside ":def" results in an "error" message.
18 " If "lnum" is given check that the error is reported for this line. 23 " If "lnum" is given check that the error is reported for this line.
19 " Add a line before and after to make it less likely that the line number is 24 " Add a line before and after to make it less likely that the line number is
20 " accidentally correct. 25 " accidentally correct.
21 func CheckDefFailure(lines, error, lnum = -3) 26 func CheckDefFailure(lines, error, lnum = -3)
22 let fname = 'Xdef' .. s:sequence 27 let cwd = getcwd()
28 let fname = 'XdefFailure' .. s:sequence
29 let s:sequence += 1
23 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname) 30 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname)
24 call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1) 31 try
25 delfunc! Func 32 call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1)
26 call delete(fname) 33 finally
27 let s:sequence += 1 34 call chdir(cwd)
35 call delete(fname)
36 delfunc! Func
37 endtry
28 endfunc 38 endfunc
29 39
30 " Check that "lines" inside ":def" results in an "error" message when executed. 40 " Check that "lines" inside ":def" results in an "error" message when executed.
31 " If "lnum" is given check that the error is reported for this line. 41 " If "lnum" is given check that the error is reported for this line.
32 " Add a line before and after to make it less likely that the line number is 42 " Add a line before and after to make it less likely that the line number is
33 " accidentally correct. 43 " accidentally correct.
34 func CheckDefExecFailure(lines, error, lnum = -3) 44 func CheckDefExecFailure(lines, error, lnum = -3)
35 let fname = 'Xdef' .. s:sequence 45 let cwd = getcwd()
46 let fname = 'XdefExecFailure' .. s:sequence
36 let s:sequence += 1 47 let s:sequence += 1
37 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname) 48 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname)
38 exe 'so ' .. fname 49 try
39 call assert_fails('call Func()', a:error, a:lines, a:lnum + 1) 50 exe 'so ' .. fname
40 delfunc! Func 51 call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
41 call delete(fname) 52 finally
53 call chdir(cwd)
54 call delete(fname)
55 delfunc! Func
56 endtry
42 endfunc 57 endfunc
43 58
44 def CheckScriptFailure(lines: list<string>, error: string, lnum = -3) 59 def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
45 var fname = 'Xdef' .. s:sequence 60 var cwd = getcwd()
61 var fname = 'XScriptFailure' .. s:sequence
46 s:sequence += 1 62 s:sequence += 1
47 writefile(lines, fname) 63 writefile(lines, fname)
48 assert_fails('so ' .. fname, error, lines, lnum) 64 try
49 delete(fname) 65 assert_fails('so ' .. fname, error, lines, lnum)
66 finally
67 chdir(cwd)
68 delete(fname)
69 endtry
50 enddef 70 enddef
51 71
52 def CheckScriptSuccess(lines: list<string>) 72 def CheckScriptSuccess(lines: list<string>)
53 var fname = 'Xdef' .. s:sequence 73 var cwd = getcwd()
74 var fname = 'XScriptSuccess' .. s:sequence
54 s:sequence += 1 75 s:sequence += 1
55 writefile(lines, fname) 76 writefile(lines, fname)
56 exe 'so ' .. fname 77 try
57 delete(fname) 78 exe 'so ' .. fname
79 finally
80 chdir(cwd)
81 delete(fname)
82 endtry
58 enddef 83 enddef
59 84
60 def CheckDefAndScriptSuccess(lines: list<string>) 85 def CheckDefAndScriptSuccess(lines: list<string>)
61 CheckDefSuccess(lines) 86 CheckDefSuccess(lines)
62 CheckScriptSuccess(['vim9script'] + lines) 87 CheckScriptSuccess(['vim9script'] + lines)