Merge pull request from Carpetsmoker/gopath

Remove "go env" from gobuild linter
This commit is contained in:
w0rp 2018-08-23 22:33:01 +01:00 committed by GitHub
commit 774c02552f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 51 deletions
ale_linters/go
test/command_callback

@ -5,35 +5,11 @@
call ale#Set('go_gobuild_options', '') call ale#Set('go_gobuild_options', '')
function! ale_linters#go#gobuild#ResetEnv() abort function! ale_linters#go#gobuild#GetCommand(buffer) abort
unlet! s:go_env
endfunction
function! ale_linters#go#gobuild#GoEnv(buffer) abort
if exists('s:go_env')
return ''
endif
return 'go env GOPATH GOROOT'
endfunction
function! ale_linters#go#gobuild#GetCommand(buffer, goenv_output) abort
let l:options = ale#Var(a:buffer, 'go_gobuild_options') let l:options = ale#Var(a:buffer, 'go_gobuild_options')
if !exists('s:go_env')
let s:go_env = {
\ 'GOPATH': a:goenv_output[0],
\ 'GOROOT': a:goenv_output[1],
\}
endif
let l:gopath_env_command = has('win32')
\ ? 'set GOPATH=' . ale#Escape(s:go_env.GOPATH) . ' && '
\ : 'GOPATH=' . ale#Escape(s:go_env.GOPATH) . ' '
" Run go test in local directory with relative path " Run go test in local directory with relative path
return l:gopath_env_command return ale#path#BufferCdString(a:buffer)
\ . ale#path#BufferCdString(a:buffer)
\ . 'go test' \ . 'go test'
\ . (!empty(l:options) ? ' ' . l:options : '') \ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -c -o /dev/null ./' \ . ' -c -o /dev/null ./'
@ -73,10 +49,8 @@ call ale#linter#Define('go', {
\ 'name': 'gobuild', \ 'name': 'gobuild',
\ 'aliases': ['go build'], \ 'aliases': ['go build'],
\ 'executable': 'go', \ 'executable': 'go',
\ 'command_chain': [ \ 'command_callback': 'ale_linters#go#gobuild#GetCommand',
\ {'callback': 'ale_linters#go#gobuild#GoEnv', 'output_stream': 'stdout'}, \ 'output_stream': 'stderr',
\ {'callback': 'ale_linters#go#gobuild#GetCommand', 'output_stream': 'stderr'},
\ ],
\ 'callback': 'ale_linters#go#gobuild#Handler', \ 'callback': 'ale_linters#go#gobuild#Handler',
\ 'lint_file': 1, \ 'lint_file': 1,
\}) \})

@ -1,36 +1,19 @@
Before: Before:
call ale#assert#SetUpLinterTest('go', 'gobuild') call ale#assert#SetUpLinterTest('go', 'gobuild')
let g:env_prefix = has('win32')
\ ? 'set GOPATH=' . ale#Escape('/foo/bar') . ' && '
\ : 'GOPATH=' . ale#Escape('/foo/bar') . ' '
call ale_linters#go#gobuild#ResetEnv()
WithChainResults ['/foo/bar', '/foo/baz'] WithChainResults ['/foo/bar', '/foo/baz']
After: After:
unlet! g:env_prefix
call ale#assert#TearDownLinterTest() call ale#assert#TearDownLinterTest()
Execute(The default commands should be correct): Execute(The default commands should be correct):
AssertLinter 'go', [ AssertLinter 'go',
\ 'go env GOPATH GOROOT', \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
\ g:env_prefix . 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
\ . 'go test -c -o /dev/null ./' \ . 'go test -c -o /dev/null ./'
\]
" We shouldn't run `go env` many times after we've got it.
AssertLinter 'go', [
\ '',
\ g:env_prefix . 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
\ . 'go test -c -o /dev/null ./'
\]
Execute(Extra options should be supported): Execute(Extra options should be supported):
let g:ale_go_gobuild_options = '--foo-bar' let g:ale_go_gobuild_options = '--foo-bar'
AssertLinter 'go', [ AssertLinter 'go',
\ 'go env GOPATH GOROOT', \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
\ g:env_prefix . 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
\ . 'go test --foo-bar -c -o /dev/null ./' \ . 'go test --foo-bar -c -o /dev/null ./'
\]