|
1 | 1 | " Utility functions for testing vim9 script |
2 | 2 |
|
3 | | -" Check that "lines" inside ":def" has no error. |
| 3 | +" Use a different file name for each run. |
| 4 | +let s:sequence = 1 |
| 5 | + |
| 6 | +" Check that "lines" inside a ":def" function has no error. |
4 | 7 | func CheckDefSuccess(lines) |
5 | | - call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef') |
6 | | - so Xdef |
| 8 | + let fname = 'Xdef' .. s:sequence |
| 9 | + let s:sequence += 1 |
| 10 | + call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname) |
| 11 | + exe 'so ' .. fname |
7 | 12 | call Func() |
8 | | - call delete('Xdef') |
| 13 | + delfunc! Func |
| 14 | + call delete(fname) |
9 | 15 | endfunc |
10 | 16 |
|
11 | 17 | " Check that "lines" inside ":def" results in an "error" message. |
12 | 18 | " If "lnum" is given check that the error is reported for this line. |
13 | 19 | " Add a line before and after to make it less likely that the line number is |
14 | 20 | " accidentally correct. |
15 | 21 | func CheckDefFailure(lines, error, lnum = -3) |
16 | | - call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], 'Xdef') |
17 | | - call assert_fails('so Xdef', a:error, a:lines, a:lnum + 1) |
18 | | - call delete('Xdef') |
| 22 | + let fname = 'Xdef' .. s:sequence |
| 23 | + call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname) |
| 24 | + call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1) |
| 25 | + delfunc! Func |
| 26 | + call delete(fname) |
| 27 | + let s:sequence += 1 |
19 | 28 | endfunc |
20 | 29 |
|
21 | 30 | " Check that "lines" inside ":def" results in an "error" message when executed. |
22 | 31 | " If "lnum" is given check that the error is reported for this line. |
23 | 32 | " Add a line before and after to make it less likely that the line number is |
24 | 33 | " accidentally correct. |
25 | 34 | func CheckDefExecFailure(lines, error, lnum = -3) |
26 | | - call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], 'Xdef') |
27 | | - so Xdef |
| 35 | + let fname = 'Xdef' .. s:sequence |
| 36 | + let s:sequence += 1 |
| 37 | + call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname) |
| 38 | + exe 'so ' .. fname |
28 | 39 | call assert_fails('call Func()', a:error, a:lines, a:lnum + 1) |
29 | | - call delete('Xdef') |
| 40 | + delfunc! Func |
| 41 | + call delete(fname) |
30 | 42 | endfunc |
31 | 43 |
|
32 | 44 | def CheckScriptFailure(lines: list<string>, error: string, lnum = -3) |
33 | | - writefile(lines, 'Xdef') |
34 | | - assert_fails('so Xdef', error, lines, lnum) |
35 | | - delete('Xdef') |
| 45 | + var fname = 'Xdef' .. s:sequence |
| 46 | + s:sequence += 1 |
| 47 | + writefile(lines, fname) |
| 48 | + assert_fails('so ' .. fname, error, lines, lnum) |
| 49 | + delete(fname) |
36 | 50 | enddef |
37 | 51 |
|
38 | 52 | def CheckScriptSuccess(lines: list<string>) |
39 | | - writefile(lines, 'Xdef') |
40 | | - so Xdef |
41 | | - delete('Xdef') |
| 53 | + var fname = 'Xdef' .. s:sequence |
| 54 | + s:sequence += 1 |
| 55 | + writefile(lines, fname) |
| 56 | + exe 'so ' .. fname |
| 57 | + delete(fname) |
42 | 58 | enddef |
43 | 59 |
|
44 | 60 | def CheckDefAndScriptSuccess(lines: list<string>) |
45 | 61 | CheckDefSuccess(lines) |
46 | 62 | CheckScriptSuccess(['vim9script'] + lines) |
47 | 63 | enddef |
48 | 64 |
|
49 | | -" Check that a command fails both when used in a :def function and when used |
50 | | -" in Vim9 script. |
| 65 | +" Check that a command fails with the same error when used in a :def function |
| 66 | +" and when used in Vim9 script. |
51 | 67 | def CheckDefAndScriptFailure(lines: list<string>, error: string, lnum = -3) |
52 | 68 | CheckDefFailure(lines, error, lnum) |
53 | 69 | CheckScriptFailure(['vim9script'] + lines, error, lnum + 1) |
54 | 70 | enddef |
55 | 71 |
|
56 | | -" Check that a command fails both when executed in a :def function and when |
57 | | -" used in Vim9 script. |
| 72 | +" Check that a command fails with the same error when executed in a :def |
| 73 | +" function and when used in Vim9 script. |
58 | 74 | def CheckDefExecAndScriptFailure(lines: list<string>, error: string, lnum = -3) |
59 | 75 | CheckDefExecFailure(lines, error, lnum) |
60 | 76 | CheckScriptFailure(['vim9script'] + lines, error, lnum + 1) |
|
0 commit comments