summaryrefslogtreecommitdiff
path: root/test/test_other_sources.vader
blob: b397788d7aab9768960224e9f8678e3fcf2e7618 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Before:
  Save g:ale_buffer_info
  Save g:ale_set_signs
  Save g:ale_set_quickfix
  Save g:ale_set_loclist
  Save g:ale_set_highlights
  Save g:ale_echo_cursor

  let g:ale_buffer_info = {}
  let g:ale_run_synchronously = 1
  let g:ale_set_lists_synchronously = 1
  let g:ale_set_signs = 0
  let g:ale_set_quickfix = 0
  let g:ale_set_loclist = 1
  let g:ale_set_highlights = 0
  let g:ale_echo_cursor = 0

  function! TestCallback(buffer, output)
    return []
  endfunction

  call ale#linter#Define('foobar', {
  \ 'name': 'testlinter',
  \ 'callback': 'TestCallback',
  \ 'executable': has('win32') ? 'cmd' : 'echo',
  \ 'command': has('win32') ? 'echo foo bar' : '/bin/sh -c ''echo foo bar''',
  \})

After:
  Restore

  unlet! b:ale_linters
  unlet! g:want_results_signaled
  unlet! g:want_results_buffer_value
  unlet! g:lint_pre_signaled
  unlet! g:ale_run_synchronously
  unlet! g:ale_set_lists_synchronously

  delfunction TestCallback

  augroup VaderTest
    autocmd!
  augroup END

  augroup! VaderTest

  call ale#linter#Reset()
  call setloclist(0, [])

Given foobar (Some imaginary filetype):
Execute(StartChecking should mark a buffer as being actively checked):
  Assert !ale#engine#IsCheckingBuffer(bufnr(''))

  call ale#other_source#StartChecking(bufnr(''), 'other-source-linter')

  Assert ale#engine#IsCheckingBuffer(bufnr(''))

Execute(ShowResults sould make a buffer inactive):
  call ale#other_source#StartChecking(bufnr(''), 'other-source-linter')
  call ale#other_source#StartChecking(bufnr(''), 'second-other-source-linter')

  call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', [])

  Assert ale#engine#IsCheckingBuffer(bufnr(''))

  call ale#other_source#ShowResults(bufnr(''), 'second-other-source-linter', [])

  Assert !ale#engine#IsCheckingBuffer(bufnr(''))

Execute(ShowResults should show results at any time):
  call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', [
  \ {'text': 'xyz', 'lnum': 1},
  \])

  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'bufnr': bufnr(''),
  \     'col': 0,
  \     'valid': 1,
  \     'vcol': 0,
  \     'nr': -1,
  \     'type': 'E',
  \     'pattern': '',
  \     'text': 'xyz',
  \   },
  \ ],
  \ ale#test#GetLoclistWithoutNewerKeys()

  call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', [])

  AssertEqual [], ale#test#GetLoclistWithoutNewerKeys()

Execute(A regular lint cycle shouldn't clear results from other sources):
  call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', [
  \ {'text': 'xyz', 'lnum': 1},
  \])
  ALELint

  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'bufnr': bufnr(''),
  \     'col': 0,
  \     'valid': 1,
  \     'vcol': 0,
  \     'nr': -1,
  \     'type': 'E',
  \     'pattern': '',
  \     'text': 'xyz',
  \   },
  \ ],
  \ ale#test#GetLoclistWithoutNewerKeys()

Execute(ALEWantResults should be signaled when a buffer is checked):
  augroup VaderTest
    autocmd!
    autocmd User ALEWantResults let g:want_results_signaled = 1
    autocmd User ALELintPre let g:lint_pre_signaled = 1
  augroup END

  " Even when all linters are disabled, we should send the signal.
  let b:ale_linters = []
  ALELint

  Assert get(g:, 'want_results_signaled')
  Assert !get(g:, 'lint_pre_signaled')

Execute(ALEWantResults should set a variable indicating which buffer is being checked):
  augroup VaderTest
    autocmd!
    autocmd User ALEWantResults let g:want_results_buffer_value = g:ale_want_results_buffer
  augroup END

  let b:ale_linters = []
  ALELint

  AssertEqual bufnr(''), g:want_results_buffer_value

Execute(ALEWantResults should lead to an ALELintPre signal if another source responds):
  augroup VaderTest
    autocmd!
    autocmd User ALEWantResults call ale#other_source#StartChecking(bufnr(''), 'other-source-linter')
    autocmd User ALELintPre let g:lint_pre_signaled = 1
  augroup END

  " Even when all linters are disabled, we should send the signal.
  let b:ale_linters = []
  ALELint

  Assert get(g:, 'lint_pre_signaled')