diff options
author | Bram Moolenaar <Bram@vim.org> | 2013-05-21 20:40:40 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2013-05-21 20:40:40 +0200 |
commit | a7b64ce74e857d4516b87ca80c850e5ef6324ba6 (patch) | |
tree | 7973c8efc51c8f261a01aa5c19d519b2c643233d /src/testdir | |
parent | cac867ad1836d0bc44403f66a3367afffda76095 (diff) | |
download | vim-git-a7b64ce74e857d4516b87ca80c850e5ef6324ba6.tar.gz |
updated for version 7.3.997v7.3.997
Problem: Vim and Python exceptions are different.
Solution: Make Vim exceptions be Python exceptions. (ZyX)
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test86.in | 56 | ||||
-rw-r--r-- | src/testdir/test86.ok | 8 | ||||
-rw-r--r-- | src/testdir/test87.in | 56 | ||||
-rw-r--r-- | src/testdir/test87.ok | 8 |
4 files changed, 90 insertions, 38 deletions
diff --git a/src/testdir/test86.in b/src/testdir/test86.in index c49eb3bad..fac315e2d 100644 --- a/src/testdir/test86.in +++ b/src/testdir/test86.in @@ -380,20 +380,24 @@ def e(s, g=globals(), l=locals()): try: exec(s, g, l) except: - vim.command('throw ' + repr(sys.exc_type.__name__)) + vim.command('return ' + repr(sys.exc_type.__name__)) def ev(s, g=globals(), l=locals()): try: return eval(s, g, l) except: - vim.command('throw ' + repr(sys.exc_type.__name__)) + vim.command('let exc=' + repr(sys.exc_type.__name__)) return 0 EOF :function E(s) : python e(vim.eval('a:s')) :endfunction :function Ev(s) -: return pyeval('ev(vim.eval("a:s"))') +: let r=pyeval('ev(vim.eval("a:s"))') +: if exists('exc') +: throw exc +: endif +: return r :endfunction :py gopts1=vim.options :py wopts1=vim.windows[2].options @@ -437,27 +441,24 @@ EOF : catch : put =' p/'.v.'! '.v:exception : endtry -: try -: call E(v.'["'.oname.'"]=invval') -: catch -: put =' inv: '.string(invval).'! '.v:exception -: endtry +: let r=E(v.'['''.oname.''']=invval') +: if r isnot 0 +: put =' inv: '.string(invval).'! '.r +: endif : for vv in (v is# 'gopts1' ? [v] : [v, v[:-2].'2', v[:-2].'3']) : let val=substitute(vv, '^.opts', 'oval', '') -: try -: call E(vv.'["'.oname.'"]='.val) -: catch -: put =' '.vv.'! '.v:exception -: endtry +: let r=E(vv.'['''.oname.''']='.val) +: if r isnot 0 +: put =' '.vv.'! '.r +: endif : endfor : endfor : call RecVars(oname) : for v in ['wopts3', 'bopts3'] -: try -: call E('del '.v.'["'.oname.'"]') -: catch -: put =' del '.v.'! '.v:exception -: endtry +: let r=E('del '.v.'["'.oname.'"]') +: if r isnot 0 +: put =' del '.v.'! '.r +: endif : endfor : call RecVars(oname) :endfor @@ -651,6 +652,25 @@ for expr, attr in ( ): cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr))) EOF +:" +:" Test exceptions +:fun Exe(e) +: execute a:e +:endfun +py << EOF +def ee(expr, g=globals(), l=locals()): + try: + exec(expr, g, l) + except: + cb.append(repr(sys.exc_info()[:2])) +Exe = vim.bindeval('function("Exe")') +ee('vim.command("throw \'abc\'")') +ee('Exe("throw \'def\'")') +ee('vim.eval("Exe(\'throw \'\'ghi\'\'\')")') +ee('vim.eval("Exe(\'echoerr \'\'jkl\'\'\')")') +ee('vim.eval("Exe(\'xxx_non_existent_command_xxx\')")') +ee('vim.bindeval("Exe(\'xxx_non_existent_command_xxx\')")') +EOF :endfun :" :call Test() diff --git a/src/testdir/test86.ok b/src/testdir/test86.ok index c91f741a0..5602b2f10 100644 --- a/src/testdir/test86.ok +++ b/src/testdir/test86.ok @@ -333,7 +333,7 @@ Number of tabs: 4 Current tab pages: <tabpage 0>(1): 1 windows, current is <window object (unknown)> Windows: - <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor is at (970, 0) + <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor is at (990, 0) <tabpage 1>(2): 1 windows, current is <window object (unknown)> Windows: <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0) @@ -368,3 +368,9 @@ vim.current.buffer:Buffer:True vim.current.range:Range:True vim.current.window:Window:True vim.current.tabpage:TabPage:True +(<class 'vim.error'>, error('abc',)) +(<class 'vim.error'>, error('def',)) +(<class 'vim.error'>, error('ghi',)) +(<class 'vim.error'>, error('Vim(echoerr):jkl',)) +(<class 'vim.error'>, error('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',)) +(<class 'vim.error'>, error('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',)) diff --git a/src/testdir/test87.in b/src/testdir/test87.in index 94c1ab535..69af02eec 100644 --- a/src/testdir/test87.in +++ b/src/testdir/test87.in @@ -367,20 +367,24 @@ def e(s, g=globals(), l=locals()): try: exec(s, g, l) except Exception as e: - vim.command('throw ' + repr(e.__class__.__name__)) + vim.command('return ' + repr(e.__class__.__name__)) def ev(s, g=globals(), l=locals()): try: return eval(s, g, l) except Exception as e: - vim.command('throw ' + repr(e.__class__.__name__)) + vim.command('let exc=' + repr(e.__class__.__name__)) return 0 EOF :function E(s) : python3 e(vim.eval('a:s')) :endfunction :function Ev(s) -: return py3eval('ev(vim.eval("a:s"))') +: let r=py3eval('ev(vim.eval("a:s"))') +: if exists('exc') +: throw exc +: endif +: return r :endfunction :py3 gopts1=vim.options :py3 wopts1=vim.windows[2].options @@ -424,27 +428,24 @@ EOF : catch : put =' p/'.v.'! '.v:exception : endtry -: try -: call E(v.'["'.oname.'"]=invval') -: catch -: put =' inv: '.string(invval).'! '.v:exception -: endtry +: let r=E(v.'['''.oname.''']=invval') +: if r isnot 0 +: put =' inv: '.string(invval).'! '.r +: endif : for vv in (v is# 'gopts1' ? [v] : [v, v[:-2].'2', v[:-2].'3']) : let val=substitute(vv, '^.opts', 'oval', '') -: try -: call E(vv.'["'.oname.'"]='.val) -: catch -: put =' '.vv.'! '.v:exception -: endtry +: let r=E(vv.'['''.oname.''']='.val) +: if r isnot 0 +: put =' '.vv.'! '.r +: endif : endfor : endfor : call RecVars(oname) : for v in ['wopts3', 'bopts3'] -: try -: call E('del '.v.'["'.oname.'"]') -: catch -: put =' del '.v.'! '.v:exception -: endtry +: let r=E('del '.v.'["'.oname.'"]') +: if r isnot 0 +: put =' del '.v.'! '.r +: endif : endfor : call RecVars(oname) :endfor @@ -638,6 +639,25 @@ for expr, attr in ( ): cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr))) EOF +:" +:" Test exceptions +:fun Exe(e) +: execute a:e +:endfun +py3 << EOF +def ee(expr, g=globals(), l=locals()): + try: + exec(expr, g, l) + except Exception as e: + cb.append(repr((e.__class__, e))) +Exe = vim.bindeval('function("Exe")') +ee('vim.command("throw \'abc\'")') +ee('Exe("throw \'def\'")') +ee('vim.eval("Exe(\'throw \'\'ghi\'\'\')")') +ee('vim.eval("Exe(\'echoerr \'\'jkl\'\'\')")') +ee('vim.eval("Exe(\'xxx_non_existent_command_xxx\')")') +ee('vim.bindeval("Exe(\'xxx_non_existent_command_xxx\')")') +EOF :endfun :" :call Test() diff --git a/src/testdir/test87.ok b/src/testdir/test87.ok index 08cd590e2..64ef57d5c 100644 --- a/src/testdir/test87.ok +++ b/src/testdir/test87.ok @@ -322,7 +322,7 @@ Number of tabs: 4 Current tab pages: <tabpage 0>(1): 1 windows, current is <window object (unknown)> Windows: - <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor is at (946, 0) + <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor is at (966, 0) <tabpage 1>(2): 1 windows, current is <window object (unknown)> Windows: <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0) @@ -357,3 +357,9 @@ vim.current.buffer:Buffer:True vim.current.range:Range:True vim.current.window:Window:True vim.current.tabpage:TabPage:True +(<class 'vim.error'>, error('abc',)) +(<class 'vim.error'>, error('def',)) +(<class 'vim.error'>, error('ghi',)) +(<class 'vim.error'>, error('Vim(echoerr):jkl',)) +(<class 'vim.error'>, error('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',)) +(<class 'vim.error'>, error('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',)) |