1
0
Fork 0
mirror of synced 2024-11-04 08:28:57 -05:00
ultimate-vim/sources_non_forked/vim-go/autoload/go/lint_test.vim

207 lines
6.1 KiB
VimL
Raw Normal View History

2018-12-17 06:28:27 -05:00
" don't spam the user when Vim is started in Vi compatibility mode
let s:cpo_save = &cpo
set cpo&vim
2019-03-27 11:08:56 -04:00
func! Test_GometaGolangciLint() abort
call s:gometa('golangci-lint')
endfunc
func! s:gometa(metalinter) abort
2019-08-22 11:36:17 -04:00
let RestoreGOPATH = go#util#SetEnv('GOPATH', fnamemodify(getcwd(), ':p') . 'test-fixtures/lint')
2018-02-04 06:35:08 -05:00
silent exe 'e ' . $GOPATH . '/src/lint/lint.go'
2019-03-27 11:08:56 -04:00
try
2019-08-22 11:36:17 -04:00
let g:go_metalinter_command = a:metalinter
2019-03-27 11:08:56 -04:00
let expected = [
\ {'lnum': 5, 'bufnr': bufnr('%')+1, 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': 'w', 'pattern': '', 'text': 'exported function MissingFooDoc should have comment or be unexported (golint)'}
\ ]
2019-08-22 11:36:17 -04:00
if a:metalinter == 'golangci-lint'
let expected = [
2019-11-16 10:28:42 -05:00
\ {'lnum': 5, 'bufnr': bufnr('%')+2, 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exported function `MissingFooDoc` should have comment or be unexported (golint)'}
2019-08-22 11:36:17 -04:00
\ ]
endif
2018-02-04 06:35:08 -05:00
2019-03-27 11:08:56 -04:00
" clear the quickfix lists
call setqflist([], 'r')
2018-02-04 06:35:08 -05:00
2019-03-27 11:08:56 -04:00
let g:go_metalinter_enabled = ['golint']
2018-02-04 06:35:08 -05:00
2019-03-27 11:08:56 -04:00
call go#lint#Gometa(0, 0, $GOPATH . '/src/foo')
2018-02-04 06:35:08 -05:00
let actual = getqflist()
2019-03-27 11:08:56 -04:00
let start = reltime()
while len(actual) == 0 && reltimefloat(reltime(start)) < 10
sleep 100m
let actual = getqflist()
endwhile
call gotest#assert_quickfix(actual, expected)
finally
2019-08-22 11:36:17 -04:00
call call(RestoreGOPATH, [])
2019-03-27 11:08:56 -04:00
unlet g:go_metalinter_enabled
endtry
2018-02-04 06:35:08 -05:00
endfunc
2019-08-22 11:36:17 -04:00
func! Test_GometaAutoSaveGolangciLint() abort
call s:gometaautosave('golangci-lint')
2019-03-27 11:08:56 -04:00
endfunc
2019-08-22 11:36:17 -04:00
func! s:gometaautosave(metalinter) abort
let RestoreGOPATH = go#util#SetEnv('GOPATH', fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint')
2018-02-04 06:35:08 -05:00
silent exe 'e ' . $GOPATH . '/src/lint/lint.go'
2019-03-27 11:08:56 -04:00
try
2019-08-22 11:36:17 -04:00
let g:go_metalinter_command = a:metalinter
2019-03-27 11:08:56 -04:00
let expected = [
2019-08-22 11:36:17 -04:00
\ {'lnum': 5, 'bufnr': bufnr('%'), 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': 'w', 'pattern': '', 'text': 'exported function MissingDoc should have comment or be unexported (golint)'}
2019-03-27 11:08:56 -04:00
\ ]
2019-08-22 11:36:17 -04:00
if a:metalinter == 'golangci-lint'
let expected = [
\ {'lnum': 5, 'bufnr': bufnr('%'), 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exported function `MissingDoc` should have comment or be unexported (golint)'}
\ ]
endif
2018-02-04 06:35:08 -05:00
2019-08-22 11:36:17 -04:00
let winnr = winnr()
2018-02-04 06:35:08 -05:00
2019-08-22 11:36:17 -04:00
" clear the location lists
call setloclist(l:winnr, [], 'r')
2018-02-04 06:35:08 -05:00
2019-08-22 11:36:17 -04:00
let g:go_metalinter_autosave_enabled = ['golint']
2018-02-04 06:35:08 -05:00
2019-08-22 11:36:17 -04:00
call go#lint#Gometa(0, 1)
let actual = getloclist(l:winnr)
2019-03-27 11:08:56 -04:00
let start = reltime()
while len(actual) == 0 && reltimefloat(reltime(start)) < 10
sleep 100m
2019-08-22 11:36:17 -04:00
let actual = getloclist(l:winnr)
2019-03-27 11:08:56 -04:00
endwhile
call gotest#assert_quickfix(actual, expected)
finally
2019-08-22 11:36:17 -04:00
call call(RestoreGOPATH, [])
unlet g:go_metalinter_autosave_enabled
2019-03-27 11:08:56 -04:00
endtry
2018-02-04 06:35:08 -05:00
endfunc
2019-08-22 11:36:17 -04:00
func! Test_Vet() abort
let l:tmp = gotest#load_fixture('lint/src/vet/vet.go')
2018-02-04 06:35:08 -05:00
2019-03-27 11:08:56 -04:00
try
2019-08-22 11:36:17 -04:00
2019-03-27 11:08:56 -04:00
let expected = [
2019-08-22 11:36:17 -04:00
\ {'lnum': 7, 'bufnr': bufnr('%'), 'col': 2, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '',
\ 'text': 'Printf format %d has arg str of wrong type string'}
2019-03-27 11:08:56 -04:00
\ ]
2018-02-04 06:35:08 -05:00
2019-03-27 11:08:56 -04:00
let winnr = winnr()
2018-02-04 06:35:08 -05:00
2019-03-27 11:08:56 -04:00
" clear the location lists
2019-08-22 11:36:17 -04:00
call setqflist([], 'r')
2018-02-04 06:35:08 -05:00
2019-08-22 11:36:17 -04:00
call go#lint#Vet(1)
2018-02-04 06:35:08 -05:00
2019-08-22 11:36:17 -04:00
let actual = getqflist()
2019-03-27 11:08:56 -04:00
let start = reltime()
while len(actual) == 0 && reltimefloat(reltime(start)) < 10
sleep 100m
2019-08-22 11:36:17 -04:00
let actual = getqflist()
2019-03-27 11:08:56 -04:00
endwhile
2019-11-16 10:28:42 -05:00
call gotest#assert_quickfix(actual, expected)
finally
call delete(l:tmp, 'rf')
endtry
endfunc
func! Test_Vet_compilererror() abort
let l:tmp = gotest#load_fixture('lint/src/vet/compilererror/compilererror.go')
try
let expected = [
\ {'lnum': 6, 'bufnr': bufnr('%'), 'col': 22, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': "missing ',' before newline in argument list (and 1 more errors)"}
\ ]
let winnr = winnr()
" clear the location lists
call setqflist([], 'r')
call go#lint#Vet(1)
let actual = getqflist()
let start = reltime()
while len(actual) == 0 && reltimefloat(reltime(start)) < 10
sleep 100m
let actual = getqflist()
endwhile
2019-03-27 11:08:56 -04:00
call gotest#assert_quickfix(actual, expected)
finally
2019-08-22 11:36:17 -04:00
call delete(l:tmp, 'rf')
2019-03-27 11:08:56 -04:00
endtry
2018-02-04 06:35:08 -05:00
endfunc
2019-08-22 11:36:17 -04:00
func! Test_Lint_GOPATH() abort
let RestoreGOPATH = go#util#SetEnv('GOPATH', fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint')
silent exe 'e ' . $GOPATH . '/src/lint/lint.go'
compiler go
let expected = [
\ {'lnum': 5, 'bufnr': bufnr('%'), 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exported function MissingDoc should have comment or be unexported'},
\ {'lnum': 5, 'bufnr': 6, 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exported function AlsoMissingDoc should have comment or be unexported'}
\ ]
let winnr = winnr()
" clear the location lists
call setqflist([], 'r')
call go#lint#Golint(1)
let actual = getqflist()
let start = reltime()
while len(actual) == 0 && reltimefloat(reltime(start)) < 10
sleep 100m
let actual = getqflist()
endwhile
call gotest#assert_quickfix(actual, expected)
call call(RestoreGOPATH, [])
endfunc
func! Test_Lint_NullModule() abort
silent exe 'e ' . fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint/src/lint/lint.go'
2018-03-31 10:56:26 -04:00
compiler go
let expected = [
2019-08-22 11:36:17 -04:00
\ {'lnum': 5, 'bufnr': bufnr('%'), 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exported function MissingDoc should have comment or be unexported'},
\ {'lnum': 5, 'bufnr': 6, 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exported function AlsoMissingDoc should have comment or be unexported'}
2018-03-31 10:56:26 -04:00
\ ]
let winnr = winnr()
" clear the location lists
call setqflist([], 'r')
2019-08-22 11:36:17 -04:00
call go#lint#Golint(1)
2018-03-31 10:56:26 -04:00
let actual = getqflist()
let start = reltime()
while len(actual) == 0 && reltimefloat(reltime(start)) < 10
sleep 100m
let actual = getqflist()
endwhile
call gotest#assert_quickfix(actual, expected)
endfunc
2018-12-17 06:28:27 -05:00
" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
2018-02-04 06:35:08 -05:00
" vim: sw=2 ts=2 et