@@ -55,16 +55,26 @@ endfunction
5555" ExecAsScript - Source a temporary script made from a function. {{{2
5656"
5757" Make a temporary script file from the function a:funcname, ":source" it, and
58- " delete it afterwards.
58+ " delete it afterwards. However, if an exception is thrown the file may remain,
59+ " the caller should call DeleteTheScript() afterwards.
60+ let s: script_name = ' '
5961function ! ExecAsScript (funcname)
6062 " Make a script from the function passed as argument.
61- let script = MakeScript (a: funcname )
63+ let s: script_name = MakeScript (a: funcname )
6264
6365 " Source and delete the script.
64- exec " source" script
65- call delete (script )
66+ exec " source" s: script_name
67+ call delete (s: script_name )
68+ let s: script_name = ' '
6669endfunction
6770
71+ function ! DeleteTheScript ()
72+ if s: script_name
73+ call delete (s: script_name )
74+ let s: script_name = ' '
75+ endif
76+ endfunc
77+
6878com ! -nargs =1 - bar ExecAsScript call ExecAsScript (<f-args> )
6979
7080
@@ -143,6 +153,7 @@ func Test_endwhile_script()
143153 XpathINIT
144154 ExecAsScript T1_F
145155 Xpath ' F'
156+ call DeleteTheScript ()
146157
147158 try
148159 ExecAsScript T1_G
@@ -152,6 +163,7 @@ func Test_endwhile_script()
152163 Xpath ' x'
153164 endtry
154165 Xpath ' G'
166+ call DeleteTheScript ()
155167
156168 call assert_equal (' abcFhijxG' , g: Xpath )
157169endfunc
@@ -260,6 +272,7 @@ function Test_finish()
260272 XpathINIT
261273 ExecAsScript T4_F
262274 Xpath ' 5'
275+ call DeleteTheScript ()
263276
264277 call assert_equal (' ab3e3b2c25' , g: Xpath )
265278endfunction
@@ -987,6 +1000,11 @@ func Test_type()
9871000 call assert_equal (v: true , eval (string (v: true )))
9881001 call assert_equal (v: none , eval (string (v: none )))
9891002 call assert_equal (v: null , eval (string (v: null )))
1003+
1004+ call assert_true (empty (v: false ))
1005+ call assert_false (empty (v: true ))
1006+ call assert_true (empty (v: null ))
1007+ call assert_true (empty (v: none ))
9901008endfunc
9911009
9921010" -------------------------------------------------------------------------------
0 commit comments