Skip to content

Commit edf634e

Browse files
committed
patch 7.4.2148
Problem: Not much testing for cscope. Solution: Add a test that uses the cscope program. (Christian Brabandt)
1 parent abb71fb commit edf634e

2 files changed

Lines changed: 128 additions & 1 deletion

File tree

src/testdir/test_cscope.vim

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Test for cscope commands.
22

3-
if !has('cscope')
3+
if !has('cscope') || !executable('cscope') || !has('quickfix')
44
finish
55
endif
66

@@ -13,3 +13,128 @@ func Test_cscopequickfix()
1313
call assert_fails('set cscopequickfix=s7', 'E474:')
1414
call assert_fails('set cscopequickfix=s-a', 'E474:')
1515
endfunc
16+
17+
func CscopeSetupOrClean(setup)
18+
if a:setup
19+
noa sp ../memfile_test.c
20+
saveas! Xmemfile_test.c
21+
call system('cscope -bk -fXcscope.out Xmemfile_test.c')
22+
cscope add Xcscope.out
23+
set cscopequickfix=s-,g-,d-,c-,t-,e-,f-,i-,a-
24+
else
25+
cscope kill -1
26+
for file in ['Xcscope.out', 'Xmemfile_test.c']
27+
call delete(file)
28+
endfor
29+
endif
30+
endfunc
31+
32+
func Test_cscope1()
33+
call CscopeSetupOrClean(1)
34+
" Test 0: E568: duplicate cscope database not added
35+
try
36+
set nocscopeverbose
37+
cscope add Xcscope.out
38+
set cscopeverbose
39+
catch
40+
call assert_true(0)
41+
endtry
42+
call assert_fails('cscope add Xcscope.out', 'E568')
43+
" Test 1: Find this C-Symbol
44+
let a=execute('cscope find s main')
45+
" Test 1.1 test where it moves the cursor
46+
call assert_equal('main(void)', getline('.'))
47+
" Test 1.2 test the output of the :cs command
48+
call assert_match('\n(1 of 1): <<main>> main(void )', a)
49+
50+
" Test 2: Find this definition
51+
cscope find g test_mf_hash
52+
call assert_equal(['', '/*', ' * Test mf_hash_*() functions.', ' */', ' static void', 'test_mf_hash(void)', '{'], getline(line('.')-5, line('.')+1))
53+
54+
" Test 3: Find functions called by this function
55+
let a=execute('cscope find d test_mf_hash')
56+
call assert_match('\n(1 of 42): <<mf_hash_init>> mf_hash_init(&ht);', a)
57+
call assert_equal(' mf_hash_init(&ht);', getline('.'))
58+
59+
" Test 4: Find functions calling this function
60+
let a=execute('cscope find c test_mf_hash')
61+
call assert_match('\n(1 of 1): <<main>> test_mf_hash();', a)
62+
call assert_equal(' test_mf_hash();', getline('.'))
63+
64+
" Test 5: Find this text string
65+
let a=execute('cscope find t Bram')
66+
call assert_match('(1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a)
67+
call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.'))
68+
69+
" Test 6: Find this egrep pattern
70+
" test all matches returned by cscope
71+
let a=execute('cscope find e ^\#includ.')
72+
call assert_match('\n(1 of 3): <<<unknown>>> #include <assert.h>', a)
73+
call assert_equal('#include <assert.h>', getline('.'))
74+
cnext
75+
call assert_equal('#include "main.c"', getline('.'))
76+
cnext
77+
call assert_equal('#include "memfile.c"', getline('.'))
78+
call assert_fails('cnext', 'E553')
79+
80+
" Test 7: Find this file
81+
enew
82+
let a=execute('cscope find f Xmemfile_test.c')
83+
call assert_match('\n"Xmemfile_test.c" 143L, 3137C', a)
84+
call assert_equal('Xmemfile_test.c', @%)
85+
86+
" Test 8: Find files #including this file
87+
enew
88+
let a=execute('cscope find i assert.h')
89+
call assert_equal(['','"Xmemfile_test.c" 143L, 3137C','(1 of 1): <<global>> #include <assert.h>'], split(a, '\n', 1))
90+
call assert_equal('#include <assert.h>', getline('.'))
91+
92+
" Test 9: Find places where this symbol is assigned a value
93+
" this needs a cscope >= 15.8
94+
" unfortunatly, Travis has cscope version 15.7
95+
let cscope_version=systemlist('cscope --version')[0]
96+
let cs_version=str2float(matchstr(cscope_version, '\d\+\(\.\d\+\)\?'))
97+
if cs_version >= 15.8
98+
let a=execute('cscope find a item')
99+
call assert_equal(['', '(1 of 4): <<test_mf_hash>> item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);'], split(a, '\n', 1))
100+
call assert_equal(' item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);', getline('.'))
101+
cnext
102+
call assert_equal(' item = mf_hash_find(&ht, key);', getline('.'))
103+
cnext
104+
call assert_equal(' item = mf_hash_find(&ht, key);', getline('.'))
105+
cnext
106+
call assert_equal(' item = mf_hash_find(&ht, key);', getline('.'))
107+
endif
108+
109+
" Test 10: leading whitespace is not removed for cscope find text
110+
let a=execute('cscope find t test_mf_hash')
111+
call assert_equal(['', '(1 of 1): <<<unknown>>> test_mf_hash();'], split(a, '\n', 1))
112+
call assert_equal(' test_mf_hash();', getline('.'))
113+
114+
" Test 11: cscope help
115+
let a=execute('cscope help')
116+
call assert_match('^cscope commands:\n', a)
117+
call assert_match('\nadd :', a)
118+
call assert_match('\nfind :', a)
119+
call assert_match('\nhelp : Show this message', a)
120+
call assert_match('\nkill : Kill a connection', a)
121+
call assert_match('\nreset: Reinit all connections', a)
122+
call assert_match('\nshow : Show connections', a)
123+
124+
" Test 12: reset connections
125+
let a=execute('cscope reset')
126+
call assert_match('\nAdded cscope database.*Xcscope.out (#0)', a)
127+
call assert_match('\nAll cscope databases reset', a)
128+
129+
" Test 13: cscope show
130+
let a=execute('cscope show')
131+
call assert_match('\n 0 \d\+.*Xcscope.out\s*<none>', a)
132+
133+
" Test 14: 'csprg' option
134+
call assert_equal('cscope', &csprg)
135+
136+
" CleanUp
137+
call CscopeSetupOrClean(0)
138+
endfunc
139+
140+
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ static char *(features[]) =
763763

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2148,
766768
/**/
767769
2147,
768770
/**/

0 commit comments

Comments
 (0)