From 7d046574cbb4fe47d8e5d8d681edcef7161e9af9 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sat, 14 Dec 2019 18:03:34 +0000 Subject: [PATCH] Add tests for toggling breakpoint and inserting line --- docs/configuration.md | 7 ++- python3/vimspector/breakpoints.py | 2 +- .../python/simple_python/.vimspector.json | 12 +++++ tests/breakpoints.test.vim | 49 +++++++++++++++++++ tests/language_python.test.vim | 16 ++---- tests/lib/autoload/vimspector/test/setup.vim | 9 +++- 6 files changed, 79 insertions(+), 16 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 199ebe9..97418e1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -24,7 +24,6 @@ things like: Along with optional additional configuration for things like: -- Function breakpoints - Exception breakpoints ### Debug adapter configuration @@ -109,6 +108,12 @@ But for now, consider the following example snippet: "--test-identifier", "${TestIdentifier}", "--secret-token", "${SecretToken}" ] + }, + "breakpoints": { + "exception": { + "caught": "", + "uncaught": "Y" + } } } } diff --git a/python3/vimspector/breakpoints.py b/python3/vimspector/breakpoints.py index 82f4c6f..01da54d 100644 --- a/python3/vimspector/breakpoints.py +++ b/python3/vimspector/breakpoints.py @@ -305,7 +305,7 @@ class ProjectBreakpoints( object ): if isinstance( result, bool ): result = 'Y' if result else 'N' - if not isinstance( result, str) or result not in ( 'Y', 'N', '' ): + if not isinstance( result, str ) or result not in ( 'Y', 'N', '' ): raise ValueError( f"Invalid value for exception breakpoint filter '{f}': " f"'{result}'. Must be boolean, 'Y', 'N' or '' (default)" ) diff --git a/support/test/python/simple_python/.vimspector.json b/support/test/python/simple_python/.vimspector.json index 600295c..3de14d8 100644 --- a/support/test/python/simple_python/.vimspector.json +++ b/support/test/python/simple_python/.vimspector.json @@ -9,6 +9,12 @@ "program": "${file}", "stopOnEntry": true, "console": "integratedTerminal" + }, + "breakpoints": { + "exception": { + "raised": "N", + "uncaught": "" + } } }, "attach": { @@ -18,6 +24,12 @@ "type": "python", "host": "localhost", "port": "5678" + }, + "breakpoints": { + "exception": { + "raised": "N", + "uncaught": "" + } } } } diff --git a/tests/breakpoints.test.vim b/tests/breakpoints.test.vim index 9faf08e..1c36c08 100644 --- a/tests/breakpoints.test.vim +++ b/tests/breakpoints.test.vim @@ -246,3 +246,52 @@ function Test_DisableBreakpointWhileDebugging() lcd - %bwipeout! endfunction + +function! SetUp_Test_Insert_Code_Above_Breakpoint() + let g:vimspector_enable_mappings = 'HUMAN' +endfunction + +function! Test_Insert_Code_Above_Breakpoint() + let fn='main.py' + lcd ../support/test/python/simple_python + exe 'edit ' . fn + call setpos( '.', [ 0, 25, 5 ] ) + + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 25, 5 ) + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 25 ) + + " Add the breakpoint + call feedkeys( "\", 'xt' ) + call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP', + \ 25, + \ 'vimspectorBP' ) + + " Insert a line above the breakpoint + call append( 22, ' # Test' ) + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 5 ) + call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP', + \ 26, + \ 'vimspectorBP' ) + + " CHeck that we break at the right point + call setpos( '.', [ 0, 1, 1 ] ) + call vimspector#LaunchWithSettings( { "configuration": "run" } ) + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 ) + call vimspector#Reset() + call vimspector#test#setup#WaitForReset() + + " Toggle the breakpoint + call setpos( '.', [ 0, 26, 1 ] ) + call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP', + \ 26, + \ 'vimspectorBP' ) + call feedkeys( "\", 'xt' ) + call vimspector#test#signs#AssertSignGroupSingletonAtLine( + \ 'VimspectorBP', + \ 26, + \ 'vimspectorBPDisabled' ) + " Delete it + call feedkeys( "\", 'xt' ) + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 26 ) + +endfunction diff --git a/tests/language_python.test.vim b/tests/language_python.test.vim index 5240fac..7bf95a8 100644 --- a/tests/language_python.test.vim +++ b/tests/language_python.test.vim @@ -6,11 +6,11 @@ function! ClearDown() call vimspector#test#setup#ClearDown() endfunction -function! SetUp_Test_Go_Simple() +function! SetUp_Test_Python_Simple() let g:vimspector_enable_mappings = 'HUMAN' endfunction -function! Test_Go_Simple() +function! Test_Python_Simple() let fn='main.py' lcd ../support/test/python/simple_python exe 'edit ' . fn @@ -28,16 +28,8 @@ function! Test_Go_Simple() call setpos( '.', [ 0, 1, 1 ] ) " Here we go. Start Debugging - pyx << EOF -from unittest.mock import patch -with patch( 'vimspector.utils.SelectFromList', - return_value=None ) as p: - with patch( 'vimspector.utils.AskForInput', - return_value=None ) as p: - vim.eval( 'vimspector#LaunchWithSettings( { "configuration": "run" } )' ) - vim.eval( 'vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 6, 1 )' ) - p.assert_called() -EOF + call vimspector#LaunchWithSettings( { "configuration": "run" } ) + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 6, 1 ) " Step call feedkeys( "\", 'xt' ) diff --git a/tests/lib/autoload/vimspector/test/setup.vim b/tests/lib/autoload/vimspector/test/setup.vim index a1df8d5..6610647 100644 --- a/tests/lib/autoload/vimspector/test/setup.vim +++ b/tests/lib/autoload/vimspector/test/setup.vim @@ -16,8 +16,7 @@ endfunction function! vimspector#test#setup#ClearDown() abort endfunction -function! vimspector#test#setup#Reset() abort - call vimspector#Reset() +function! vimspector#test#setup#WaitForReset() abort call WaitForAssert( {-> \ assert_true( pyxeval( '_vimspector_session._connection is None' ) ) \ } ) @@ -26,6 +25,12 @@ function! vimspector#test#setup#Reset() abort \ }, 10000 ) call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorCode' ) +endfunction + +function! vimspector#test#setup#Reset() abort + call vimspector#Reset() + call vimspector#test#setup#WaitForReset() + call vimspector#ClearBreakpoints() call vimspector#test#signs#AssertSignGroupEmpty( 'VimspectorBP' )