blob: 9d4337023592c8dd592dc4a27aac1ad5549b1259 [file] [log] [blame]
Bram Moolenaarfc8aa6d2020-10-12 20:31:26 +02001" Test for Vim9 script with failures, causing memory leaks to be reported.
2" The leaks happen after a fork() and can be ignored.
3
Bram Moolenaar853a7692021-12-04 15:00:23 +00004source check.vim
5
Bram Moolenaarfc8aa6d2020-10-12 20:31:26 +02006def Test_assignment()
Bram Moolenaar853a7692021-12-04 15:00:23 +00007 if !has('channel')
8 CheckFeature channel
9 else
Bram Moolenaarfc8aa6d2020-10-12 20:31:26 +020010 var chan1: channel
11 var job1: job
12 var job2: job = job_start('willfail')
13 endif
14enddef
Bram Moolenaarf0e496a2021-12-01 12:41:31 +000015
16" Unclear why this test causes valgrind to report problems.
17def Test_job_info_return_type()
18 if !has('job')
19 CheckFeature job
20 else
21 var job: job = job_start(&shell)
22 var jobs = job_info()
23 assert_equal('list<job>', typename(jobs))
24 assert_equal('dict<any>', typename(job_info(jobs[0])))
25 job_stop(job)
26 endif
27enddef
28
Bram Moolenaar259a7412022-09-23 16:11:37 +010029" Using "idx" from a legacy global function does not work.
30" This caused a crash when called from legacy context.
31" This creates a dict that contains a partial that refers to the dict, causing
32" valgrind to report "possibly leaked memory".
33func Test_partial_call_fails()
34 let lines =<< trim END
35 vim9script
36
37 var l = ['a', 'b', 'c']
38 def Iter(container: any): any
39 var idx = -1
40 var obj = {state: container}
41 def g:NextItem__(self: dict<any>): any
42 ++idx
43 return self.state[idx]
44 enddef
45 obj.__next__ = function('g:NextItem__', [obj])
46 return obj
47 enddef
48
49 var it = Iter(l)
50 echo it.__next__()
51 END
52 call writefile(lines, 'XpartialCall', 'D')
53 let caught = 'no'
54 try
55 source XpartialCall
56 catch /E1248:/
57 let caught = 'yes'
58 endtry
59 call assert_equal('yes', caught)
60 delfunc g:NextItem__
61endfunc
62