Add ClearBreakpoints API

Add a test which actually triggers the mappings and fires up vimspector
with the cpptools debugger.
This commit is contained in:
Ben Jackson 2019-04-28 09:35:59 +01:00
commit 470c64603a
11 changed files with 155 additions and 19 deletions

View file

@ -31,6 +31,10 @@ function! Test_Mappings_Are_Added_HUMAN()
call assert_true( hasmapto( 'vimspector#StepOut()' ) )
endfunction
function! SetUp_Test_Mappings_Are_Added_VISUAL_STUDIO()
let g:vimspector_enable_mappings = 'VISUAL_STUDIO'
endfunction
function! Test_Mappings_Are_Added_VISUAL_STUDIO()
call assert_true( hasmapto( 'vimspector#Continue()' ) )
call assert_false( hasmapto( 'vimspector#Launch()' ) )
@ -49,8 +53,8 @@ endfunction
function! Test_Signs_Placed_Using_API_Are_Shown()
" We need a real file
edit testdata/cpp/simple.cpp
call feedkeys( '/printf<CR>' )
edit testdata/cpp/simple/simple.cpp
call feedkeys( "/printf\<CR>", 'x' )
" Set breakpoint
call vimspector#ToggleBreakpoint()
@ -62,9 +66,9 @@ function! Test_Signs_Placed_Using_API_Are_Shown()
\ 'line': line( '.' )
\ } )
call assert_true( len( signs ) == 1 )
call assert_true( len( signs[ 0 ].signs ) == 1 )
call assert_true( signs[ 0 ].signs[ 0 ].name == 'vimspectorBP' )
call assert_equal( 1, len( signs ) )
call assert_equal( 1, len( signs[ 0 ].signs ) )
call assert_equal( 'vimspectorBP', signs[ 0 ].signs[ 0 ].name )
" Disable breakpoint
call vimspector#ToggleBreakpoint()
@ -74,9 +78,9 @@ function! Test_Signs_Placed_Using_API_Are_Shown()
\ 'line': line( '.' )
\ } )
call assert_true( len( signs ) == 1 )
call assert_true( len( signs[ 0 ].signs ) == 1 )
call assert_true( signs[ 0 ].signs[ 0 ].name == 'vimspectorBPDisabled' )
call assert_equal( 1, len( signs ) )
call assert_equal( 1, len( signs[ 0 ].signs ) )
call assert_equal( 'vimspectorBPDisabled', signs[ 0 ].signs[ 0 ].name )
" Remove breakpoint
call vimspector#ToggleBreakpoint()
@ -86,8 +90,76 @@ function! Test_Signs_Placed_Using_API_Are_Shown()
\ 'line': line( '.' )
\ } )
call assert_true( len( signs ) == 1 )
call assert_true( len( signs[ 0 ].signs ) == 0 )
call assert_equal( 1, len( signs ) )
call assert_equal( 0, len( signs[ 0 ].signs ) )
" TODO: Use the screen dump test ?
call vimspector#ClearBreakpoints()
bwipeout!
endfunction
function! SetUp_Test_Use_Mappings_HUMAN()
let g:vimspector_enable_mappings = 'HUMAN'
endfunction
function! Test_Use_Mappings_HUMAN()
lcd testdata/cpp/simple
edit simple.cpp
15
call assert_equal( 15, line( '.' ) )
" Add the breakpoing
call feedkeys( "\<F9>", 'x' )
let signs = sign_getplaced( '.', {
\ 'group': 'VimspectorBP',
\ 'line': line( '.' )
\ } )
call assert_equal( 1, len( signs ), 1 )
call assert_equal( 1, len( signs[ 0 ].signs ), 1 )
call assert_equal( 'vimspectorBP', signs[ 0 ].signs[ 0 ].name )
" Disable the breakpoint
call feedkeys( "\<F9>", 'x' )
let signs = sign_getplaced( '.', {
\ 'group': 'VimspectorBP',
\ 'line': line( '.' )
\ } )
call assert_equal( 1, len( signs ), 1 )
call assert_equal( 1, len( signs[ 0 ].signs ), 1 )
call assert_equal( 'vimspectorBPDisabled', signs[ 0 ].signs[ 0 ].name )
" Delete the breakpoint
call feedkeys( "\<F9>", 'x' )
let signs = sign_getplaced( '.', {
\ 'group': 'VimspectorBP',
\ 'line': line( '.' )
\ } )
call assert_equal( 1, len( signs ), 1 )
call assert_equal( 0, len( signs[ 0 ].signs ) )
" Add it again
call feedkeys( "\<F9>", 'x' )
let signs = sign_getplaced( '.', {
\ 'group': 'VimspectorBP',
\ 'line': line( '.' )
\ } )
call assert_equal( 1, len( signs ), 1 )
call assert_equal( 1, len( signs[ 0 ].signs ), 1 )
call assert_equal( 'vimspectorBP', signs[ 0 ].signs[ 0 ].name )
" Here we go. Start Debugging
call feedkeys( "\<F5>", 'x' )
call vimspector#Reset()
call vimspector#ClearBreakpoints()
lcd -
bwipeout!
endfunction

View file

@ -1,7 +0,0 @@
#include <iostream>
int main( int argc, char ** )
{
printf( "this is a test %d", argc );
return 0;
}

1
tests/testdata/cpp/simple/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
simple

View file

@ -0,0 +1,18 @@
{
"configurations": {
"cpptools-run": {
"adapter": "vscode-cpptools",
"configuration": {
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/simple",
"args": [],
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"stopAtEntry": true,
"MImode": "${VIMSPECTOR_MIMODE}"
}
}
}
}

7
tests/testdata/cpp/simple/Makefile vendored Normal file
View file

@ -0,0 +1,7 @@
CXXFLAGS=-g -O0
simple: simple.cpp
clean:
rm -f simple
rm -rf simple.dSYM

18
tests/testdata/cpp/simple/simple.cpp vendored Normal file
View file

@ -0,0 +1,18 @@
#include <iostream>
namespace
{
void foo( int bar )
{
int unused;
printf( "%d\n", bar );
}
}
int main( int argc, char ** )
{
printf( "this is a test %d\n", argc );
foo( argc );
return 0;
}