summaryrefslogtreecommitdiff
path: root/test/smoke_test.vader
blob: 843bddab23866651d99cad02ec94d8491c5cb436 (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
Before:
  Save g:ale_set_lists_synchronously
  Save g:ale_buffer_info
  Save &shell

  let g:ale_buffer_info = {}
  let g:ale_set_lists_synchronously = 1

  function! TestCallback(buffer, output)
    " Windows adds extra spaces to the text from echo.
    return [{
    \ 'lnum': 2,
    \ 'col': 3,
    \ 'text': substitute(a:output[0], ' *$', '', ''),
    \}]
  endfunction
  function! TestCallback2(buffer, output)
    return [{
    \ 'lnum': 3,
    \ 'col': 4,
    \ 'text': substitute(a:output[0],  ' *$', '', ''),
    \}]
  endfunction

  " Running the command in another subshell seems to help here.
  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

  delfunction TestCallback
  delfunction TestCallback2
  call ale#linter#Reset()

Given foobar (Some imaginary filetype):
  foo
  bar
  baz

Execute(Linters should run with the default options):
  AssertEqual 'foobar', &filetype

  call ale#Lint()
  call ale#engine#WaitForJobs(2000)

  AssertEqual [{
  \   'bufnr': bufnr('%'),
  \   'lnum': 2,
  \   'vcol': 0,
  \   'col': 3,
  \   'text': 'foo bar',
  \   'type': 'E',
  \   'nr': -1,
  \   'pattern': '',
  \   'valid': 1,
  \ }], getloclist(0)

Execute(Linters should run in PowerShell too):
  if has('win32')
    set shell=powershell

    AssertEqual 'foobar', &filetype

    " Replace the callback to handle two lines.
    function! TestCallback(buffer, output)
      " Windows adds extra spaces to the text from echo.
      return [
      \ {
      \   'lnum': 1,
      \   'col': 3,
      \   'text': substitute(a:output[0], ' *$', '', ''),
      \ },
      \ {
      \   'lnum': 2,
      \   'col': 3,
      \   'text': substitute(a:output[1], ' *$', '', ''),
      \ },
      \]
    endfunction

    " Recreate the command string to use &&, which PowerShell does not support.
    call ale#linter#Reset()
    call ale#linter#Define('foobar', {
    \ 'name': 'testlinter',
    \ 'callback': 'TestCallback',
    \ 'executable': 'cmd',
    \ 'command': 'echo foo && echo bar',
    \})

    call ale#Lint()
    call ale#engine#WaitForJobs(4000)

    AssertEqual [
    \ {
    \   'bufnr': bufnr('%'),
    \   'lnum': 1,
    \   'vcol': 0,
    \   'col': 3,
    \   'text': 'foo',
    \   'type': 'E',
    \   'nr': -1,
    \   'pattern': '',
    \   'valid': 1,
    \ },
    \ {
    \   'bufnr': bufnr('%'),
    \   'lnum': 2,
    \   'vcol': 0,
    \   'col': 3,
    \   'text': 'bar',
    \   'type': 'E',
    \   'nr': -1,
    \   'pattern': '',
    \   'valid': 1,
    \ },
    \], getloclist(0)
  endif

Execute(Previous errors should be removed when linters change):
  call ale#Lint()
  call ale#engine#WaitForJobs(2000)

  call ale#linter#Reset()

  call ale#linter#Define('foobar', {
  \ 'name': 'testlinter2',
  \ 'callback': 'TestCallback2',
  \ 'executable': has('win32') ? 'cmd' : 'echo',
  \ 'command': has('win32') ? 'echo baz boz' : '/bin/sh -c ''echo baz boz''',
  \})

  call ale#Lint()
  call ale#engine#WaitForJobs(2000)

  AssertEqual [{
  \   'bufnr': bufnr('%'),
  \   'lnum': 3,
  \   'vcol': 0,
  \   'col': 4,
  \   'text': 'baz boz',
  \   'type': 'E',
  \   'nr': -1,
  \   'pattern': '',
  \   'valid': 1,
  \ }], getloclist(0)