forked from aniani/vim
patch 8.2.0511: Cscope code not fully tested
Problem: Cscope code not fully tested. Solution: Add more test cases. (Dominique Pelle, closes #5886)
This commit is contained in:
@@ -23,7 +23,7 @@ endfunc
|
|||||||
|
|
||||||
func Test_cscopeWithCscopeConnections()
|
func Test_cscopeWithCscopeConnections()
|
||||||
call CscopeSetupOrClean(1)
|
call CscopeSetupOrClean(1)
|
||||||
" Test 0: E568: duplicate cscope database not added
|
" Test: E568: duplicate cscope database not added
|
||||||
try
|
try
|
||||||
set nocscopeverbose
|
set nocscopeverbose
|
||||||
cscope add Xcscope.out
|
cscope add Xcscope.out
|
||||||
@@ -34,44 +34,49 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
call assert_fails('cscope add', 'E560')
|
call assert_fails('cscope add', 'E560')
|
||||||
call assert_fails('cscope add Xcscope.out', 'E568')
|
call assert_fails('cscope add Xcscope.out', 'E568')
|
||||||
call assert_fails('cscope add doesnotexist.out', 'E563')
|
call assert_fails('cscope add doesnotexist.out', 'E563')
|
||||||
|
if has('unix')
|
||||||
|
call assert_fails('cscope add /dev/null', 'E564:')
|
||||||
|
endif
|
||||||
|
|
||||||
" Test 1: Find this C-Symbol
|
" Test: Find this C-Symbol
|
||||||
for cmd in ['cs find s main', 'cs find 0 main']
|
for cmd in ['cs find s main', 'cs find 0 main']
|
||||||
let a = execute(cmd)
|
let a = execute(cmd)
|
||||||
" Test 1.1 test where it moves the cursor
|
" Test where it moves the cursor
|
||||||
call assert_equal('main(void)', getline('.'))
|
call assert_equal('main(void)', getline('.'))
|
||||||
" Test 1.2 test the output of the :cs command
|
" Test the output of the :cs command
|
||||||
call assert_match('\n(1 of 1): <<main>> main(void )', a)
|
call assert_match('\n(1 of 1): <<main>> main(void )', a)
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Test 2: Find this definition
|
" Test: Find this definition
|
||||||
for cmd in ['cs find g test_mf_hash', 'cs find 1 test_mf_hash']
|
for cmd in ['cs find g test_mf_hash',
|
||||||
|
\ 'cs find 1 test_mf_hash',
|
||||||
|
\ 'cs find 1 test_mf_hash'] " leading space ignored.
|
||||||
exe cmd
|
exe cmd
|
||||||
call assert_equal(['', '/*', ' * Test mf_hash_*() functions.', ' */', ' static void', 'test_mf_hash(void)', '{'], getline(line('.')-5, line('.')+1))
|
call assert_equal(['', '/*', ' * Test mf_hash_*() functions.', ' */', ' static void', 'test_mf_hash(void)', '{'], getline(line('.')-5, line('.')+1))
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Test 3: Find functions called by this function
|
" Test: Find functions called by this function
|
||||||
for cmd in ['cs find d test_mf_hash', 'cs find 2 test_mf_hash']
|
for cmd in ['cs find d test_mf_hash', 'cs find 2 test_mf_hash']
|
||||||
let a = execute(cmd)
|
let a = execute(cmd)
|
||||||
call assert_match('\n(1 of 42): <<mf_hash_init>> mf_hash_init(&ht);', a)
|
call assert_match('\n(1 of 42): <<mf_hash_init>> mf_hash_init(&ht);', a)
|
||||||
call assert_equal(' mf_hash_init(&ht);', getline('.'))
|
call assert_equal(' mf_hash_init(&ht);', getline('.'))
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Test 4: Find functions calling this function
|
" Test: Find functions calling this function
|
||||||
for cmd in ['cs find c test_mf_hash', 'cs find 3 test_mf_hash']
|
for cmd in ['cs find c test_mf_hash', 'cs find 3 test_mf_hash']
|
||||||
let a = execute(cmd)
|
let a = execute(cmd)
|
||||||
call assert_match('\n(1 of 1): <<main>> test_mf_hash();', a)
|
call assert_match('\n(1 of 1): <<main>> test_mf_hash();', a)
|
||||||
call assert_equal(' test_mf_hash();', getline('.'))
|
call assert_equal(' test_mf_hash();', getline('.'))
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Test 5: Find this text string
|
" Test: Find this text string
|
||||||
for cmd in ['cs find t Bram', 'cs find 4 Bram']
|
for cmd in ['cs find t Bram', 'cs find 4 Bram']
|
||||||
let a = execute(cmd)
|
let a = execute(cmd)
|
||||||
call assert_match('(1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a)
|
call assert_match('(1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a)
|
||||||
call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.'))
|
call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.'))
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Test 6: Find this egrep pattern
|
" Test: Find this egrep pattern
|
||||||
" test all matches returned by cscope
|
" test all matches returned by cscope
|
||||||
for cmd in ['cs find e ^\#includ.', 'cs find 6 ^\#includ.']
|
for cmd in ['cs find e ^\#includ.', 'cs find 6 ^\#includ.']
|
||||||
let a = execute(cmd)
|
let a = execute(cmd)
|
||||||
@@ -84,7 +89,7 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
call assert_fails('cnext', 'E553:')
|
call assert_fails('cnext', 'E553:')
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Test 7: Find the same egrep pattern using lcscope this time.
|
" Test: Find the same egrep pattern using lcscope this time.
|
||||||
let a = execute('lcs find e ^\#includ.')
|
let a = execute('lcs find e ^\#includ.')
|
||||||
call assert_match('\n(1 of 3): <<<unknown>>> #include <assert.h>', a)
|
call assert_match('\n(1 of 3): <<<unknown>>> #include <assert.h>', a)
|
||||||
call assert_equal('#include <assert.h>', getline('.'))
|
call assert_equal('#include <assert.h>', getline('.'))
|
||||||
@@ -94,7 +99,7 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
call assert_equal('#include "memfile.c"', getline('.'))
|
call assert_equal('#include "memfile.c"', getline('.'))
|
||||||
call assert_fails('lnext', 'E553:')
|
call assert_fails('lnext', 'E553:')
|
||||||
|
|
||||||
" Test 8: Find this file
|
" Test: Find this file
|
||||||
for cmd in ['cs find f Xmemfile_test.c', 'cs find 7 Xmemfile_test.c']
|
for cmd in ['cs find f Xmemfile_test.c', 'cs find 7 Xmemfile_test.c']
|
||||||
enew
|
enew
|
||||||
let a = execute(cmd)
|
let a = execute(cmd)
|
||||||
@@ -102,7 +107,7 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
call assert_equal('Xmemfile_test.c', @%)
|
call assert_equal('Xmemfile_test.c', @%)
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Test 9: Find files #including this file
|
" Test: Find files #including this file
|
||||||
for cmd in ['cs find i assert.h', 'cs find 8 assert.h']
|
for cmd in ['cs find i assert.h', 'cs find 8 assert.h']
|
||||||
enew
|
enew
|
||||||
let a = execute(cmd)
|
let a = execute(cmd)
|
||||||
@@ -113,11 +118,11 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
call assert_equal('#include <assert.h>', getline('.'))
|
call assert_equal('#include <assert.h>', getline('.'))
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Test 10: Invalid find command
|
" Test: Invalid find command
|
||||||
call assert_fails('cs find x', 'E560:')
|
call assert_fails('cs find x', 'E560:')
|
||||||
|
|
||||||
if has('float')
|
if has('float')
|
||||||
" Test 11: Find places where this symbol is assigned a value
|
" Test: Find places where this symbol is assigned a value
|
||||||
" this needs a cscope >= 15.8
|
" this needs a cscope >= 15.8
|
||||||
" unfortunately, Travis has cscope version 15.7
|
" unfortunately, Travis has cscope version 15.7
|
||||||
let cscope_version = systemlist('cscope --version')[0]
|
let cscope_version = systemlist('cscope --version')[0]
|
||||||
@@ -137,17 +142,17 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Test 12: leading whitespace is not removed for cscope find text
|
" Test: leading whitespace is not removed for cscope find text
|
||||||
let a = execute('cscope find t test_mf_hash')
|
let a = execute('cscope find t test_mf_hash')
|
||||||
call assert_equal(['', '(1 of 1): <<<unknown>>> test_mf_hash();'], split(a, '\n', 1))
|
call assert_equal(['', '(1 of 1): <<<unknown>>> test_mf_hash();'], split(a, '\n', 1))
|
||||||
call assert_equal(' test_mf_hash();', getline('.'))
|
call assert_equal(' test_mf_hash();', getline('.'))
|
||||||
|
|
||||||
" Test 13: test with scscope
|
" Test: test with scscope
|
||||||
let a = execute('scs find t Bram')
|
let a = execute('scs find t Bram')
|
||||||
call assert_match('(1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a)
|
call assert_match('(1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a)
|
||||||
call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.'))
|
call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.'))
|
||||||
|
|
||||||
" Test 14: cscope help
|
" Test: cscope help
|
||||||
for cmd in ['cs', 'cs help', 'cs xxx']
|
for cmd in ['cs', 'cs help', 'cs xxx']
|
||||||
let a = execute(cmd)
|
let a = execute(cmd)
|
||||||
call assert_match('^cscope commands:\n', a)
|
call assert_match('^cscope commands:\n', a)
|
||||||
@@ -161,16 +166,16 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
let a = execute('scscope help')
|
let a = execute('scscope help')
|
||||||
call assert_match('This cscope command does not support splitting the window\.', a)
|
call assert_match('This cscope command does not support splitting the window\.', a)
|
||||||
|
|
||||||
" Test 15: reset connections
|
" Test: reset connections
|
||||||
let a = execute('cscope reset')
|
let a = execute('cscope reset')
|
||||||
call assert_match('\nAdded cscope database.*Xcscope.out (#0)', a)
|
call assert_match('\nAdded cscope database.*Xcscope.out (#0)', a)
|
||||||
call assert_match('\nAll cscope databases reset', a)
|
call assert_match('\nAll cscope databases reset', a)
|
||||||
|
|
||||||
" Test 16: cscope show
|
" Test: cscope show
|
||||||
let a = execute('cscope show')
|
let a = execute('cscope show')
|
||||||
call assert_match('\n 0 \d\+.*Xcscope.out\s*<none>', a)
|
call assert_match('\n 0 \d\+.*Xcscope.out\s*<none>', a)
|
||||||
|
|
||||||
" Test 17: cstag and 'csto' option
|
" Test: cstag and 'csto' option
|
||||||
set csto=0
|
set csto=0
|
||||||
let a = execute('cstag TEST_COUNT')
|
let a = execute('cstag TEST_COUNT')
|
||||||
call assert_match('(1 of 1): <<TEST_COUNT>> #define TEST_COUNT 50000', a)
|
call assert_match('(1 of 1): <<TEST_COUNT>> #define TEST_COUNT 50000', a)
|
||||||
@@ -182,7 +187,7 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
call assert_fails('cstag xxx', 'E257:')
|
call assert_fails('cstag xxx', 'E257:')
|
||||||
call assert_fails('cstag', 'E562:')
|
call assert_fails('cstag', 'E562:')
|
||||||
|
|
||||||
" Test 18: 'cst' option
|
" Test: 'cst' option
|
||||||
set nocst
|
set nocst
|
||||||
call assert_fails('tag TEST_COUNT', 'E426:')
|
call assert_fails('tag TEST_COUNT', 'E426:')
|
||||||
set cst
|
set cst
|
||||||
@@ -192,12 +197,24 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
let a = execute('tags')
|
let a = execute('tags')
|
||||||
call assert_match('1 1 TEST_COUNT\s\+\d\+\s\+#define index_to_key', a)
|
call assert_match('1 1 TEST_COUNT\s\+\d\+\s\+#define index_to_key', a)
|
||||||
|
|
||||||
" Test 19: this should trigger call to cs_print_tags()
|
" Test: 'cscoperelative'
|
||||||
|
call mkdir('Xcscoperelative')
|
||||||
|
cd Xcscoperelative
|
||||||
|
let a = execute('cs find g test_mf_hash')
|
||||||
|
call assert_notequal('test_mf_hash(void)', getline('.'))
|
||||||
|
set cscoperelative
|
||||||
|
let a = execute('cs find g test_mf_hash')
|
||||||
|
call assert_equal('test_mf_hash(void)', getline('.'))
|
||||||
|
set nocscoperelative
|
||||||
|
cd ..
|
||||||
|
call delete('Xcscoperelative', 'd')
|
||||||
|
|
||||||
|
" Test: this should trigger call to cs_print_tags()
|
||||||
" Unclear how to check result though, we just exercise the code.
|
" Unclear how to check result though, we just exercise the code.
|
||||||
set cst cscopequickfix=s0
|
set cst cscopequickfix=s0
|
||||||
call feedkeys(":cs find s main\<CR>", 't')
|
call feedkeys(":cs find s main\<CR>", 't')
|
||||||
|
|
||||||
" Test 20: cscope kill
|
" Test: cscope kill
|
||||||
call assert_fails('cscope kill 2', 'E261:')
|
call assert_fails('cscope kill 2', 'E261:')
|
||||||
call assert_fails('cscope kill xxx', 'E261:')
|
call assert_fails('cscope kill xxx', 'E261:')
|
||||||
|
|
||||||
@@ -214,20 +231,20 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
let a = execute('cscope kill -1')
|
let a = execute('cscope kill -1')
|
||||||
call assert_equal('', a)
|
call assert_equal('', a)
|
||||||
|
|
||||||
" Test 21: 'csprg' option
|
" Test: 'csprg' option
|
||||||
call assert_equal('cscope', &csprg)
|
call assert_equal('cscope', &csprg)
|
||||||
set csprg=doesnotexist
|
set csprg=doesnotexist
|
||||||
call assert_fails('cscope add Xcscope2.out', 'E609:')
|
call assert_fails('cscope add Xcscope2.out', 'E609:')
|
||||||
set csprg=cscope
|
set csprg=cscope
|
||||||
|
|
||||||
" Test 22: multiple cscope connections
|
" Test: multiple cscope connections
|
||||||
cscope add Xcscope.out
|
cscope add Xcscope.out
|
||||||
cscope add Xcscope2.out . -C
|
cscope add Xcscope2.out . -C
|
||||||
let a = execute('cscope show')
|
let a = execute('cscope show')
|
||||||
call assert_match('\n 0 \d\+.*Xcscope.out\s*<none>', a)
|
call assert_match('\n 0 \d\+.*Xcscope.out\s*<none>', a)
|
||||||
call assert_match('\n 1 \d\+.*Xcscope2.out\s*\.', a)
|
call assert_match('\n 1 \d\+.*Xcscope2.out\s*\.', a)
|
||||||
|
|
||||||
" Test 23: test Ex command line completion
|
" Test: test Ex command line completion
|
||||||
call feedkeys(":cs \<C-A>\<C-B>\"\<CR>", 'tx')
|
call feedkeys(":cs \<C-A>\<C-B>\"\<CR>", 'tx')
|
||||||
call assert_equal('"cs add find help kill reset show', @:)
|
call assert_equal('"cs add find help kill reset show', @:)
|
||||||
|
|
||||||
@@ -243,19 +260,26 @@ func Test_cscopeWithCscopeConnections()
|
|||||||
call feedkeys(":cs add Xcscope\<C-A>\<C-B>\"\<CR>", 'tx')
|
call feedkeys(":cs add Xcscope\<C-A>\<C-B>\"\<CR>", 'tx')
|
||||||
call assert_equal('"cs add Xcscope.out Xcscope2.out', @:)
|
call assert_equal('"cs add Xcscope.out Xcscope2.out', @:)
|
||||||
|
|
||||||
" Test 24: cscope_connection()
|
" Test: cscope_connection()
|
||||||
call assert_equal(cscope_connection(), 1)
|
call assert_equal(cscope_connection(), 1)
|
||||||
call assert_equal(cscope_connection(0, 'out'), 1)
|
call assert_equal(cscope_connection(0, 'out'), 1)
|
||||||
call assert_equal(cscope_connection(0, 'xxx'), 1)
|
call assert_equal(cscope_connection(0, 'xxx'), 1)
|
||||||
|
|
||||||
call assert_equal(cscope_connection(1, 'out'), 1)
|
call assert_equal(cscope_connection(1, 'out'), 1)
|
||||||
call assert_equal(cscope_connection(1, 'xxx'), 0)
|
call assert_equal(cscope_connection(1, 'xxx'), 0)
|
||||||
|
|
||||||
call assert_equal(cscope_connection(2, 'out'), 0)
|
call assert_equal(cscope_connection(2, 'out'), 0)
|
||||||
|
call assert_equal(cscope_connection(2, getcwd() .. '/Xcscope.out', 1), 1)
|
||||||
|
|
||||||
call assert_equal(cscope_connection(3, 'xxx', '..'), 0)
|
call assert_equal(cscope_connection(3, 'xxx', '..'), 0)
|
||||||
call assert_equal(cscope_connection(3, 'out', 'xxx'), 0)
|
call assert_equal(cscope_connection(3, 'out', 'xxx'), 0)
|
||||||
call assert_equal(cscope_connection(3, 'out', '.'), 1)
|
call assert_equal(cscope_connection(3, 'out', '.'), 1)
|
||||||
|
|
||||||
call assert_equal(cscope_connection(4, 'out', '.'), 0)
|
call assert_equal(cscope_connection(4, 'out', '.'), 0)
|
||||||
|
|
||||||
" CleanUp
|
call assert_equal(cscope_connection(5, 'out'), 0)
|
||||||
|
call assert_equal(cscope_connection(-1, 'out'), 0)
|
||||||
|
|
||||||
call CscopeSetupOrClean(0)
|
call CscopeSetupOrClean(0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -738,6 +738,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
511,
|
||||||
/**/
|
/**/
|
||||||
510,
|
510,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user