annotate src/testdir/script_util.vim @ 29970:d891115c0aea v9.0.0323

patch 9.0.0323: using common name in tests leads to flaky tests Commit: https://github.com/vim/vim/commit/3b0d70f4ff436cb144683dafd956e8a3ee485a90 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 29 22:31:20 2022 +0100 patch 9.0.0323: using common name in tests leads to flaky tests Problem: Using common name in tests leads to flaky tests. Solution: Rename files and directories to be more specific.
author Bram Moolenaar <Bram@vim.org>
date Mon, 29 Aug 2022 23:45:04 +0200
parents 792398a9fe39
children f936d46cc9c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21632
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Functions shared by the tests for Vim Script
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 " Commands to track the execution path of a script
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 com! XpathINIT let g:Xpath = ''
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 com! -nargs=1 -bar Xpath let g:Xpath ..= <args>
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 com! XloopINIT let g:Xloop = 1
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 com! -nargs=1 -bar Xloop let g:Xpath ..= <args> .. g:Xloop
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 com! XloopNEXT let g:Xloop += 1
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 " MakeScript() - Make a script file from a function. {{{2
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 "
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 " Create a script that consists of the body of the function a:funcname.
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 " Replace any ":return" by a ":finish", any argument variable by a global
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 " variable, and every ":call" by a ":source" for the next following argument
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 " in the variable argument list. This function is useful if similar tests are
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 " to be made for a ":return" from a function call or a ":finish" in a script
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 " file.
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 func MakeScript(funcname, ...)
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 let script = tempname()
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 execute "redir! >" . script
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 execute "function" a:funcname
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 redir END
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 execute "edit" script
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 " Delete the "function" and the "endfunction" lines. Do not include the
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 " word "function" in the pattern since it might be translated if LANG is
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 " set. When MakeScript() is being debugged, this deletes also the debugging
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 " output of its line 3 and 4.
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 exec '1,/.*' . a:funcname . '(.*)/d'
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 /^\d*\s*endfunction\>/,$d
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 %s/^\d*//e
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 %s/return/finish/e
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 %s/\<a:\(\h\w*\)/g:\1/ge
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 normal gg0
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 let cnt = 0
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 while search('\<call\s*\%(\u\|s:\)\w*\s*(.*)', 'W') > 0
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 let cnt = cnt + 1
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 s/\<call\s*\%(\u\|s:\)\w*\s*(.*)/\='source ' . a:{cnt}/
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 endwhile
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 g/^\s*$/d
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 write
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 bwipeout
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 return script
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 endfunc
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 " ExecAsScript - Source a temporary script made from a function. {{{2
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 "
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 " Make a temporary script file from the function a:funcname, ":source" it, and
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 " delete it afterwards. However, if an exception is thrown the file may remain,
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 " the caller should call DeleteTheScript() afterwards.
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 let s:script_name = ''
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 function! ExecAsScript(funcname)
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 " Make a script from the function passed as argument.
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 let s:script_name = MakeScript(a:funcname)
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 " Source and delete the script.
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 exec "source" s:script_name
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 call delete(s:script_name)
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 let s:script_name = ''
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 endfunction
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 function! DeleteTheScript()
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 if s:script_name
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 call delete(s:script_name)
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 let s:script_name = ''
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 endif
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 endfunc
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 com! -nargs=1 -bar ExecAsScript call ExecAsScript(<f-args>)
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69