comparison src/testdir/test87.in @ 4498:ef02f32d8e53 v7.3.997

updated for version 7.3.997 Problem: Vim and Python exceptions are different. Solution: Make Vim exceptions be Python exceptions. (ZyX)
author Bram Moolenaar <bram@vim.org>
date Tue, 21 May 2013 20:40:40 +0200
parents ebd94eabfd80
children ce94a870b59b
comparison
equal deleted inserted replaced
4497:51bae43f1787 4498:ef02f32d8e53
365 py3 << EOF 365 py3 << EOF
366 def e(s, g=globals(), l=locals()): 366 def e(s, g=globals(), l=locals()):
367 try: 367 try:
368 exec(s, g, l) 368 exec(s, g, l)
369 except Exception as e: 369 except Exception as e:
370 vim.command('throw ' + repr(e.__class__.__name__)) 370 vim.command('return ' + repr(e.__class__.__name__))
371 371
372 def ev(s, g=globals(), l=locals()): 372 def ev(s, g=globals(), l=locals()):
373 try: 373 try:
374 return eval(s, g, l) 374 return eval(s, g, l)
375 except Exception as e: 375 except Exception as e:
376 vim.command('throw ' + repr(e.__class__.__name__)) 376 vim.command('let exc=' + repr(e.__class__.__name__))
377 return 0 377 return 0
378 EOF 378 EOF
379 :function E(s) 379 :function E(s)
380 : python3 e(vim.eval('a:s')) 380 : python3 e(vim.eval('a:s'))
381 :endfunction 381 :endfunction
382 :function Ev(s) 382 :function Ev(s)
383 : return py3eval('ev(vim.eval("a:s"))') 383 : let r=py3eval('ev(vim.eval("a:s"))')
384 : if exists('exc')
385 : throw exc
386 : endif
387 : return r
384 :endfunction 388 :endfunction
385 :py3 gopts1=vim.options 389 :py3 gopts1=vim.options
386 :py3 wopts1=vim.windows[2].options 390 :py3 wopts1=vim.windows[2].options
387 :py3 wopts2=vim.windows[0].options 391 :py3 wopts2=vim.windows[0].options
388 :py3 wopts3=vim.windows[1].options 392 :py3 wopts3=vim.windows[1].options
422 : try 426 : try
423 : put =' p/'.v.': '.Ev('repr('.v.'['''.oname.'''])') 427 : put =' p/'.v.': '.Ev('repr('.v.'['''.oname.'''])')
424 : catch 428 : catch
425 : put =' p/'.v.'! '.v:exception 429 : put =' p/'.v.'! '.v:exception
426 : endtry 430 : endtry
427 : try 431 : let r=E(v.'['''.oname.''']=invval')
428 : call E(v.'["'.oname.'"]=invval') 432 : if r isnot 0
429 : catch 433 : put =' inv: '.string(invval).'! '.r
430 : put =' inv: '.string(invval).'! '.v:exception 434 : endif
431 : endtry
432 : for vv in (v is# 'gopts1' ? [v] : [v, v[:-2].'2', v[:-2].'3']) 435 : for vv in (v is# 'gopts1' ? [v] : [v, v[:-2].'2', v[:-2].'3'])
433 : let val=substitute(vv, '^.opts', 'oval', '') 436 : let val=substitute(vv, '^.opts', 'oval', '')
434 : try 437 : let r=E(vv.'['''.oname.''']='.val)
435 : call E(vv.'["'.oname.'"]='.val) 438 : if r isnot 0
436 : catch 439 : put =' '.vv.'! '.r
437 : put =' '.vv.'! '.v:exception 440 : endif
438 : endtry
439 : endfor 441 : endfor
440 : endfor 442 : endfor
441 : call RecVars(oname) 443 : call RecVars(oname)
442 : for v in ['wopts3', 'bopts3'] 444 : for v in ['wopts3', 'bopts3']
443 : try 445 : let r=E('del '.v.'["'.oname.'"]')
444 : call E('del '.v.'["'.oname.'"]') 446 : if r isnot 0
445 : catch 447 : put =' del '.v.'! '.r
446 : put =' del '.v.'! '.v:exception 448 : endif
447 : endtry
448 : endfor 449 : endfor
449 : call RecVars(oname) 450 : call RecVars(oname)
450 :endfor 451 :endfor
451 :only 452 :only
452 :for buf in g:bufs[1:] 453 :for buf in g:bufs[1:]
636 ('vim.current.window', 'Window'), 637 ('vim.current.window', 'Window'),
637 ('vim.current.tabpage', 'TabPage'), 638 ('vim.current.tabpage', 'TabPage'),
638 ): 639 ):
639 cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr))) 640 cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr)))
640 EOF 641 EOF
642 :"
643 :" Test exceptions
644 :fun Exe(e)
645 : execute a:e
646 :endfun
647 py3 << EOF
648 def ee(expr, g=globals(), l=locals()):
649 try:
650 exec(expr, g, l)
651 except Exception as e:
652 cb.append(repr((e.__class__, e)))
653 Exe = vim.bindeval('function("Exe")')
654 ee('vim.command("throw \'abc\'")')
655 ee('Exe("throw \'def\'")')
656 ee('vim.eval("Exe(\'throw \'\'ghi\'\'\')")')
657 ee('vim.eval("Exe(\'echoerr \'\'jkl\'\'\')")')
658 ee('vim.eval("Exe(\'xxx_non_existent_command_xxx\')")')
659 ee('vim.bindeval("Exe(\'xxx_non_existent_command_xxx\')")')
660 EOF
641 :endfun 661 :endfun
642 :" 662 :"
643 :call Test() 663 :call Test()
644 :" 664 :"
645 :delfunc Test 665 :delfunc Test