diff --git a/run_tests b/run_tests index 7c7fc59..d4b8218 100755 --- a/run_tests +++ b/run_tests @@ -77,7 +77,7 @@ echo " * BASEDIR_CMD=$BASEDIR_CMD" echo "%SETUP - Building test programs..." set -e pushd tests/testdata/cpp/simple - make clean simple + make clean all popd set +e echo "%DONE - built test programs" diff --git a/tests/lib/autoload/vimspector/test/setup.vim b/tests/lib/autoload/vimspector/test/setup.vim index d69acef..b0296e0 100644 --- a/tests/lib/autoload/vimspector/test/setup.vim +++ b/tests/lib/autoload/vimspector/test/setup.vim @@ -11,6 +11,12 @@ function! vimspector#test#setup#SetUpWithMappings( mappings ) abort " This is a bit of a hack runtime! plugin/**/*.vim + + augroup VimspectorTestSwap + au! + au SwapExists * let v:swapchoice = 'e' + augroup END + endfunction function! vimspector#test#setup#ClearDown() abort diff --git a/tests/lib/autoload/vimspector/test/signs.vim b/tests/lib/autoload/vimspector/test/signs.vim index 1ef7fc9..bd7a463 100644 --- a/tests/lib/autoload/vimspector/test/signs.vim +++ b/tests/lib/autoload/vimspector/test/signs.vim @@ -2,7 +2,9 @@ function! vimspector#test#signs#AssertCursorIsAtLineInBuffer( buffer, \ line, \ column ) abort call WaitForAssert( {-> - \ assert_equal( a:buffer, bufname( '%' ), 'Current buffer' ) + \ assert_equal( fnamemodify( a:buffer, ':p' ), + \ fnamemodify( bufname( '%' ), ':p' ), + \ 'Current buffer' ) \ }, 10000 ) call WaitForAssert( {-> \ assert_equal( a:line, line( '.' ), 'Current line' ) diff --git a/tests/testdata/cpp/simple/.gitignore b/tests/testdata/cpp/simple/.gitignore index ac54bdc..fec4c0b 100644 --- a/tests/testdata/cpp/simple/.gitignore +++ b/tests/testdata/cpp/simple/.gitignore @@ -1,2 +1,3 @@ simple variables +struct diff --git a/tests/testdata/cpp/simple/Makefile b/tests/testdata/cpp/simple/Makefile index 8583202..0e8d8c8 100644 --- a/tests/testdata/cpp/simple/Makefile +++ b/tests/testdata/cpp/simple/Makefile @@ -2,7 +2,7 @@ CXXFLAGS=-g -O0 -std=c++17 .PHONY: all -TARGETS=simple variables +TARGETS=simple variables struct all: $(TARGETS) diff --git a/tests/testdata/cpp/simple/struct.cpp b/tests/testdata/cpp/simple/struct.cpp new file mode 100644 index 0000000..ea55efc --- /dev/null +++ b/tests/testdata/cpp/simple/struct.cpp @@ -0,0 +1,33 @@ +struct AnotherTest +{ + char choo; + int ints[5]; +}; + +struct Test +{ + int i; + char c; + float fffff; + + AnotherTest another_test; +}; + +static Test SetUp( Test t ) +{ + t.another_test.choo = 'p'; + t.another_test.ints[ 0 ] = t.i; return t; +} + +int main( int , char ** ) +{ + Test t = {}; + + t.i = 1; + t.c = 'c'; + t.fffff = 3.14; + + t = SetUp( t ); + + return t.another_test.ints[ 0 ]; +} diff --git a/tests/ui.test.vim b/tests/ui.test.vim index ec1bc4c..07639e5 100644 --- a/tests/ui.test.vim +++ b/tests/ui.test.vim @@ -1,4 +1,4 @@ -let s:fn='main.py' +let s:fn='../support/test/python/simple_python/main.py' function! SetUp() call vimspector#test#setup#SetUpWithMappings( 'HUMAN' ) @@ -9,7 +9,6 @@ function! ClearDown() endfunction function! s:StartDebugging() - lcd ../support/test/python/simple_python exe 'edit ' . s:fn call setpos( '.', [ 0, 23, 1 ] ) call vimspector#ToggleBreakpoint() diff --git a/tests/variables.test.vim b/tests/variables.test.vim new file mode 100644 index 0000000..ad6f34d --- /dev/null +++ b/tests/variables.test.vim @@ -0,0 +1,343 @@ +let s:fn='../support/test/python/simple_python/main.py' + +function! SetUp() + call vimspector#test#setup#SetUpWithMappings( 'HUMAN' ) +endfunction + +function! ClearDown() + call vimspector#test#setup#ClearDown() +endfunction + +function! s:StartDebugging( ... ) + if a:0 == 0 + let config = #{ + \ fn: s:fn, + \ line: 23, + \ col: 1, + \ launch: #{ configuration: 'run' } + \ } + else + let config = a:1 + endif + + execute 'edit' config.fn + call setpos( '.', [ 0, config.line, config.col ] ) + call vimspector#ToggleBreakpoint() + call vimspector#LaunchWithSettings( config.launch ) + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( + \ config.fn, + \ config.line, + \ config.col ) +endfunction + +function! Test_SimpleWatches() + call s:StartDebugging() + + 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 ) + + " Delete a watch expression + call win_gotoid( g:vimspector_session_windows.watches ) + call setpos( '.', [ 0, 3, 1 ] ) + call feedkeys( "\", 'xt' ) + + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ 'Watches: ----', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.watches ), + \ 1, + \ '$' ) + \ ) + \ } ) + + call assert_equal( 'python', + \ getbufvar( + \ winbufnr( g:vimspector_session_windows.watches ), + \ '&syntax' ) ) + + 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.watches ), + \ 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.watches ), + \ 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.watches ), + \ 1, + \ '$' ) + \ ) + \ } ) + + " Delete that middle watch + call win_gotoid( g:vimspector_session_windows.watches ) + 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.watches ), + \ 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.watches ), + \ 1, + \ '$' ) + \ ) + \ } ) + + " Delete the top watch + call win_gotoid( g:vimspector_session_windows.watches ) + 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.watches ), + \ 1, + \ '$' ) + \ ) + \ } ) + call vimspector#test#setup#Reset() + %bwipe! +endfunction + +function! Test_ExpandWatch() + let fn = 'testdata/cpp/simple/struct.cpp' + " TODO: This stops at a different point on linux/gdb + call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{ + \ configuration: 'run-to-breakpoint' + \ } } ) + " Make sure the Test t is initialised + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 ) + + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ '- Scope: Locals', + \ ' *+ t (Test): {...}', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + call assert_equal( 'cpp', + \ getbufvar( + \ winbufnr( g:vimspector_session_windows.variables ), + \ '&syntax' ) ) + + " Expand + call win_gotoid( g:vimspector_session_windows.variables ) + call setpos( '.', [ 0, 2, 1 ] ) + call feedkeys( "\", 'xt' ) + + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ '- Scope: Locals', + \ ' *- t (Test): {...}', + \ ' *- i (int): 0', + \ " *- c (char): 0 '\\0'", + \ ' *- fffff (float): 0', + \ ' *+ another_test (AnotherTest): {...}', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + " Step - stays expanded + call vimspector#StepOver() + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ '- Scope: Locals', + \ ' - t (Test): {...}', + \ ' *- i (int): 1', + \ " - c (char): 0 '\\0'", + \ ' - fffff (float): 0', + \ ' + another_test (AnotherTest): {...}', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + " Collapse + call win_gotoid( g:vimspector_session_windows.variables ) + call setpos( '.', [ 0, 2, 1 ] ) + call feedkeys( "\", 'xt' ) + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ '- Scope: Locals', + \ ' + t (Test): {...}', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + call vimspector#StepOver() + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ '- Scope: Locals', + \ ' + t (Test): {...}', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + " Exapand - see that the changed value is highlighted + call win_gotoid( g:vimspector_session_windows.variables ) + call setpos( '.', [ 0, 2, 1 ] ) + call feedkeys( "\", 'xt' ) + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ '- Scope: Locals', + \ ' - t (Test): {...}', + \ ' - i (int): 1', + \ " *- c (char): 99 'c'", + \ ' - fffff (float): 0', + \ ' + another_test (AnotherTest): {...}', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + " Collapse the 'inexpensive' scope and see that it stays collapsed + " Exapand - see that the changed value is highlighted + call win_gotoid( g:vimspector_session_windows.variables ) + call setpos( '.', [ 0, 1, 1 ] ) + call feedkeys( "\", 'xt' ) + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ '+ Scope: Locals', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + " Stays collpased through step + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 30, 1 ) + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ '+ Scope: Locals', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + " Cpptools keeps the same "Locals" scope, so it stays collapsed even throught + " step-in + call vimspector#StepInto() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 18, 1 ) + call WaitForAssert( {-> + \ assert_equal( + \ [ + \ '+ Scope: Locals', + \ ], + \ getbufline( winbufnr( g:vimspector_session_windows.variables ), + \ 1, + \ '$' ) + \ ) + \ } ) + + call vimspector#test#setup#Reset() + %bwipe! +endfunction