Mercurial > vim
comparison src/testdir/test_vim9_func.vim @ 23092:c713358da074 v8.2.2092
patch 8.2.2092: Vim9: unpredictable errors for script tests
Commit: https://github.com/vim/vim/commit/2d870f8d9ebad22d32799d0d0ee30943d0a0e49d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 5 13:41:01 2020 +0100
patch 8.2.2092: Vim9: unpredictable errors for script tests
Problem: Vim9: unpredictable errors for script tests.
Solution: Use a different script file name for each run.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 05 Dec 2020 13:45:04 +0100 |
parents | cd885eb0e50c |
children | bdafc132a4a1 |
comparison
equal
deleted
inserted
replaced
23091:dd27e20498a3 | 23092:c713358da074 |
---|---|
197 MyDefaultSecond('test')->assert_equal('test') | 197 MyDefaultSecond('test')->assert_equal('test') |
198 MyDefaultSecond('test', true)->assert_equal('test') | 198 MyDefaultSecond('test', true)->assert_equal('test') |
199 MyDefaultSecond('test', false)->assert_equal('none') | 199 MyDefaultSecond('test', false)->assert_equal('none') |
200 | 200 |
201 CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:') | 201 CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:') |
202 delfunc g:Func | |
202 CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string') | 203 CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string') |
204 delfunc g:Func | |
203 enddef | 205 enddef |
204 | 206 |
205 def Test_nested_function() | 207 def Test_nested_function() |
206 def Nested(arg: string): string | 208 def Nested(arg: string): string |
207 return 'nested ' .. arg | 209 return 'nested ' .. arg |
324 def Func(): string | 326 def Func(): string |
325 return 'local' | 327 return 'local' |
326 enddef | 328 enddef |
327 g:Func()->assert_equal('global') | 329 g:Func()->assert_equal('global') |
328 Func()->assert_equal('local') | 330 Func()->assert_equal('local') |
331 delfunc g:Func | |
329 END | 332 END |
330 CheckScriptSuccess(lines) | 333 CheckScriptSuccess(lines) |
331 | 334 |
332 lines =<< trim END | 335 lines =<< trim END |
333 vim9script | 336 vim9script |
603 var l: list<string> = [] | 606 var l: list<string> = [] |
604 ListArg(l) | 607 ListArg(l) |
605 l[0]->assert_equal('value') | 608 l[0]->assert_equal('value') |
606 | 609 |
607 CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:') | 610 CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:') |
611 delfunc! g:Func | |
608 enddef | 612 enddef |
609 | 613 |
610 " These argument names are reserved in legacy functions. | 614 " These argument names are reserved in legacy functions. |
611 def WithReservedNames(firstline: string, lastline: string): string | 615 def WithReservedNames(firstline: string, lastline: string): string |
612 return firstline .. lastline | 616 return firstline .. lastline |
761 CheckScriptFailure([ | 765 CheckScriptFailure([ |
762 'def Func(): number', | 766 'def Func(): number', |
763 'return "a"', | 767 'return "a"', |
764 'enddef', | 768 'enddef', |
765 'defcompile'], 'expected number but got string') | 769 'defcompile'], 'expected number but got string') |
770 delfunc! g:Func | |
766 CheckScriptFailure([ | 771 CheckScriptFailure([ |
767 'def Func(): string', | 772 'def Func(): string', |
768 'return 1', | 773 'return 1', |
769 'enddef', | 774 'enddef', |
770 'defcompile'], 'expected string but got number') | 775 'defcompile'], 'expected string but got number') |
776 delfunc! g:Func | |
771 CheckScriptFailure([ | 777 CheckScriptFailure([ |
772 'def Func(): void', | 778 'def Func(): void', |
773 'return "a"', | 779 'return "a"', |
774 'enddef', | 780 'enddef', |
775 'defcompile'], | 781 'defcompile'], |
776 'E1096: Returning a value in a function without a return type') | 782 'E1096: Returning a value in a function without a return type') |
783 delfunc! g:Func | |
777 CheckScriptFailure([ | 784 CheckScriptFailure([ |
778 'def Func()', | 785 'def Func()', |
779 'return "a"', | 786 'return "a"', |
780 'enddef', | 787 'enddef', |
781 'defcompile'], | 788 'defcompile'], |
782 'E1096: Returning a value in a function without a return type') | 789 'E1096: Returning a value in a function without a return type') |
790 delfunc! g:Func | |
783 | 791 |
784 CheckScriptFailure([ | 792 CheckScriptFailure([ |
785 'def Func(): number', | 793 'def Func(): number', |
786 'return', | 794 'return', |
787 'enddef', | 795 'enddef', |
788 'defcompile'], 'E1003:') | 796 'defcompile'], 'E1003:') |
797 delfunc! g:Func | |
789 | 798 |
790 CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:') | 799 CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:') |
800 delfunc! g:Func | |
791 CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:') | 801 CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:') |
802 delfunc! g:Func | |
792 CheckScriptFailure(['def Func()', 'return 1'], 'E1057:') | 803 CheckScriptFailure(['def Func()', 'return 1'], 'E1057:') |
804 delfunc! g:Func | |
793 | 805 |
794 CheckScriptFailure([ | 806 CheckScriptFailure([ |
795 'vim9script', | 807 'vim9script', |
796 'def FuncB()', | 808 'def FuncB()', |
797 ' return 123', | 809 ' return 123', |
1246 assert_report('should have failed') | 1258 assert_report('should have failed') |
1247 catch /E476:/ | 1259 catch /E476:/ |
1248 v:exception->assert_match('Invalid command: invalid') | 1260 v:exception->assert_match('Invalid command: invalid') |
1249 v:throwpoint->assert_match(', line 3$') | 1261 v:throwpoint->assert_match(', line 3$') |
1250 endtry | 1262 endtry |
1263 delfunc! g:Func | |
1251 | 1264 |
1252 # comment lines after the start of the function | 1265 # comment lines after the start of the function |
1253 lines =<< trim END | 1266 lines =<< trim END |
1254 " comment | 1267 " comment |
1255 def Func() | 1268 def Func() |
1266 assert_report('should have failed') | 1279 assert_report('should have failed') |
1267 catch /E476:/ | 1280 catch /E476:/ |
1268 v:exception->assert_match('Invalid command: invalid') | 1281 v:exception->assert_match('Invalid command: invalid') |
1269 v:throwpoint->assert_match(', line 4$') | 1282 v:throwpoint->assert_match(', line 4$') |
1270 endtry | 1283 endtry |
1284 delfunc! g:Func | |
1271 | 1285 |
1272 lines =<< trim END | 1286 lines =<< trim END |
1273 vim9script | 1287 vim9script |
1274 def Func() | 1288 def Func() |
1275 var db = {foo: 1, bar: 2} | 1289 var db = {foo: 1, bar: 2} |
1284 source Xdef | 1298 source Xdef |
1285 assert_report('should have failed') | 1299 assert_report('should have failed') |
1286 catch /E716:/ | 1300 catch /E716:/ |
1287 v:throwpoint->assert_match('_Func, line 3$') | 1301 v:throwpoint->assert_match('_Func, line 3$') |
1288 endtry | 1302 endtry |
1303 delfunc! g:Func | |
1289 | 1304 |
1290 delete('Xdef') | 1305 delete('Xdef') |
1291 enddef | 1306 enddef |
1292 | 1307 |
1293 def Test_deleted_function() | 1308 def Test_deleted_function() |
1764 popup_close(winid) | 1779 popup_close(winid) |
1765 enddef | 1780 enddef |
1766 Func() | 1781 Func() |
1767 END | 1782 END |
1768 CheckScriptFailure(lines, 'E492:', 8) | 1783 CheckScriptFailure(lines, 'E492:', 8) |
1784 delfunc! g:Func | |
1769 enddef | 1785 enddef |
1770 | 1786 |
1771 def Test_abort_even_with_silent() | 1787 def Test_abort_even_with_silent() |
1772 var lines =<< trim END | 1788 var lines =<< trim END |
1773 vim9script | 1789 vim9script |