Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: add test in module-aware mode #3679

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 17 additions & 37 deletions autoload/go/lint_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,10 @@ func! Test_Vet_compilererror() abort
endtry
endfunc

func! Test_Lint_GOPATH() abort
let g:go_gopls_enabled = 0
let RestoreGO111MODULE = go#util#SetEnv('GO111MODULE', 'off')
let RestoreGOPATH = go#util#SetEnv('GOPATH', fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint')

silent exe 'e! ' . $GOPATH . '/src/lint/baz.go'
silent exe 'e! ' . $GOPATH . '/src/lint/quux.go'
silent exe 'e! ' . $GOPATH . '/src/lint/lint.go'
func! s:testLint() abort
silent exe 'e! ' . fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint/src/lint/baz.go'
silent exe 'e! ' . fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint/src/lint/quux.go'
silent exe 'e! ' . fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint/src/lint/lint.go'
compiler go

let expected = [
Expand Down Expand Up @@ -509,8 +505,19 @@ func! Test_Lint_GOPATH() abort
call sort(expected)

call gotest#assert_quickfix(actual, expected)
endfunc

"call assert_report(execute('ls'))
func! Test_Lint() abort
let g:go_gopls_enabled = 0
call s:testLint()
endfunc

func! Test_Lint_GOPATH() abort
let g:go_gopls_enabled = 0
let RestoreGO111MODULE = go#util#SetEnv('GO111MODULE', 'off')
let RestoreGOPATH = go#util#SetEnv('GOPATH', fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint')

call s:testLint()

call call(RestoreGOPATH, [])
call call(RestoreGO111MODULE, [])
Expand All @@ -519,36 +526,9 @@ endfunc
func! Test_Lint_NullModule() abort
let g:go_gopls_enabled = 0
let RestoreGO111MODULE = go#util#SetEnv('GO111MODULE', 'off')
silent exe 'e! ' . fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint/src/lint/baz.go'
silent exe 'e! ' . fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint/src/lint/quux.go'
silent exe 'e! ' . fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint/src/lint/lint.go'
compiler go

let expected = [
\ {'lnum': 1, 'bufnr': bufnr('test-fixtures/lint/src/lint/baz.go'), 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'should have a package comment'},
\ {'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': bufnr('test-fixtures/lint/src/lint/quux.go'), '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 quickfix list
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 s:testLint()

" sort the results for deterministic ordering
call sort(actual)
call sort(expected)

call gotest#assert_quickfix(actual, expected)
call call(RestoreGO111MODULE, [])
endfunc

Expand Down
Loading