Bram Moolenaar | 6d20e17 | 2016-07-13 22:44:12 +0200 | [diff] [blame] | 1 | " Test for cscope commands. |
| 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckFeature cscope |
| 5 | CheckFeature quickfix |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 6 | CheckExecutable cscope |
Bram Moolenaar | 6d20e17 | 2016-07-13 22:44:12 +0200 | [diff] [blame] | 7 | |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 8 | func CscopeSetupOrClean(setup) |
| 9 | if a:setup |
| 10 | noa sp ../memfile_test.c |
| 11 | saveas! Xmemfile_test.c |
| 12 | call system('cscope -bk -fXcscope.out Xmemfile_test.c') |
| 13 | call system('cscope -bk -fXcscope2.out Xmemfile_test.c') |
| 14 | cscope add Xcscope.out |
| 15 | set cscopequickfix=s-,g-,d-,c-,t-,e-,f-,i-,a- |
| 16 | else |
| 17 | cscope kill -1 |
| 18 | for file in ['Xcscope.out', 'Xcscope2.out', 'Xmemfile_test.c'] |
| 19 | call delete(file) |
| 20 | endfo |
| 21 | endif |
| 22 | endfunc |
| 23 | |
| 24 | func Test_cscopeWithCscopeConnections() |
| 25 | call CscopeSetupOrClean(1) |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 26 | " Test: E568: duplicate cscope database not added |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 27 | try |
| 28 | set nocscopeverbose |
| 29 | cscope add Xcscope.out |
| 30 | set cscopeverbose |
| 31 | catch |
Bram Moolenaar | 3717540 | 2017-03-18 20:18:45 +0100 | [diff] [blame] | 32 | call assert_report('exception thrown') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 33 | endtry |
| 34 | call assert_fails('cscope add', 'E560') |
| 35 | call assert_fails('cscope add Xcscope.out', 'E568') |
| 36 | call assert_fails('cscope add doesnotexist.out', 'E563') |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 37 | if has('unix') |
| 38 | call assert_fails('cscope add /dev/null', 'E564:') |
| 39 | endif |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 40 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 41 | " Test: Find this C-Symbol |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 42 | for cmd in ['cs find s main', 'cs find 0 main'] |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 43 | let a = execute(cmd) |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 44 | " Test where it moves the cursor |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 45 | call assert_equal('main(void)', getline('.')) |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 46 | " Test the output of the :cs command |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 47 | call assert_match('\n(1 of 1): <<main>> main(void )', a) |
| 48 | endfor |
| 49 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 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. |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 54 | exe cmd |
| 55 | call assert_equal(['', '/*', ' * Test mf_hash_*() functions.', ' */', ' static void', 'test_mf_hash(void)', '{'], getline(line('.')-5, line('.')+1)) |
| 56 | endfor |
| 57 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 58 | " Test: Find functions called by this function |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 59 | for cmd in ['cs find d test_mf_hash', 'cs find 2 test_mf_hash'] |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 60 | let a = execute(cmd) |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 61 | call assert_match('\n(1 of 42): <<mf_hash_init>> mf_hash_init(&ht);', a) |
| 62 | call assert_equal(' mf_hash_init(&ht);', getline('.')) |
| 63 | endfor |
| 64 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 65 | " Test: Find functions calling this function |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 66 | for cmd in ['cs find c test_mf_hash', 'cs find 3 test_mf_hash'] |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 67 | let a = execute(cmd) |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 68 | call assert_match('\n(1 of 1): <<main>> test_mf_hash();', a) |
| 69 | call assert_equal(' test_mf_hash();', getline('.')) |
| 70 | endfor |
| 71 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 72 | " Test: Find this text string |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 73 | for cmd in ['cs find t Bram', 'cs find 4 Bram'] |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 74 | let a = execute(cmd) |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 75 | call assert_match('(1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a) |
| 76 | call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.')) |
| 77 | endfor |
| 78 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 79 | " Test: Find this egrep pattern |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 80 | " test all matches returned by cscope |
| 81 | for cmd in ['cs find e ^\#includ.', 'cs find 6 ^\#includ.'] |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 82 | let a = execute(cmd) |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 83 | call assert_match('\n(1 of 3): <<<unknown>>> #include <assert.h>', a) |
| 84 | call assert_equal('#include <assert.h>', getline('.')) |
| 85 | cnext |
| 86 | call assert_equal('#include "main.c"', getline('.')) |
| 87 | cnext |
| 88 | call assert_equal('#include "memfile.c"', getline('.')) |
| 89 | call assert_fails('cnext', 'E553:') |
| 90 | endfor |
| 91 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 92 | " Test: Find the same egrep pattern using lcscope this time. |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 93 | let a = execute('lcs find e ^\#includ.') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 94 | call assert_match('\n(1 of 3): <<<unknown>>> #include <assert.h>', a) |
| 95 | call assert_equal('#include <assert.h>', getline('.')) |
| 96 | lnext |
| 97 | call assert_equal('#include "main.c"', getline('.')) |
| 98 | lnext |
| 99 | call assert_equal('#include "memfile.c"', getline('.')) |
| 100 | call assert_fails('lnext', 'E553:') |
| 101 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 102 | " Test: Find this file |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 103 | for cmd in ['cs find f Xmemfile_test.c', 'cs find 7 Xmemfile_test.c'] |
| 104 | enew |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 105 | let a = execute(cmd) |
Bram Moolenaar | 4792255 | 2016-08-30 10:56:50 +0200 | [diff] [blame] | 106 | call assert_true(a =~ '"Xmemfile_test.c" \d\+L, \d\+C') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 107 | call assert_equal('Xmemfile_test.c', @%) |
| 108 | endfor |
| 109 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 110 | " Test: Find files #including this file |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 111 | for cmd in ['cs find i assert.h', 'cs find 8 assert.h'] |
| 112 | enew |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 113 | let a = execute(cmd) |
Bram Moolenaar | 4792255 | 2016-08-30 10:56:50 +0200 | [diff] [blame] | 114 | let alines = split(a, '\n', 1) |
| 115 | call assert_equal('', alines[0]) |
| 116 | call assert_true(alines[1] =~ '"Xmemfile_test.c" \d\+L, \d\+C') |
| 117 | call assert_equal('(1 of 1): <<global>> #include <assert.h>', alines[2]) |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 118 | call assert_equal('#include <assert.h>', getline('.')) |
| 119 | endfor |
| 120 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 121 | " Test: Invalid find command |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 122 | call assert_fails('cs find x', 'E560:') |
| 123 | |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 124 | if has('float') |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 125 | " Test: Find places where this symbol is assigned a value |
Bram Moolenaar | 5feabe0 | 2020-01-30 18:24:53 +0100 | [diff] [blame] | 126 | " this needs a cscope >= 15.8 |
| 127 | " unfortunately, Travis has cscope version 15.7 |
| 128 | let cscope_version = systemlist('cscope --version')[0] |
| 129 | let cs_version = str2float(matchstr(cscope_version, '\d\+\(\.\d\+\)\?')) |
| 130 | if cs_version >= 15.8 |
| 131 | for cmd in ['cs find a item', 'cs find 9 item'] |
| 132 | let a = execute(cmd) |
| 133 | call assert_equal(['', '(1 of 4): <<test_mf_hash>> item = LALLOC_CLEAR_ONE(mf_hashitem_T);'], split(a, '\n', 1)) |
| 134 | call assert_equal(' item = LALLOC_CLEAR_ONE(mf_hashitem_T);', getline('.')) |
| 135 | cnext |
| 136 | call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) |
| 137 | cnext |
| 138 | call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) |
| 139 | cnext |
| 140 | call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) |
| 141 | endfor |
| 142 | endif |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 143 | endif |
| 144 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 145 | " Test: leading whitespace is not removed for cscope find text |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 146 | let a = execute('cscope find t test_mf_hash') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 147 | call assert_equal(['', '(1 of 1): <<<unknown>>> test_mf_hash();'], split(a, '\n', 1)) |
| 148 | call assert_equal(' test_mf_hash();', getline('.')) |
| 149 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 150 | " Test: test with scscope |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 151 | let a = execute('scs find t Bram') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 152 | call assert_match('(1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a) |
| 153 | call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.')) |
| 154 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 155 | " Test: cscope help |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 156 | for cmd in ['cs', 'cs help', 'cs xxx'] |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 157 | let a = execute(cmd) |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 158 | call assert_match('^cscope commands:\n', a) |
| 159 | call assert_match('\nadd :', a) |
| 160 | call assert_match('\nfind :', a) |
| 161 | call assert_match('\nhelp : Show this message', a) |
| 162 | call assert_match('\nkill : Kill a connection', a) |
| 163 | call assert_match('\nreset: Reinit all connections', a) |
| 164 | call assert_match('\nshow : Show connections', a) |
| 165 | endfor |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 166 | let a = execute('scscope help') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 167 | call assert_match('This cscope command does not support splitting the window\.', a) |
| 168 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 169 | " Test: reset connections |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 170 | let a = execute('cscope reset') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 171 | call assert_match('\nAdded cscope database.*Xcscope.out (#0)', a) |
| 172 | call assert_match('\nAll cscope databases reset', a) |
| 173 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 174 | " Test: cscope show |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 175 | let a = execute('cscope show') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 176 | call assert_match('\n 0 \d\+.*Xcscope.out\s*<none>', a) |
| 177 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 178 | " Test: cstag and 'csto' option |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 179 | set csto=0 |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 180 | let a = execute('cstag TEST_COUNT') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 181 | call assert_match('(1 of 1): <<TEST_COUNT>> #define TEST_COUNT 50000', a) |
| 182 | call assert_equal('#define TEST_COUNT 50000', getline('.')) |
| 183 | set csto=1 |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 184 | let a = execute('cstag index_to_key') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 185 | call assert_match('(1 of 1): <<index_to_key>> #define index_to_key(i) ((i) ^ 15167)', a) |
| 186 | call assert_equal('#define index_to_key(i) ((i) ^ 15167)', getline('.')) |
| 187 | call assert_fails('cstag xxx', 'E257:') |
| 188 | call assert_fails('cstag', 'E562:') |
| 189 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 190 | " Test: 'cst' option |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 191 | set nocst |
| 192 | call assert_fails('tag TEST_COUNT', 'E426:') |
| 193 | set cst |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 194 | let a = execute('tag TEST_COUNT') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 195 | call assert_match('(1 of 1): <<TEST_COUNT>> #define TEST_COUNT 50000', a) |
| 196 | call assert_equal('#define TEST_COUNT 50000', getline('.')) |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 197 | let a = execute('tags') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 198 | call assert_match('1 1 TEST_COUNT\s\+\d\+\s\+#define index_to_key', a) |
| 199 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 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() |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 213 | " Unclear how to check result though, we just exercise the code. |
| 214 | set cst cscopequickfix=s0 |
| 215 | call feedkeys(":cs find s main\<CR>", 't') |
| 216 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 217 | " Test: cscope kill |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 218 | call assert_fails('cscope kill 2', 'E261:') |
| 219 | call assert_fails('cscope kill xxx', 'E261:') |
| 220 | |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 221 | let a = execute('cscope kill 0') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 222 | call assert_match('cscope connection 0 closed', a) |
| 223 | |
| 224 | cscope add Xcscope.out |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 225 | let a = execute('cscope kill Xcscope.out') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 226 | call assert_match('cscope connection Xcscope.out closed', a) |
| 227 | |
| 228 | cscope add Xcscope.out . |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 229 | let a = execute('cscope kill -1') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 230 | call assert_match('cscope connection .*Xcscope.out closed', a) |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 231 | let a = execute('cscope kill -1') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 232 | call assert_equal('', a) |
| 233 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 234 | " Test: 'csprg' option |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 235 | call assert_equal('cscope', &csprg) |
| 236 | set csprg=doesnotexist |
| 237 | call assert_fails('cscope add Xcscope2.out', 'E609:') |
| 238 | set csprg=cscope |
| 239 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 240 | " Test: multiple cscope connections |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 241 | cscope add Xcscope.out |
| 242 | cscope add Xcscope2.out . -C |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 243 | let a = execute('cscope show') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 244 | call assert_match('\n 0 \d\+.*Xcscope.out\s*<none>', a) |
| 245 | call assert_match('\n 1 \d\+.*Xcscope2.out\s*\.', a) |
| 246 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 247 | " Test: test Ex command line completion |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 248 | call feedkeys(":cs \<C-A>\<C-B>\"\<CR>", 'tx') |
| 249 | call assert_equal('"cs add find help kill reset show', @:) |
| 250 | |
| 251 | call feedkeys(":scs \<C-A>\<C-B>\"\<CR>", 'tx') |
| 252 | call assert_equal('"scs find', @:) |
| 253 | |
| 254 | call feedkeys(":cs find \<C-A>\<C-B>\"\<CR>", 'tx') |
| 255 | call assert_equal('"cs find a c d e f g i s t', @:) |
| 256 | |
| 257 | call feedkeys(":cs kill \<C-A>\<C-B>\"\<CR>", 'tx') |
| 258 | call assert_equal('"cs kill -1 0 1', @:) |
| 259 | |
| 260 | call feedkeys(":cs add Xcscope\<C-A>\<C-B>\"\<CR>", 'tx') |
| 261 | call assert_equal('"cs add Xcscope.out Xcscope2.out', @:) |
| 262 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 263 | " Test: cscope_connection() |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 264 | call assert_equal(cscope_connection(), 1) |
| 265 | call assert_equal(cscope_connection(0, 'out'), 1) |
| 266 | call assert_equal(cscope_connection(0, 'xxx'), 1) |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 267 | |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 268 | call assert_equal(cscope_connection(1, 'out'), 1) |
| 269 | call assert_equal(cscope_connection(1, 'xxx'), 0) |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 270 | |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 271 | call assert_equal(cscope_connection(2, 'out'), 0) |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 272 | call assert_equal(cscope_connection(2, getcwd() .. '/Xcscope.out', 1), 1) |
| 273 | |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 274 | call assert_equal(cscope_connection(3, 'xxx', '..'), 0) |
| 275 | call assert_equal(cscope_connection(3, 'out', 'xxx'), 0) |
| 276 | call assert_equal(cscope_connection(3, 'out', '.'), 1) |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 277 | |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 278 | call assert_equal(cscope_connection(4, 'out', '.'), 0) |
| 279 | |
Bram Moolenaar | d7ffc0b | 2020-04-05 15:36:16 +0200 | [diff] [blame] | 280 | call assert_equal(cscope_connection(5, 'out'), 0) |
| 281 | call assert_equal(cscope_connection(-1, 'out'), 0) |
| 282 | |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 283 | call CscopeSetupOrClean(0) |
Bram Moolenaar | 2196bca | 2018-07-15 17:36:32 +0200 | [diff] [blame] | 284 | endfunc |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 285 | |
Bram Moolenaar | 2196bca | 2018-07-15 17:36:32 +0200 | [diff] [blame] | 286 | " Test ":cs add {dir}" (add the {dir}/cscope.out database) |
| 287 | func Test_cscope_add_dir() |
| 288 | call mkdir('Xcscopedir', 'p') |
Bram Moolenaar | 320bf2d | 2018-08-22 20:06:26 +0200 | [diff] [blame] | 289 | |
| 290 | " Cscope doesn't handle symlinks, so this needs to be resolved in case a |
| 291 | " shadow directory is being used. |
| 292 | let memfile = resolve('../memfile_test.c') |
| 293 | call system('cscope -bk -fXcscopedir/cscope.out ' . memfile) |
| 294 | |
Bram Moolenaar | 2196bca | 2018-07-15 17:36:32 +0200 | [diff] [blame] | 295 | cs add Xcscopedir |
| 296 | let a = execute('cscope show') |
| 297 | let lines = split(a, "\n", 1) |
| 298 | call assert_equal(3, len(lines)) |
| 299 | call assert_equal(' # pid database name prepend path', lines[0]) |
| 300 | call assert_equal('', lines[1]) |
| 301 | call assert_match('^ 0 \d\+.*Xcscopedir/cscope.out\s\+<none>$', lines[2]) |
| 302 | |
| 303 | cs kill -1 |
| 304 | call delete('Xcscopedir/cscope.out') |
| 305 | call assert_fails('cs add Xcscopedir', 'E563:') |
| 306 | |
| 307 | call delete('Xcscopedir', 'd') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 308 | endfunc |
| 309 | |
Bram Moolenaar | 6d20e17 | 2016-07-13 22:44:12 +0200 | [diff] [blame] | 310 | func Test_cscopequickfix() |
| 311 | set cscopequickfix=s-,g-,d+,c-,t+,e-,f0,i-,a- |
| 312 | call assert_equal('s-,g-,d+,c-,t+,e-,f0,i-,a-', &cscopequickfix) |
| 313 | |
| 314 | call assert_fails('set cscopequickfix=x-', 'E474:') |
| 315 | call assert_fails('set cscopequickfix=s', 'E474:') |
| 316 | call assert_fails('set cscopequickfix=s7', 'E474:') |
| 317 | call assert_fails('set cscopequickfix=s-a', 'E474:') |
| 318 | endfunc |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 319 | |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 320 | func Test_withoutCscopeConnection() |
| 321 | call assert_equal(cscope_connection(), 0) |
| 322 | |
| 323 | call assert_fails('cscope find s main', 'E567:') |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 324 | let a = execute('cscope show') |
Bram Moolenaar | 812ad4f | 2016-08-07 14:03:13 +0200 | [diff] [blame] | 325 | call assert_match('no cscope connections', a) |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 326 | endfunc |
| 327 | |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 328 | |
| 329 | " vim: shiftwidth=2 sts=2 expandtab |