From 47cbd1133c15cee4b475f90657c54615425ca081 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Sat, 17 Aug 2024 20:36:00 -0700 Subject: [PATCH] lint: add test in module-aware mode Add test in module-aware mode and DRY the lint tests. --- autoload/go/lint_test.vim | 54 ++++++++++++--------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/autoload/go/lint_test.vim b/autoload/go/lint_test.vim index d0b472f264..0847314a6d 100644 --- a/autoload/go/lint_test.vim +++ b/autoload/go/lint_test.vim @@ -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 = [ @@ -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:lintTest() call call(RestoreGOPATH, []) call call(RestoreGO111MODULE, []) @@ -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