From 727214c599749cffe30bcaabff368ec9af4d1194 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sat, 11 Jul 2020 21:59:28 +0100 Subject: [PATCH] Add a bunch of tests for the ui customisation --- azure-pipelines.yml | 4 +- compiler/vimspector_test.vim | 6 +- python3/vimspector/code.py | 3 + run_tests | 27 ++- tests/ui.test.vim | 326 +++++++++++++++++++++++++++++++++++ tests/vimrc | 1 + 6 files changed, 354 insertions(+), 13 deletions(-) create mode 100644 tests/ui.test.vim diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5dc944a..1eeb1c4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -62,7 +62,7 @@ stages: displayName: 'Run the tests' env: VIMSPECTOR_MIMODE: gdb - VIMSPECTOR_TEST_STDOUT: true + VIMSPECTOR_TEST_STDOUT: all - bash: ./make_package linux $(Build.SourceVersion) displayName: 'Package' @@ -107,7 +107,7 @@ stages: displayName: 'Run the tests' env: VIMSPECTOR_MIMODE: lldb - VIMSPECTOR_TEST_STDOUT: true + VIMSPECTOR_TEST_STDOUT: all - bash: ./make_package macos $(Build.SourceVersion) displayName: 'Package' diff --git a/compiler/vimspector_test.vim b/compiler/vimspector_test.vim index 8ccd734..5264b4b 100644 --- a/compiler/vimspector_test.vim +++ b/compiler/vimspector_test.vim @@ -92,7 +92,7 @@ function! s:RunTestUnderCursor() let l:cwd = getcwd() execute 'lcd ' . s:root_dir try - execute s:make_cmd . ' ' + execute s:make_cmd . ' --report messages ' \ . get( g:, 'vimspector_test_args', '' ) . ' ' \ . l:test_arg finally @@ -105,7 +105,7 @@ function! s:RunTest() let l:cwd = getcwd() execute 'lcd ' . s:root_dir try - execute s:make_cmd . ' ' + execute s:make_cmd . ' --report messages ' \ . get( g:, 'vimspector_test_args', '' ) \ . ' %:p:t' finally @@ -118,7 +118,7 @@ function! s:RunAllTests() let l:cwd = getcwd() execute 'lcd ' . s:root_dir try - execute s:make_cmd . ' ' + execute s:make_cmd . ' --report messages ' \ . get( g:, 'vimspector_test_args', '' ) finally execute 'lcd ' . l:cwd diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index b826d21..cadd50b 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -258,5 +258,8 @@ class CodeView( object ): else: self._terminal_window = terminal_window self._terminal_buffer_number = buffer_number + vim.vars[ 'vimspector_session_windows' ][ 'terminal' ] = utils.WindowID( + self._terminal_window, + vim.current.tabpage ) return buffer_number diff --git a/run_tests b/run_tests index 7ff2ebd..7c7fc59 100755 --- a/run_tests +++ b/run_tests @@ -3,8 +3,9 @@ if [ "$1" == "--help" ]; then echo "$(basename $0) [--basedir ] [--install] " echo "" - echo " --basedir path to runtime directory like the optino to install_gadget.py" - echo " --install run install_gadget.py, useful with --basedir" + echo " --basedir path to runtime directory like the optino to install_gadget.py" + echo " --install run install_gadget.py, useful with --basedir" + echo " --report how verbose to be with stdout" echo "e.g.: " echo " - run all tests: $0" echo " - run specific tests script: $0 signature_help.test.vim" @@ -23,19 +24,24 @@ BASEDIR_CMD='py3 pass' while [ -n "$1" ]; do case "$1" in "--basedir") - BASEDIR=$2 + shift + BASEDIR=$1 + shift if [[ ! $BASEDIR = /* ]]; then # Relative BASEDIR=$(pwd)/${BASEDIR} fi BASEDIR_CMD="let g:vimspector_base_dir='${BASEDIR}'" - shift - shift ;; "--install") INSTALL=1 shift ;; + "--report") + shift + VIMSPECTOR_TEST_STDOUT=$1 + shift + ;; "--") shift break @@ -109,10 +115,16 @@ for t in ${TESTS}; do rm -rf $TESTLOGDIR mkdir -p $TESTLOGDIR ${RUN_VIM} --version > ${TESTLOGDIR}/vimversion + if [ "$VIMSPECTOR_TEST_STDOUT" = "messages" ]; then + if [ -f messages ]; then + cat messages + fi + fi + for l in messages debuglog test.log *.testlog; do # In CI we can't view the output files, so we just have to cat them if [ -f $l ]; then - if [ "$VIMSPECTOR_TEST_STDOUT" ]; then + if [ "$VIMSPECTOR_TEST_STDOUT" = "all" ]; then echo "" echo "" echo "*** START: $l ***" @@ -130,7 +142,6 @@ echo "Done running tests" popd > /dev/null echo "" -echo "All done." - +echo "All done. Exit with ${RESULT}" exit $RESULT diff --git a/tests/ui.test.vim b/tests/ui.test.vim new file mode 100644 index 0000000..ec1bc4c --- /dev/null +++ b/tests/ui.test.vim @@ -0,0 +1,326 @@ +let s:fn='main.py' + +function! SetUp() + call vimspector#test#setup#SetUpWithMappings( 'HUMAN' ) +endfunction + +function! ClearDown() + call vimspector#test#setup#ClearDown() +endfunction + +function! s:StartDebugging() + lcd ../support/test/python/simple_python + exe 'edit ' . s:fn + call setpos( '.', [ 0, 23, 1 ] ) + call vimspector#ToggleBreakpoint() + call vimspector#LaunchWithSettings( { 'configuration': 'run' } ) + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 23, 1 ) +endfunction + +function! Test_StandardLayout() + call s:StartDebugging() + + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 25, 1 ) + + call assert_equal( + \ [ 'row', [ + \ [ 'col', [ + \ [ 'leaf', g:vimspector_session_windows.variables ], + \ [ 'leaf', g:vimspector_session_windows.watches ], + \ [ 'leaf', g:vimspector_session_windows.stack_trace ], + \ ] ], + \ [ 'col', [ + \ [ 'row', [ + \ [ 'leaf', g:vimspector_session_windows.code ], + \ [ 'leaf', g:vimspector_session_windows.terminal ], + \ ] ], + \ [ 'leaf', g:vimspector_session_windows.output ], + \ ] ] + \ ] ], + \ winlayout( g:vimspector_session_windows.tabpage ) ) + + call vimspector#test#setup#Reset() + %bwipe! +endfunction + +function! Test_CloseVariables() + call s:StartDebugging() + + call win_execute( g:vimspector_session_windows.variables, 'q' ) + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 25, 1 ) + + call assert_equal( + \ [ 'row', [ + \ [ 'col', [ + \ [ 'leaf', g:vimspector_session_windows.watches ], + \ [ 'leaf', g:vimspector_session_windows.stack_trace ], + \ ] ], + \ [ 'col', [ + \ [ 'row', [ + \ [ 'leaf', g:vimspector_session_windows.code ], + \ [ 'leaf', g:vimspector_session_windows.terminal ], + \ ] ], + \ [ 'leaf', g:vimspector_session_windows.output ], + \ ] ] + \ ] ], + \ winlayout( g:vimspector_session_windows.tabpage ) ) + + call vimspector#test#setup#Reset() + %bwipe! +endfunction + +function! Test_CloseWatches() + call s:StartDebugging() + + call win_execute( g:vimspector_session_windows.watches, 'q' ) + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 25, 1 ) + + " Add a wtch + call vimspector#AddWatch( 't' ) + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 26, 1 ) + + call assert_equal( + \ [ 'row', [ + \ [ 'col', [ + \ [ 'leaf', g:vimspector_session_windows.variables ], + \ [ 'leaf', g:vimspector_session_windows.stack_trace ], + \ ] ], + \ [ 'col', [ + \ [ 'row', [ + \ [ 'leaf', g:vimspector_session_windows.code ], + \ [ 'leaf', g:vimspector_session_windows.terminal ], + \ ] ], + \ [ 'leaf', g:vimspector_session_windows.output ], + \ ] ] + \ ] ], + \ winlayout( g:vimspector_session_windows.tabpage ) ) + + " Replace the variables view with a watches view! + call win_execute( g:vimspector_session_windows.variables, + \ 'bu vimspector.Watches' ) + + " Delete a watch expression + call win_gotoid( g:vimspector_session_windows.variables ) + call setpos( '.', [ 0, 3, 1 ] ) + call feedkeys( "\", 'xt' ) + + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ 'Watches: ----', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + + call vimspector#StepInto() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 13, 1 ) + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 14, 1 ) + call vimspector#AddWatch( 'i' ) + + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ 'Watches: ----', + \ 'Expression: i', + \ ' *- Result: 0', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + call vimspector#AddWatch( 'i+1' ) + + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ 'Watches: ----', + \ 'Expression: i', + \ ' - Result: 0', + \ 'Expression: i+1', + \ ' *- Result: 1', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + call vimspector#AddWatch( 'i+2' ) + + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ 'Watches: ----', + \ 'Expression: i', + \ ' - Result: 0', + \ 'Expression: i+1', + \ ' - Result: 1', + \ 'Expression: i+2', + \ ' *- Result: 2', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + " Delete that middle watch + call win_gotoid( g:vimspector_session_windows.variables ) + call setpos( '.', [ 0, 4, 1 ] ) + call vimspector#DeleteWatch() + + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ 'Watches: ----', + \ 'Expression: i', + \ ' - Result: 0', + \ 'Expression: i+2', + \ ' *- Result: 2', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 15, 1 ) + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ 'Watches: ----', + \ 'Expression: i', + \ ' - Result: 0', + \ 'Expression: i+2', + \ ' - Result: 2', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + " Delete the top watch + call win_gotoid( g:vimspector_session_windows.variables ) + call setpos( '.', [ 0, 3, 1 ] ) + call vimspector#DeleteWatch() + + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 13, 1 ) + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 14, 1 ) + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ 'Watches: ----', + \ 'Expression: i+2', + \ ' *- Result: 3', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + call vimspector#test#setup#Reset() + %bwipe! +endfunction + +function! Test_CloseStackTrace() + call s:StartDebugging() + + call win_execute( g:vimspector_session_windows.stack_trace, 'q' ) + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 25, 1 ) + + call assert_equal( + \ [ 'row', [ + \ [ 'col', [ + \ [ 'leaf', g:vimspector_session_windows.variables ], + \ [ 'leaf', g:vimspector_session_windows.watches ], + \ ] ], + \ [ 'col', [ + \ [ 'row', [ + \ [ 'leaf', g:vimspector_session_windows.code ], + \ [ 'leaf', g:vimspector_session_windows.terminal ], + \ ] ], + \ [ 'leaf', g:vimspector_session_windows.output ], + \ ] ] + \ ] ], + \ winlayout( g:vimspector_session_windows.tabpage ) ) + + call vimspector#test#setup#Reset() + %bwipe! +endfunction + +function! Test_CloseOutput() + call s:StartDebugging() + + call win_execute( g:vimspector_session_windows.output, 'q' ) + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 25, 1 ) + + call assert_equal( + \ [ 'row', [ + \ [ 'col', [ + \ [ 'leaf', g:vimspector_session_windows.variables ], + \ [ 'leaf', g:vimspector_session_windows.watches ], + \ [ 'leaf', g:vimspector_session_windows.stack_trace ], + \ ] ], + \ [ 'leaf', g:vimspector_session_windows.code ], + \ [ 'leaf', g:vimspector_session_windows.terminal ], + \ ] ], + \ winlayout( g:vimspector_session_windows.tabpage ) ) + + call vimspector#test#setup#Reset() + %bwipe! +endfunction + +function! Test_CustomUI() + augroup TestCustomUI + au! + au User VimspectorUICreated + \ call win_execute( g:vimspector_session_windows.watches, 'q' ) + augroup END + + call s:StartDebugging() + + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 25, 1 ) + + " Add a watch + call vimspector#AddWatch( 't' ) + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 26, 1 ) + + call assert_equal( + \ [ 'row', [ + \ [ 'col', [ + \ [ 'leaf', g:vimspector_session_windows.variables ], + \ [ 'leaf', g:vimspector_session_windows.stack_trace ], + \ ] ], + \ [ 'col', [ + \ [ 'row', [ + \ [ 'leaf', g:vimspector_session_windows.code ], + \ [ 'leaf', g:vimspector_session_windows.terminal ], + \ ] ], + \ [ 'leaf', g:vimspector_session_windows.output ], + \ ] ] + \ ] ], + \ winlayout( g:vimspector_session_windows.tabpage ) ) + + au! TestCustomUI + call vimspector#test#setup#Reset() + %bwipe! +endfunction diff --git a/tests/vimrc b/tests/vimrc index e845f78..e362824 100644 --- a/tests/vimrc +++ b/tests/vimrc @@ -1,5 +1,6 @@ let g:vimspector_test_plugin_path = expand( ':p:h:h' ) set mouse=a +set noequalalways let &rtp = &rtp . ',' . g:vimspector_test_plugin_path