annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Utility functions for testing vim9 script
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
3 " Use a different file name for each run.
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
4 let s:sequence = 1
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
5
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
6 " Check that "lines" inside a ":def" function has no error.
21733
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
7 func CheckDefSuccess(lines)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
8 let cwd = getcwd()
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
9 let fname = 'XdefSuccess' .. s:sequence
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
10 let s:sequence += 1
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
11 call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
12 try
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
13 exe 'so ' .. fname
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
14 call Func()
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
15 delfunc! Func
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
16 finally
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
17 call chdir(cwd)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
18 call delete(fname)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
19 endtry
21733
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
20 endfunc
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
21
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 " Check that "lines" inside ":def" results in an "error" message.
21859
3e5d0832a2e7 patch 8.2.1479: Vim9: error for list index uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
23 " If "lnum" is given check that the error is reported for this line.
21863
809b1e7fbd72 patch 8.2.1481: Vim9: line number reported with error may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 21859
diff changeset
24 " Add a line before and after to make it less likely that the line number is
809b1e7fbd72 patch 8.2.1481: Vim9: line number reported with error may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 21859
diff changeset
25 " accidentally correct.
809b1e7fbd72 patch 8.2.1481: Vim9: line number reported with error may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 21859
diff changeset
26 func CheckDefFailure(lines, error, lnum = -3)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
27 let cwd = getcwd()
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
28 let fname = 'XdefFailure' .. s:sequence
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
29 let s:sequence += 1
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
30 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
31 try
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
32 call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
33 finally
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
34 call chdir(cwd)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
35 call delete(fname)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
36 delfunc! Func
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
37 endtry
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 endfunc
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
40 " Check that "lines" inside ":def" results in an "error" message when executed.
21859
3e5d0832a2e7 patch 8.2.1479: Vim9: error for list index uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents: 21733
diff changeset
41 " If "lnum" is given check that the error is reported for this line.
21863
809b1e7fbd72 patch 8.2.1481: Vim9: line number reported with error may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 21859
diff changeset
42 " Add a line before and after to make it less likely that the line number is
809b1e7fbd72 patch 8.2.1481: Vim9: line number reported with error may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 21859
diff changeset
43 " accidentally correct.
809b1e7fbd72 patch 8.2.1481: Vim9: line number reported with error may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 21859
diff changeset
44 func CheckDefExecFailure(lines, error, lnum = -3)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
45 let cwd = getcwd()
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
46 let fname = 'XdefExecFailure' .. s:sequence
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
47 let s:sequence += 1
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
48 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
49 try
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
50 exe 'so ' .. fname
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
51 call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
52 finally
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
53 call chdir(cwd)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
54 call delete(fname)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
55 delfunc! Func
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
56 endtry
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
57 endfunc
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
58
21863
809b1e7fbd72 patch 8.2.1481: Vim9: line number reported with error may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 21859
diff changeset
59 def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
60 var cwd = getcwd()
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
61 var fname = 'XScriptFailure' .. s:sequence
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
62 s:sequence += 1
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
63 writefile(lines, fname)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
64 try
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
65 assert_fails('so ' .. fname, error, lines, lnum)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
66 finally
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
67 chdir(cwd)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
68 delete(fname)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
69 endtry
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 enddef
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 def CheckScriptSuccess(lines: list<string>)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
73 var cwd = getcwd()
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
74 var fname = 'XScriptSuccess' .. s:sequence
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
75 s:sequence += 1
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
76 writefile(lines, fname)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
77 try
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
78 exe 'so ' .. fname
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
79 finally
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
80 chdir(cwd)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
81 delete(fname)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
82 endtry
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 enddef
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21863
diff changeset
84
21937
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
85 def CheckDefAndScriptSuccess(lines: list<string>)
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
86 CheckDefSuccess(lines)
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
87 CheckScriptSuccess(['vim9script'] + lines)
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
88 enddef
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
89
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
90 " Check that a command fails with the same error when used in a :def function
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
91 " and when used in Vim9 script.
22190
da851f3b6a0b patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
92 def CheckDefAndScriptFailure(lines: list<string>, error: string, lnum = -3)
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21863
diff changeset
93 CheckDefFailure(lines, error, lnum)
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21863
diff changeset
94 CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21863
diff changeset
95 enddef
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
96
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
97 " Check that a command fails with the same error when executed in a :def
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
98 " function and when used in Vim9 script.
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
99 def CheckDefExecAndScriptFailure(lines: list<string>, error: string, lnum = -3)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
100 CheckDefExecFailure(lines, error, lnum)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
101 CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22190
diff changeset
102 enddef