Skip to content

Commit

Permalink
lint: add test in module-aware mode
Browse files Browse the repository at this point in the history
Add test in module-aware mode and DRY the lint tests.
  • Loading branch information
bhcleek committed Aug 18, 2024
1 parent ced525d commit b0611fc
Showing 1 changed file with 17 additions and 37 deletions.
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:lintTest()
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:lintTest()

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

0 comments on commit b0611fc

Please sign in to comment.