Bram Moolenaar | fc8aa6d | 2020-10-12 20:31:26 +0200 | [diff] [blame] | 1 | " 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 Moolenaar | 853a769 | 2021-12-04 15:00:23 +0000 | [diff] [blame] | 4 | source check.vim |
| 5 | |
Bram Moolenaar | fc8aa6d | 2020-10-12 20:31:26 +0200 | [diff] [blame] | 6 | def Test_assignment() |
Bram Moolenaar | 853a769 | 2021-12-04 15:00:23 +0000 | [diff] [blame] | 7 | if !has('channel') |
| 8 | CheckFeature channel |
| 9 | else |
Bram Moolenaar | fc8aa6d | 2020-10-12 20:31:26 +0200 | [diff] [blame] | 10 | var chan1: channel |
| 11 | var job1: job |
| 12 | var job2: job = job_start('willfail') |
| 13 | endif |
| 14 | enddef |
Bram Moolenaar | f0e496a | 2021-12-01 12:41:31 +0000 | [diff] [blame] | 15 | |
| 16 | " Unclear why this test causes valgrind to report problems. |
| 17 | def 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 |
| 27 | enddef |
| 28 | |
Bram Moolenaar | 259a741 | 2022-09-23 16:11:37 +0100 | [diff] [blame^] | 29 | " 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". |
| 33 | func 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__ |
| 61 | endfunc |
| 62 | |