Bram Moolenaar | 6d20e17 | 2016-07-13 22:44:12 +0200 | [diff] [blame] | 1 | " Test for cscope commands. |
| 2 | |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 3 | if !has('cscope') || !executable('cscope') || !has('quickfix') |
Bram Moolenaar | 6d20e17 | 2016-07-13 22:44:12 +0200 | [diff] [blame] | 4 | finish |
| 5 | endif |
| 6 | |
| 7 | func Test_cscopequickfix() |
| 8 | set cscopequickfix=s-,g-,d+,c-,t+,e-,f0,i-,a- |
| 9 | call assert_equal('s-,g-,d+,c-,t+,e-,f0,i-,a-', &cscopequickfix) |
| 10 | |
| 11 | call assert_fails('set cscopequickfix=x-', 'E474:') |
| 12 | call assert_fails('set cscopequickfix=s', 'E474:') |
| 13 | call assert_fails('set cscopequickfix=s7', 'E474:') |
| 14 | call assert_fails('set cscopequickfix=s-a', 'E474:') |
| 15 | endfunc |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 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') |
Bram Moolenaar | 5971dab | 2016-08-05 21:25:29 +0200 | [diff] [blame] | 43 | call assert_fails('cscope add doesnotexist.out', 'E563') |
| 44 | call assert_fails('cscope kill 2', 'E261') |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 45 | " Test 1: Find this C-Symbol |
| 46 | let a=execute('cscope find s main') |
| 47 | " Test 1.1 test where it moves the cursor |
| 48 | call assert_equal('main(void)', getline('.')) |
| 49 | " Test 1.2 test the output of the :cs command |
| 50 | call assert_match('\n(1 of 1): <<main>> main(void )', a) |
| 51 | |
| 52 | " Test 2: Find this definition |
| 53 | cscope find g test_mf_hash |
| 54 | call assert_equal(['', '/*', ' * Test mf_hash_*() functions.', ' */', ' static void', 'test_mf_hash(void)', '{'], getline(line('.')-5, line('.')+1)) |
| 55 | |
| 56 | " Test 3: Find functions called by this function |
| 57 | let a=execute('cscope find d test_mf_hash') |
| 58 | call assert_match('\n(1 of 42): <<mf_hash_init>> mf_hash_init(&ht);', a) |
| 59 | call assert_equal(' mf_hash_init(&ht);', getline('.')) |
| 60 | |
| 61 | " Test 4: Find functions calling this function |
| 62 | let a=execute('cscope find c test_mf_hash') |
| 63 | call assert_match('\n(1 of 1): <<main>> test_mf_hash();', a) |
| 64 | call assert_equal(' test_mf_hash();', getline('.')) |
| 65 | |
| 66 | " Test 5: Find this text string |
| 67 | let a=execute('cscope find t Bram') |
| 68 | call assert_match('(1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a) |
| 69 | call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.')) |
| 70 | |
| 71 | " Test 6: Find this egrep pattern |
| 72 | " test all matches returned by cscope |
| 73 | let a=execute('cscope find e ^\#includ.') |
| 74 | call assert_match('\n(1 of 3): <<<unknown>>> #include <assert.h>', a) |
| 75 | call assert_equal('#include <assert.h>', getline('.')) |
| 76 | cnext |
| 77 | call assert_equal('#include "main.c"', getline('.')) |
| 78 | cnext |
| 79 | call assert_equal('#include "memfile.c"', getline('.')) |
| 80 | call assert_fails('cnext', 'E553') |
| 81 | |
| 82 | " Test 7: Find this file |
| 83 | enew |
| 84 | let a=execute('cscope find f Xmemfile_test.c') |
| 85 | call assert_match('\n"Xmemfile_test.c" 143L, 3137C', a) |
| 86 | call assert_equal('Xmemfile_test.c', @%) |
| 87 | |
| 88 | " Test 8: Find files #including this file |
| 89 | enew |
| 90 | let a=execute('cscope find i assert.h') |
| 91 | call assert_equal(['','"Xmemfile_test.c" 143L, 3137C','(1 of 1): <<global>> #include <assert.h>'], split(a, '\n', 1)) |
| 92 | call assert_equal('#include <assert.h>', getline('.')) |
| 93 | |
Bram Moolenaar | 5971dab | 2016-08-05 21:25:29 +0200 | [diff] [blame] | 94 | " Test 9: Invalid find command |
| 95 | call assert_fails('cs find x', 'E560') |
| 96 | |
| 97 | " Test 10: Find places where this symbol is assigned a value |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 98 | " this needs a cscope >= 15.8 |
Bram Moolenaar | 5971dab | 2016-08-05 21:25:29 +0200 | [diff] [blame] | 99 | " unfortunately, Travis has cscope version 15.7 |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 100 | let cscope_version=systemlist('cscope --version')[0] |
| 101 | let cs_version=str2float(matchstr(cscope_version, '\d\+\(\.\d\+\)\?')) |
| 102 | if cs_version >= 15.8 |
| 103 | let a=execute('cscope find a item') |
| 104 | call assert_equal(['', '(1 of 4): <<test_mf_hash>> item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);'], split(a, '\n', 1)) |
| 105 | call assert_equal(' item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);', getline('.')) |
| 106 | cnext |
| 107 | call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) |
| 108 | cnext |
| 109 | call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) |
| 110 | cnext |
| 111 | call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) |
| 112 | endif |
| 113 | |
Bram Moolenaar | 5971dab | 2016-08-05 21:25:29 +0200 | [diff] [blame] | 114 | " Test 11: leading whitespace is not removed for cscope find text |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 115 | let a=execute('cscope find t test_mf_hash') |
| 116 | call assert_equal(['', '(1 of 1): <<<unknown>>> test_mf_hash();'], split(a, '\n', 1)) |
| 117 | call assert_equal(' test_mf_hash();', getline('.')) |
| 118 | |
Bram Moolenaar | 5971dab | 2016-08-05 21:25:29 +0200 | [diff] [blame] | 119 | " Test 12: cscope help |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 120 | let a=execute('cscope help') |
| 121 | call assert_match('^cscope commands:\n', a) |
| 122 | call assert_match('\nadd :', a) |
| 123 | call assert_match('\nfind :', a) |
| 124 | call assert_match('\nhelp : Show this message', a) |
| 125 | call assert_match('\nkill : Kill a connection', a) |
| 126 | call assert_match('\nreset: Reinit all connections', a) |
| 127 | call assert_match('\nshow : Show connections', a) |
| 128 | |
Bram Moolenaar | 5971dab | 2016-08-05 21:25:29 +0200 | [diff] [blame] | 129 | " Test 13: reset connections |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 130 | let a=execute('cscope reset') |
| 131 | call assert_match('\nAdded cscope database.*Xcscope.out (#0)', a) |
| 132 | call assert_match('\nAll cscope databases reset', a) |
| 133 | |
Bram Moolenaar | 5971dab | 2016-08-05 21:25:29 +0200 | [diff] [blame] | 134 | " Test 14: cscope show |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 135 | let a=execute('cscope show') |
| 136 | call assert_match('\n 0 \d\+.*Xcscope.out\s*<none>', a) |
| 137 | |
Bram Moolenaar | 5971dab | 2016-08-05 21:25:29 +0200 | [diff] [blame] | 138 | " Test 15: cstag and 'csto' option |
| 139 | set csto=0 |
| 140 | let a=execute('cstag TEST_COUNT') |
| 141 | call assert_match('(1 of 1): <<TEST_COUNT>> #define TEST_COUNT 50000', a) |
| 142 | call assert_equal('#define TEST_COUNT 50000', getline('.')) |
| 143 | set csto=1 |
| 144 | let a=execute('cstag index_to_key') |
| 145 | call assert_match('(1 of 1): <<index_to_key>> #define index_to_key(i) ((i) ^ 15167)', a) |
| 146 | call assert_equal('#define index_to_key(i) ((i) ^ 15167)', getline('.')) |
| 147 | call assert_fails('cstag xxx', 'E257') |
| 148 | call assert_fails('cstag', 'E562') |
| 149 | |
| 150 | " Test 15: 'csprg' option |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 151 | call assert_equal('cscope', &csprg) |
| 152 | |
Bram Moolenaar | 5971dab | 2016-08-05 21:25:29 +0200 | [diff] [blame] | 153 | " Test 16: 'cst' option |
| 154 | set cst |
| 155 | let a=execute('tag TEST_COUNT') |
| 156 | call assert_match('(1 of 1): <<TEST_COUNT>> #define TEST_COUNT 50000', a) |
| 157 | call assert_equal('#define TEST_COUNT 50000', getline('.')) |
| 158 | set nocst |
| 159 | call assert_fails('tag TEST_COUNT', 'E426') |
| 160 | |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 161 | " CleanUp |
| 162 | call CscopeSetupOrClean(0) |
Bram Moolenaar | 5971dab | 2016-08-05 21:25:29 +0200 | [diff] [blame] | 163 | |
| 164 | " cscope command should fail after killing scope connection. |
| 165 | call assert_fails('cscope find s main', 'E567') |
| 166 | |
Bram Moolenaar | edf634e | 2016-08-02 23:01:40 +0200 | [diff] [blame] | 167 | endfunc |
| 168 | |
| 169 | " vim: shiftwidth=2 sts=2 expandtab |