Support $GO111MODULE with Go tooling

Allows the user to override $GO111MODULE environment variable through
ale options. This gives control over the default behavior of Go module
resolution.

Golang documentation:
https://github.com/golang/go/wiki/Modules#how-to-use-modules

Add `ale#Go#EnvString()` function to make it easy to add similar Go
environment variables in the future.

Use the new `EnvString` function in all available Go tools callbacks
& update tests

Also add test of linter command callback for `gofmt`
This commit is contained in:
Elias Martinez Cohen
2019-04-10 22:25:06 -04:00
parent 89f7292138
commit 49db8210f6
32 changed files with 269 additions and 15 deletions

View File

@@ -9,6 +9,7 @@ After:
endif
unlet! b:ale_completion_enabled
unlet! b:ale_go_go111module
call ale#assert#TearDownLinterTest()
@@ -34,6 +35,14 @@ Execute(should set bingo options):
AssertLinter 'bingo',
\ ale#Escape('bingo') . ' --mode stdio --trace'
Execute(should support Go environment variables):
call ale#test#SetFilename('go_paths/go1/prj1/file.go')
let b:ale_go_go111module = 'on'
AssertLinter 'bingo',
\ ale#Env('GO111MODULE', 'on') . ale#Escape('bingo') . ' --mode stdio'
Execute(Should return directory for 'go.mod' if found in parent directory):
call ale#test#SetFilename('../go_files/test.go')
@@ -44,3 +53,20 @@ Execute(Should return nearest directory with '.git' if found in parent directory
call mkdir(g:dir . '/.git')
AssertLSPProject g:dir
Execute(Should ignore 'go.mod' and return '.git' dir if modules off):
call ale#test#SetFilename('../go_files/test.go')
let b:ale_go_go111module = 'off'
let b:parent_dir = ale#path#Simplify(g:dir . '/..')
let b:git_dir = b:parent_dir . '/.git'
if !isdirectory(b:git_dir)
call mkdir(b:git_dir)
endif
AssertLSPProject b:parent_dir
call delete(b:git_dir, 'd')
unlet! b:parent_dir
unlet! b:git_dir