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