summaryrefslogtreecommitdiff
path: root/src/testdir/vim9.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-12-20 15:43:31 +0100
committerBram Moolenaar <Bram@vim.org>2020-12-20 15:43:31 +0100
commit090728ad4d54287c911894ef42bfe92844ce0fa5 (patch)
tree31895b9ef4ffd16f2740a2bcd4c07ba14ba0dacd /src/testdir/vim9.vim
parentd24602f43cf1f3c37136fe275b83153c26a406e7 (diff)
downloadvim-git-090728ad4d54287c911894ef42bfe92844ce0fa5.tar.gz
patch 8.2.2169: Vim9: test leaves file behindv8.2.2169
Problem: Vim9: test leaves file behind. Solution: Rename script files. (Dominique Pellé, closes #7511) Use try/finally.
Diffstat (limited to 'src/testdir/vim9.vim')
-rw-r--r--src/testdir/vim9.vim67
1 files changed, 46 insertions, 21 deletions
diff --git a/src/testdir/vim9.vim b/src/testdir/vim9.vim
index e7007320d..bb522df15 100644
--- a/src/testdir/vim9.vim
+++ b/src/testdir/vim9.vim
@@ -5,13 +5,18 @@ let s:sequence = 1
" Check that "lines" inside a ":def" function has no error.
func CheckDefSuccess(lines)
- let fname = 'Xdef' .. s:sequence
+ let cwd = getcwd()
+ let fname = 'XdefSuccess' .. s:sequence
let s:sequence += 1
call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
- exe 'so ' .. fname
- call Func()
- delfunc! Func
- call delete(fname)
+ try
+ exe 'so ' .. fname
+ call Func()
+ delfunc! Func
+ finally
+ call chdir(cwd)
+ call delete(fname)
+ endtry
endfunc
" Check that "lines" inside ":def" results in an "error" message.
@@ -19,12 +24,17 @@ endfunc
" Add a line before and after to make it less likely that the line number is
" accidentally correct.
func CheckDefFailure(lines, error, lnum = -3)
- let fname = 'Xdef' .. s:sequence
- call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname)
- call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1)
- delfunc! Func
- call delete(fname)
+ let cwd = getcwd()
+ let fname = 'XdefFailure' .. s:sequence
let s:sequence += 1
+ call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname)
+ try
+ call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1)
+ finally
+ call chdir(cwd)
+ call delete(fname)
+ delfunc! Func
+ endtry
endfunc
" Check that "lines" inside ":def" results in an "error" message when executed.
@@ -32,29 +42,44 @@ endfunc
" Add a line before and after to make it less likely that the line number is
" accidentally correct.
func CheckDefExecFailure(lines, error, lnum = -3)
- let fname = 'Xdef' .. s:sequence
+ let cwd = getcwd()
+ let fname = 'XdefExecFailure' .. s:sequence
let s:sequence += 1
call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname)
- exe 'so ' .. fname
- call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
- delfunc! Func
- call delete(fname)
+ try
+ exe 'so ' .. fname
+ call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
+ finally
+ call chdir(cwd)
+ call delete(fname)
+ delfunc! Func
+ endtry
endfunc
def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
- var fname = 'Xdef' .. s:sequence
+ var cwd = getcwd()
+ var fname = 'XScriptFailure' .. s:sequence
s:sequence += 1
writefile(lines, fname)
- assert_fails('so ' .. fname, error, lines, lnum)
- delete(fname)
+ try
+ assert_fails('so ' .. fname, error, lines, lnum)
+ finally
+ chdir(cwd)
+ delete(fname)
+ endtry
enddef
def CheckScriptSuccess(lines: list<string>)
- var fname = 'Xdef' .. s:sequence
+ var cwd = getcwd()
+ var fname = 'XScriptSuccess' .. s:sequence
s:sequence += 1
writefile(lines, fname)
- exe 'so ' .. fname
- delete(fname)
+ try
+ exe 'so ' .. fname
+ finally
+ chdir(cwd)
+ delete(fname)
+ endtry
enddef
def CheckDefAndScriptSuccess(lines: list<string>)