@@ -23,7 +23,7 @@ endfunc
2323
2424func Test_cscopeWithCscopeConnections ()
2525 call CscopeSetupOrClean (1 )
26- " Test 0 : E568: duplicate cscope database not added
26+ " Test: E568: duplicate cscope database not added
2727 try
2828 set nocscopeverbose
2929 cscope add Xcscope.out
@@ -34,44 +34,49 @@ func Test_cscopeWithCscopeConnections()
3434 call assert_fails (' cscope add' , ' E560' )
3535 call assert_fails (' cscope add Xcscope.out' , ' E568' )
3636 call assert_fails (' cscope add doesnotexist.out' , ' E563' )
37+ if has (' unix' )
38+ call assert_fails (' cscope add /dev/null' , ' E564:' )
39+ endif
3740
38- " Test 1 : Find this C-Symbol
41+ " Test: Find this C-Symbol
3942 for cmd in [' cs find s main' , ' cs find 0 main' ]
4043 let a = execute (cmd)
41- " Test 1.1 test where it moves the cursor
44+ " Test where it moves the cursor
4245 call assert_equal (' main(void)' , getline (' .' ))
43- " Test 1.2 test the output of the :cs command
46+ " Test the output of the :cs command
4447 call assert_match (' \n(1 of 1): <<main>> main(void )' , a )
4548 endfor
4649
47- " Test 2: Find this definition
48- for cmd in [' cs find g test_mf_hash' , ' cs find 1 test_mf_hash' ]
50+ " Test: Find this definition
51+ for cmd in [' cs find g test_mf_hash' ,
52+ \ ' cs find 1 test_mf_hash' ,
53+ \ ' cs find 1 test_mf_hash' ] " leading space ignored.
4954 exe cmd
5055 call assert_equal ([' ' , ' /*' , ' * Test mf_hash_*() functions.' , ' */' , ' static void' , ' test_mf_hash(void)' , ' {' ], getline (line (' .' )-5 , line (' .' )+ 1 ))
5156 endfor
5257
53- " Test 3 : Find functions called by this function
58+ " Test: Find functions called by this function
5459 for cmd in [' cs find d test_mf_hash' , ' cs find 2 test_mf_hash' ]
5560 let a = execute (cmd)
5661 call assert_match (' \n(1 of 42): <<mf_hash_init>> mf_hash_init(&ht);' , a )
5762 call assert_equal (' mf_hash_init(&ht);' , getline (' .' ))
5863 endfor
5964
60- " Test 4 : Find functions calling this function
65+ " Test: Find functions calling this function
6166 for cmd in [' cs find c test_mf_hash' , ' cs find 3 test_mf_hash' ]
6267 let a = execute (cmd)
6368 call assert_match (' \n(1 of 1): <<main>> test_mf_hash();' , a )
6469 call assert_equal (' test_mf_hash();' , getline (' .' ))
6570 endfor
6671
67- " Test 5 : Find this text string
72+ " Test: Find this text string
6873 for cmd in [' cs find t Bram' , ' cs find 4 Bram' ]
6974 let a = execute (cmd)
7075 call assert_match (' (1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar' , a )
7176 call assert_equal (' * VIM - Vi IMproved by Bram Moolenaar' , getline (' .' ))
7277 endfor
7378
74- " Test 6 : Find this egrep pattern
79+ " Test: Find this egrep pattern
7580 " test all matches returned by cscope
7681 for cmd in [' cs find e ^\#includ.' , ' cs find 6 ^\#includ.' ]
7782 let a = execute (cmd)
@@ -84,7 +89,7 @@ func Test_cscopeWithCscopeConnections()
8489 call assert_fails (' cnext' , ' E553:' )
8590 endfor
8691
87- " Test 7 : Find the same egrep pattern using lcscope this time.
92+ " Test: Find the same egrep pattern using lcscope this time.
8893 let a = execute (' lcs find e ^\#includ.' )
8994 call assert_match (' \n(1 of 3): <<<unknown>>> #include <assert.h>' , a )
9095 call assert_equal (' #include <assert.h>' , getline (' .' ))
@@ -94,15 +99,15 @@ func Test_cscopeWithCscopeConnections()
9499 call assert_equal (' #include "memfile.c"' , getline (' .' ))
95100 call assert_fails (' lnext' , ' E553:' )
96101
97- " Test 8 : Find this file
102+ " Test: Find this file
98103 for cmd in [' cs find f Xmemfile_test.c' , ' cs find 7 Xmemfile_test.c' ]
99104 enew
100105 let a = execute (cmd)
101106 call assert_true (a = ~ ' "Xmemfile_test.c" \d\+L, \d\+C' )
102107 call assert_equal (' Xmemfile_test.c' , @% )
103108 endfor
104109
105- " Test 9 : Find files #including this file
110+ " Test: Find files #including this file
106111 for cmd in [' cs find i assert.h' , ' cs find 8 assert.h' ]
107112 enew
108113 let a = execute (cmd)
@@ -113,11 +118,11 @@ func Test_cscopeWithCscopeConnections()
113118 call assert_equal (' #include <assert.h>' , getline (' .' ))
114119 endfor
115120
116- " Test 10 : Invalid find command
121+ " Test: Invalid find command
117122 call assert_fails (' cs find x' , ' E560:' )
118123
119124 if has (' float' )
120- " Test 11 : Find places where this symbol is assigned a value
125+ " Test: Find places where this symbol is assigned a value
121126 " this needs a cscope >= 15.8
122127 " unfortunately, Travis has cscope version 15.7
123128 let cscope_version = systemlist (' cscope --version' )[0 ]
@@ -137,17 +142,17 @@ func Test_cscopeWithCscopeConnections()
137142 endif
138143 endif
139144
140- " Test 12 : leading whitespace is not removed for cscope find text
145+ " Test: leading whitespace is not removed for cscope find text
141146 let a = execute (' cscope find t test_mf_hash' )
142147 call assert_equal ([' ' , ' (1 of 1): <<<unknown>>> test_mf_hash();' ], split (a , ' \n' , 1 ))
143148 call assert_equal (' test_mf_hash();' , getline (' .' ))
144149
145- " Test 13 : test with scscope
150+ " Test: test with scscope
146151 let a = execute (' scs find t Bram' )
147152 call assert_match (' (1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar' , a )
148153 call assert_equal (' * VIM - Vi IMproved by Bram Moolenaar' , getline (' .' ))
149154
150- " Test 14 : cscope help
155+ " Test: cscope help
151156 for cmd in [' cs' , ' cs help' , ' cs xxx' ]
152157 let a = execute (cmd)
153158 call assert_match (' ^cscope commands:\n' , a )
@@ -161,16 +166,16 @@ func Test_cscopeWithCscopeConnections()
161166 let a = execute (' scscope help' )
162167 call assert_match (' This cscope command does not support splitting the window\.' , a )
163168
164- " Test 15 : reset connections
169+ " Test: reset connections
165170 let a = execute (' cscope reset' )
166171 call assert_match (' \nAdded cscope database.*Xcscope.out (#0)' , a )
167172 call assert_match (' \nAll cscope databases reset' , a )
168173
169- " Test 16 : cscope show
174+ " Test: cscope show
170175 let a = execute (' cscope show' )
171176 call assert_match (' \n 0 \d\+.*Xcscope.out\s*<none>' , a )
172177
173- " Test 17 : cstag and 'csto' option
178+ " Test: cstag and 'csto' option
174179 set csto = 0
175180 let a = execute (' cstag TEST_COUNT' )
176181 call assert_match (' (1 of 1): <<TEST_COUNT>> #define TEST_COUNT 50000' , a )
@@ -182,7 +187,7 @@ func Test_cscopeWithCscopeConnections()
182187 call assert_fails (' cstag xxx' , ' E257:' )
183188 call assert_fails (' cstag' , ' E562:' )
184189
185- " Test 18 : 'cst' option
190+ " Test: 'cst' option
186191 set nocst
187192 call assert_fails (' tag TEST_COUNT' , ' E426:' )
188193 set cst
@@ -192,12 +197,24 @@ func Test_cscopeWithCscopeConnections()
192197 let a = execute (' tags' )
193198 call assert_match (' 1 1 TEST_COUNT\s\+\d\+\s\+#define index_to_key' , a )
194199
195- " Test 19: this should trigger call to cs_print_tags()
200+ " Test: 'cscoperelative'
201+ call mkdir (' Xcscoperelative' )
202+ cd Xcscoperelative
203+ let a = execute (' cs find g test_mf_hash' )
204+ call assert_notequal (' test_mf_hash(void)' , getline (' .' ))
205+ set cscoperelative
206+ let a = execute (' cs find g test_mf_hash' )
207+ call assert_equal (' test_mf_hash(void)' , getline (' .' ))
208+ set nocscoperelative
209+ cd ..
210+ call delete (' Xcscoperelative' , ' d' )
211+
212+ " Test: this should trigger call to cs_print_tags()
196213 " Unclear how to check result though, we just exercise the code.
197214 set cst cscopequickfix = s0
198215 call feedkeys (" :cs find s main\<CR> " , ' t' )
199216
200- " Test 20 : cscope kill
217+ " Test: cscope kill
201218 call assert_fails (' cscope kill 2' , ' E261:' )
202219 call assert_fails (' cscope kill xxx' , ' E261:' )
203220
@@ -214,20 +231,20 @@ func Test_cscopeWithCscopeConnections()
214231 let a = execute (' cscope kill -1' )
215232 call assert_equal (' ' , a )
216233
217- " Test 21 : 'csprg' option
234+ " Test: 'csprg' option
218235 call assert_equal (' cscope' , &csprg )
219236 set csprg = doesnotexist
220237 call assert_fails (' cscope add Xcscope2.out' , ' E609:' )
221238 set csprg = cscope
222239
223- " Test 22 : multiple cscope connections
240+ " Test: multiple cscope connections
224241 cscope add Xcscope.out
225242 cscope add Xcscope2.out . - C
226243 let a = execute (' cscope show' )
227244 call assert_match (' \n 0 \d\+.*Xcscope.out\s*<none>' , a )
228245 call assert_match (' \n 1 \d\+.*Xcscope2.out\s*\.' , a )
229246
230- " Test 23 : test Ex command line completion
247+ " Test: test Ex command line completion
231248 call feedkeys (" :cs \<C-A>\<C-B> \" \<CR> " , ' tx' )
232249 call assert_equal (' "cs add find help kill reset show' , @: )
233250
@@ -243,19 +260,26 @@ func Test_cscopeWithCscopeConnections()
243260 call feedkeys (" :cs add Xcscope\<C-A>\<C-B> \" \<CR> " , ' tx' )
244261 call assert_equal (' "cs add Xcscope.out Xcscope2.out' , @: )
245262
246- " Test 24 : cscope_connection()
263+ " Test: cscope_connection()
247264 call assert_equal (cscope_connection (), 1 )
248265 call assert_equal (cscope_connection (0 , ' out' ), 1 )
249266 call assert_equal (cscope_connection (0 , ' xxx' ), 1 )
267+
250268 call assert_equal (cscope_connection (1 , ' out' ), 1 )
251269 call assert_equal (cscope_connection (1 , ' xxx' ), 0 )
270+
252271 call assert_equal (cscope_connection (2 , ' out' ), 0 )
272+ call assert_equal (cscope_connection (2 , getcwd () .. ' /Xcscope.out' , 1 ), 1 )
273+
253274 call assert_equal (cscope_connection (3 , ' xxx' , ' ..' ), 0 )
254275 call assert_equal (cscope_connection (3 , ' out' , ' xxx' ), 0 )
255276 call assert_equal (cscope_connection (3 , ' out' , ' .' ), 1 )
277+
256278 call assert_equal (cscope_connection (4 , ' out' , ' .' ), 0 )
257279
258- " CleanUp
280+ call assert_equal (cscope_connection (5 , ' out' ), 0 )
281+ call assert_equal (cscope_connection (-1 , ' out' ), 0 )
282+
259283 call CscopeSetupOrClean (0 )
260284endfunc
261285
0 commit comments