annotate src/testdir/script_util.vim @ 31339:e1691ff3ad6d v9.0.1003

patch 9.0.1003: tiny build fails Commit: https://github.com/vim/vim/commit/3d3e2aa82695082d01f8d42032229c6fbcc0f1a6 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 4 21:40:51 2022 +0000 patch 9.0.1003: tiny build fails Problem: Tiny build fails. Solution: Remove #ifdef from error message.
author Bram Moolenaar <Bram@vim.org>
date Sun, 04 Dec 2022 22:45:03 +0100
parents f936d46cc9c1
children fc1aeadd8e5c
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 = ''
30687
f936d46cc9c1 patch 9.0.0678: using exclamation marks on :function
Bram Moolenaar <Bram@vim.org>
parents: 21632
diff changeset
51 func ExecAsScript(funcname)
21632
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 = ''
30687
f936d46cc9c1 patch 9.0.0678: using exclamation marks on :function
Bram Moolenaar <Bram@vim.org>
parents: 21632
diff changeset
59 endfunc
21632
792398a9fe39 patch 8.2.1366: test 49 is old style
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
30687
f936d46cc9c1 patch 9.0.0678: using exclamation marks on :function
Bram Moolenaar <Bram@vim.org>
parents: 21632
diff changeset
61 func DeleteTheScript()
21632
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