Mercurial > vim
comparison src/testdir/test86.in @ 5517:064e2a080e2e v7.4.107
updated for version 7.4.107
Problem: Python: When vim.eval() encounters a Vim error, a try/catch in the
Python code doesn't catch it. (Yggdroot Chen)
Solution: Throw exceptions on errors in vim.eval(). (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 28 Nov 2013 17:04:43 +0100 |
parents | a56f60cf6834 |
children | ec02e1474bc2 |
comparison
equal
deleted
inserted
replaced
5516:a0b7edaf6a92 | 5517:064e2a080e2e |
---|---|
177 :py l[2]='i' | 177 :py l[2]='i' |
178 :$put =string(l) | 178 :$put =string(l) |
179 :unlockvar! l | 179 :unlockvar! l |
180 :" | 180 :" |
181 :" Function calls | 181 :" Function calls |
182 py << EOF | |
183 import sys | |
184 def ee(expr, g=globals(), l=locals()): | |
185 try: | |
186 exec(expr, g, l) | |
187 except: | |
188 ei = sys.exc_info() | |
189 msg = sys.exc_info()[0].__name__ + ':' + repr(sys.exc_info()[1].args) | |
190 msg = msg.replace('TypeError:(\'argument 1 ', 'TypeError:(\'') | |
191 if expr.find('None') > -1: | |
192 msg = msg.replace('TypeError:(\'iteration over non-sequence\',)', | |
193 'TypeError:("\'NoneType\' object is not iterable",)') | |
194 if expr.find('FailingNumber') > -1: | |
195 msg = msg.replace(', not \'FailingNumber\'', '').replace('"', '\'') | |
196 msg = msg.replace('TypeError:(\'iteration over non-sequence\',)', | |
197 'TypeError:("\'FailingNumber\' object is not iterable",)') | |
198 if msg.find('(\'\'') > -1 or msg.find('(\'can\'t') > -1: | |
199 msg = msg.replace('(\'', '("').replace('\',)', '",)') | |
200 if expr == 'fd(self=[])': | |
201 # HACK: PyMapping_Check changed meaning | |
202 msg = msg.replace('AttributeError:(\'keys\',)', | |
203 'TypeError:(\'unable to convert list to vim dictionary\',)') | |
204 vim.current.buffer.append(expr + ':' + msg) | |
205 else: | |
206 vim.current.buffer.append(expr + ':NOT FAILED') | |
207 EOF | |
182 :fun New(...) | 208 :fun New(...) |
183 : return ['NewStart']+a:000+['NewEnd'] | 209 : return ['NewStart']+a:000+['NewEnd'] |
184 :endfun | 210 :endfun |
185 :fun DictNew(...) dict | 211 :fun DictNew(...) dict |
186 : return ['DictNewStart']+a:000+['DictNewEnd', self] | 212 : return ['DictNewStart']+a:000+['DictNewEnd', self] |
191 :$put =string(l) | 217 :$put =string(l) |
192 :py l.extend(list(l[1](1, 2, 3, self={'a': 'b'}))) | 218 :py l.extend(list(l[1](1, 2, 3, self={'a': 'b'}))) |
193 :$put =string(l) | 219 :$put =string(l) |
194 :py l.extend([l[0].name]) | 220 :py l.extend([l[0].name]) |
195 :$put =string(l) | 221 :$put =string(l) |
196 :try | 222 :py ee('l[1](1, 2, 3)') |
197 : py l[1](1, 2, 3) | |
198 :catch | |
199 : $put =v:exception[:16] | |
200 :endtry | |
201 :py f=l[0] | 223 :py f=l[0] |
202 :delfunction New | 224 :delfunction New |
203 :try | 225 :py ee('f(1, 2, 3)') |
204 : py f(1, 2, 3) | |
205 :catch | |
206 : $put =v:exception[:16] | |
207 :endtry | |
208 :if has('float') | 226 :if has('float') |
209 : let l=[0.0] | 227 : let l=[0.0] |
210 : py l=vim.bindeval('l') | 228 : py l=vim.bindeval('l') |
211 : py l.extend([0.0]) | 229 : py l.extend([0.0]) |
212 : $put =string(l) | 230 : $put =string(l) |
214 : $put ='[0.0, 0.0]' | 232 : $put ='[0.0, 0.0]' |
215 :endif | 233 :endif |
216 :let messages=[] | 234 :let messages=[] |
217 :delfunction DictNew | 235 :delfunction DictNew |
218 py <<EOF | 236 py <<EOF |
219 import sys | |
220 d=vim.bindeval('{}') | 237 d=vim.bindeval('{}') |
221 m=vim.bindeval('messages') | 238 m=vim.bindeval('messages') |
222 def em(expr, g=globals(), l=locals()): | 239 def em(expr, g=globals(), l=locals()): |
223 try: | 240 try: |
224 exec(expr, g, l) | 241 exec(expr, g, l) |
321 :py t.running = False | 338 :py t.running = False |
322 :py t.join() | 339 :py t.join() |
323 :py l[0] = t.t > 8 # check if the background thread is working | 340 :py l[0] = t.t > 8 # check if the background thread is working |
324 :py del time | 341 :py del time |
325 :py del threading | 342 :py del threading |
343 :py del t | |
326 :$put =string(l) | 344 :$put =string(l) |
327 :" | 345 :" |
328 :" settrace | 346 :" settrace |
329 :let l = [] | 347 :let l = [] |
330 :py l=vim.bindeval('l') | 348 :py l=vim.bindeval('l') |
880 :fun F() dict | 898 :fun F() dict |
881 :endfun | 899 :endfun |
882 :fun D() | 900 :fun D() |
883 :endfun | 901 :endfun |
884 py << EOF | 902 py << EOF |
885 def ee(expr, g=globals(), l=locals()): | |
886 try: | |
887 exec(expr, g, l) | |
888 except: | |
889 ei = sys.exc_info() | |
890 msg = sys.exc_info()[0].__name__ + ':' + repr(sys.exc_info()[1].args) | |
891 msg = msg.replace('TypeError:(\'argument 1 ', 'TypeError:(\'') | |
892 if expr.find('None') > -1: | |
893 msg = msg.replace('TypeError:(\'iteration over non-sequence\',)', | |
894 'TypeError:("\'NoneType\' object is not iterable",)') | |
895 if expr.find('FailingNumber') > -1: | |
896 msg = msg.replace(', not \'FailingNumber\'', '').replace('"', '\'') | |
897 msg = msg.replace('TypeError:(\'iteration over non-sequence\',)', | |
898 'TypeError:("\'FailingNumber\' object is not iterable",)') | |
899 if msg.find('(\'\'') > -1 or msg.find('(\'can\'t') > -1: | |
900 msg = msg.replace('(\'', '("').replace('\',)', '",)') | |
901 if expr == 'fd(self=[])': | |
902 # HACK: PyMapping_Check changed meaning | |
903 msg = msg.replace('AttributeError:(\'keys\',)', | |
904 'TypeError:(\'unable to convert list to vim dictionary\',)') | |
905 cb.append(expr + ':' + msg) | |
906 else: | |
907 cb.append(expr + ':NOT FAILED') | |
908 d = vim.Dictionary() | 903 d = vim.Dictionary() |
909 ned = vim.Dictionary(foo='bar', baz='abcD') | 904 ned = vim.Dictionary(foo='bar', baz='abcD') |
910 dl = vim.Dictionary(a=1) | 905 dl = vim.Dictionary(a=1) |
911 dl.locked = True | 906 dl.locked = True |
912 l = vim.List() | 907 l = vim.List() |
1274 ee('vim.command("throw \'abcN\'")') | 1269 ee('vim.command("throw \'abcN\'")') |
1275 ee('Exe("throw \'def\'")') | 1270 ee('Exe("throw \'def\'")') |
1276 ee('vim.eval("Exe(\'throw \'\'ghi\'\'\')")') | 1271 ee('vim.eval("Exe(\'throw \'\'ghi\'\'\')")') |
1277 ee('vim.eval("Exe(\'echoerr \'\'jkl\'\'\')")') | 1272 ee('vim.eval("Exe(\'echoerr \'\'jkl\'\'\')")') |
1278 ee('vim.eval("Exe(\'xxx_non_existent_command_xxx\')")') | 1273 ee('vim.eval("Exe(\'xxx_non_existent_command_xxx\')")') |
1274 ee('vim.eval("xxx_unknown_function_xxx()")') | |
1279 ee('vim.bindeval("Exe(\'xxx_non_existent_command_xxx\')")') | 1275 ee('vim.bindeval("Exe(\'xxx_non_existent_command_xxx\')")') |
1280 del Exe | 1276 del Exe |
1281 EOF | 1277 EOF |
1282 :delfunction Exe | 1278 :delfunction Exe |
1283 :" | 1279 :" |