test_computed_lint_file_values.vader
1 Before: 2 Save g:ale_enabled 3 Save g:ale_run_synchronously 4 Save g:ale_set_lists_synchronously 5 Save g:ale_buffer_info 6 7 let g:ale_enabled = 1 8 let g:ale_buffer_info = {} 9 let g:ale_run_synchronously = 1 10 let g:ale_set_lists_synchronously = 1 11 12 function! TestCallback(buffer, output) 13 " Windows adds extra spaces to the text from echo. 14 return [{ 15 \ 'lnum': 2, 16 \ 'col': 3, 17 \ 'text': 'testlinter1', 18 \}] 19 endfunction 20 function! TestCallback2(buffer, output) 21 " Windows adds extra spaces to the text from echo. 22 return [{ 23 \ 'lnum': 1, 24 \ 'col': 3, 25 \ 'text': 'testlinter2', 26 \}] 27 endfunction 28 function! TestCallback3(buffer, output) 29 " Windows adds extra spaces to the text from echo. 30 return [{ 31 \ 'lnum': 3, 32 \ 'col': 3, 33 \ 'text': 'testlinter3', 34 \}] 35 endfunction 36 37 " These two linters computer their lint_file values after running commands. 38 call ale#linter#Define('foobar', { 39 \ 'name': 'testlinter1', 40 \ 'callback': 'TestCallback', 41 \ 'executable': has('win32') ? 'cmd' : 'echo', 42 \ 'command': has('win32') ? 'echo foo bar' : '/bin/sh -c ''echo foo bar''', 43 \ 'lint_file': {b -> ale#command#Run(b, 'echo', {-> 1})}, 44 \}) 45 call ale#linter#Define('foobar', { 46 \ 'name': 'testlinter2', 47 \ 'callback': 'TestCallback2', 48 \ 'executable': has('win32') ? 'cmd' : 'echo', 49 \ 'command': has('win32') ? 'echo foo bar' : '/bin/sh -c ''echo foo bar''', 50 \ 'lint_file': {b -> ale#command#Run(b, 'echo', {-> ale#command#Run(b, 'echo', {-> 1})})}, 51 \}) 52 " This one directly computes the result. 53 call ale#linter#Define('foobar', { 54 \ 'name': 'testlinter3', 55 \ 'callback': 'TestCallback3', 56 \ 'executable': has('win32') ? 'cmd' : 'echo', 57 \ 'command': has('win32') ? 'echo foo bar' : '/bin/sh -c ''echo foo bar''', 58 \ 'lint_file': {b -> 1}, 59 \}) 60 61 let g:filename = tempname() 62 call writefile([], g:filename) 63 call ale#test#SetFilename(g:filename) 64 65 After: 66 delfunction TestCallback 67 68 call ale#engine#Cleanup(bufnr('')) 69 Restore 70 call ale#linter#Reset() 71 72 " Items and markers, etc. 73 call setloclist(0, []) 74 call clearmatches() 75 call ale#sign#Clear() 76 77 if filereadable(g:filename) 78 call delete(g:filename) 79 endif 80 81 unlet g:filename 82 83 Given foobar(A file with some lines): 84 foo 85 bar 86 baz 87 88 Execute(lint_file results where the result is eventually computed should be run): 89 call ale#Queue(0, 'lint_file') 90 call ale#test#FlushJobs() 91 92 AssertEqual 93 \ [ 94 \ { 95 \ 'bufnr': bufnr('%'), 96 \ 'lnum': 1, 97 \ 'vcol': 0, 98 \ 'col': 3, 99 \ 'text': 'testlinter2', 100 \ 'type': 'E', 101 \ 'nr': -1, 102 \ 'pattern': '', 103 \ 'valid': 1, 104 \ }, 105 \ { 106 \ 'bufnr': bufnr('%'), 107 \ 'lnum': 2, 108 \ 'vcol': 0, 109 \ 'col': 3, 110 \ 'text': 'testlinter1', 111 \ 'type': 'E', 112 \ 'nr': -1, 113 \ 'pattern': '', 114 \ 'valid': 1, 115 \ }, 116 \ { 117 \ 'bufnr': bufnr('%'), 118 \ 'lnum': 3, 119 \ 'vcol': 0, 120 \ 'col': 3, 121 \ 'text': 'testlinter3', 122 \ 'type': 'E', 123 \ 'nr': -1, 124 \ 'pattern': '', 125 \ 'valid': 1, 126 \ }, 127 \ ], 128 \ ale#test#GetLoclistWithoutNewerKeys() 129 130 Execute(Linters where lint_file eventually evaluates to 1 shouldn't be run if we don't want to run them): 131 call ale#Queue(0, '') 132 call ale#test#FlushJobs() 133 134 AssertEqual [], ale#test#GetLoclistWithoutNewerKeys() 135 136 Execute(Keeping computed lint_file jobs running should work): 137 AssertEqual 'testlinter2', ale#linter#Get('foobar')[1].name 138 139 call ale#engine#InitBufferInfo(bufnr('')) 140 141 call ale#engine#MarkLinterActive( 142 \ g:ale_buffer_info[bufnr('')], 143 \ ale#linter#Get('foobar')[1] 144 \) 145 call ale#engine#RunLinters(bufnr(''), ale#linter#Get('foobar'), 0) 146 147 Assert !empty(g:ale_buffer_info[bufnr('')].active_linter_list), 148 \ 'The active linter list was empty' 149 Assert ale#engine#IsCheckingBuffer(bufnr('')), 150 \ 'The IsCheckingBuffer function returned 0'