From ddbab889b824741ad06ee550b7bd6f8cbf45876f Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Tue, 28 Mar 2023 11:54:44 -0700 Subject: [PATCH 1/2] Update required version of Vim Update the required version of Vim to be the version installed with Ubuntu 20.04 LTS. --- .github/workflows/test.yml | 2 +- Dockerfile | 4 ++-- Makefile | 2 +- README.md | 2 +- autoload/go/lint_test.vim | 4 ++-- doc/vim-go.txt | 2 +- plugin/go.vim | 6 +++--- scripts/bench-syntax | 2 +- scripts/docker-test | 2 +- scripts/install-vim | 7 ++++--- scripts/lint | 2 +- scripts/run-vim | 2 +- scripts/test | 2 +- 13 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index acce346430..185eb6a2c0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,7 @@ jobs: fail-fast: false matrix: go: ['1.19','1.20'] - vim: ['vim-8.0', 'vim-8.2', 'nvim'] + vim: ['vim-8.1', 'vim-8.2', 'nvim'] steps: - name: setup Go uses: actions/setup-go@v2.1.3 diff --git a/Dockerfile b/Dockerfile index 5bd5e792a2..3416c4c7d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,14 +13,14 @@ USER vim-go COPY scripts/install-vim /vim-go/scripts/install-vim WORKDIR /vim-go -RUN scripts/install-vim vim-8.0 +RUN scripts/install-vim vim-8.1 RUN scripts/install-vim vim-8.2 RUN scripts/install-vim nvim COPY . /vim-go/ WORKDIR /vim-go -RUN scripts/install-tools vim-8.0 +RUN scripts/install-tools vim-8.1 RUN scripts/install-tools vim-8.2 RUN scripts/install-tools nvim diff --git a/Makefile b/Makefile index 874a864c7e..ab4f7d8806 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VIMS ?= vim-8.0 vim-8.2 nvim +VIMS ?= vim-8.1 vim-8.2 nvim TEST_FLAGS ?= all: install lint test diff --git a/README.md b/README.md index de87a420e9..cf9631a2b1 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ This plugin adds Go language support for Vim, with the following main features: ## Install -vim-go requires at least Vim 8.0.1453 or Neovim 0.4.0. +vim-go requires at least Vim 8.1.2269 or Neovim 0.4.0. The [**latest stable release**](https://github.com/fatih/vim-go/releases/latest) is the recommended version to use. If you choose to use the master branch instead, diff --git a/autoload/go/lint_test.vim b/autoload/go/lint_test.vim index 515b996623..423b66e46b 100644 --- a/autoload/go/lint_test.vim +++ b/autoload/go/lint_test.vim @@ -613,8 +613,8 @@ func! s:vimdir() let l:vim = "vim-8.2" if has('nvim') let l:vim = 'nvim' - elseif v:version == 800 - let l:vim = 'vim-8.0' + elseif v:version == 810 + let l:vim = 'vim-8.1' endif return l:vim diff --git a/doc/vim-go.txt b/doc/vim-go.txt index 196dcf4f37..f1d2540c86 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -77,7 +77,7 @@ experience. ============================================================================== INSTALL *go-install* -vim-go requires at least Vim 8.0.1453 or Neovim 0.4.0. On macOS, if you are +vim-go requires at least Vim 8.1.2269 or Neovim 0.4.0. On macOS, if you are still using your system version of vim, you can use homebrew to keep your version of Vim up-to-date with the following terminal command: > diff --git a/plugin/go.vim b/plugin/go.vim index 7ac2c56103..e96854ccea 100644 --- a/plugin/go.vim +++ b/plugin/go.vim @@ -14,17 +14,17 @@ function! s:checkVersion() abort if has('nvim') let l:unsupported = !has('nvim-0.4.0') else - let l:unsupported = !has('patch-8.0.1453') + let l:unsupported = !has('patch-8.1.2269') endif if l:unsupported == 1 echohl Error - echom "vim-go requires at least Vim 8.0.1453 or Neovim 0.4.0, but you're using an older version." + echom "vim-go requires at least Vim 8.1.2269 or Neovim 0.4.0, but you're using an older version." echom "Please update your Vim for the best vim-go experience." echom "If you really want to continue you can set this to make the error go away:" echom " let g:go_version_warning = 0" echom "Note that some features may error out or behave incorrectly." - echom "Please do not report bugs unless you're using at least Vim 8.0.1453 or Neovim 0.4.0." + echom "Please do not report bugs unless you're using at least Vim 8.1.2269 or Neovim 0.4.0." echohl None " Make sure people see this. diff --git a/scripts/bench-syntax b/scripts/bench-syntax index b4496af5c2..e6e4b90c95 100755 --- a/scripts/bench-syntax +++ b/scripts/bench-syntax @@ -13,7 +13,7 @@ cd "$vimgodir" if [ -z "${1:-}" ]; then echo "unknown version: '${1:-}'" - echo "First argument must be 'vim-8.0' or 'nvim'." + echo "First argument must be 'vim-8.1', 'vim-8.2', or 'nvim'." exit 1 fi diff --git a/scripts/docker-test b/scripts/docker-test index f92ec42a72..22bee0c46c 100755 --- a/scripts/docker-test +++ b/scripts/docker-test @@ -7,7 +7,7 @@ set -euC vimgodir=$(cd -P "$(dirname "$0")/.." > /dev/null && pwd) cd "$vimgodir" -docker build --tag vim-go-test . +docker build --platform=linux/amd64 --tag vim-go-test . # seccomp=confined is required for dlv to run in a container, hence it's # required for vim-go's debug tests. docker run -e VIMS --rm --security-opt="seccomp=unconfined" vim-go-test diff --git a/scripts/install-vim b/scripts/install-vim index f7db3cf47e..bd02e57af8 100755 --- a/scripts/install-vim +++ b/scripts/install-vim @@ -15,12 +15,13 @@ cd "$vimgodir" vim=${1:-} case "$vim" in - "vim-8.0") + "vim-8.1") # This follows the version in Ubuntu LTS. Vim's master branch isn't always # stable, and we don't want to have the build fail because Vim introduced a # bug. - tag="v8.0.1453" + tag="v8.1.2269" giturl="https://github.com/vim/vim" + ;; "vim-8.2") @@ -40,7 +41,7 @@ case "$vim" in *) echo "unknown version: '${1:-}'" - echo "First argument must be 'vim-8.0', vim-8.2, or 'nvim'." + echo "First argument must be 'vim-8.1', vim-8.2, or 'nvim'." exit 1 ;; esac diff --git a/scripts/lint b/scripts/lint index 5a97d95423..73d6efe6bb 100755 --- a/scripts/lint +++ b/scripts/lint @@ -11,7 +11,7 @@ cd "$vimgodir" ##################################### if [ -z "${1:-}" ]; then echo "unknown version: '${1:-}'" - echo "First argument must be 'vim-8.0' or 'nvim'." + echo "First argument must be 'vim-8.1', 'vim-8.2' or 'nvim'." exit 1 fi diff --git a/scripts/run-vim b/scripts/run-vim index a098a27b70..cdac734f9c 100755 --- a/scripts/run-vim +++ b/scripts/run-vim @@ -17,7 +17,7 @@ shift $((OPTIND - 1)) if [ -z "${1:-}" ]; then echo "unknown version: '${1:-}'" - echo "First argument must be 'vim-8.0', 'vim-8.2', or 'nvim'." + echo "First argument must be 'vim-8.1', 'vim-8.2', or 'nvim'." exit 1 fi diff --git a/scripts/test b/scripts/test index a5d3bfee3b..879da33015 100755 --- a/scripts/test +++ b/scripts/test @@ -43,7 +43,7 @@ shift $((OPTIND - 1)) ##################################### if [ -z "${1:-}" ]; then echo "unknown version: '${1:-}'" - echo "First argument must be 'vim-8.0' or 'nvim'." + echo "First argument must be 'vim-8.1', 'vim-8.2', or 'nvim'." exit 1 fi From d57b3985fbe5452176fc3491b25b2226736afbea Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Mon, 12 Jun 2023 13:49:32 -0700 Subject: [PATCH 2/2] tests: change directories before deleting Change out of the dynamically created directory before trying to delete that directory so that the directory change after deletion does not fail because the current directory at the time of change does not exist. This situation is also handled by Vim 8.2.0189, but vim-go has to support 8.1.2269 for now, so adjust tests so that vim-go is no longer susceptible to the condition that 8.2.0189 fixes. --- autoload/go/calls_test.vim | 2 ++ autoload/go/cmd_test.vim | 2 ++ autoload/go/complete_test.vim | 2 ++ autoload/go/config_test.vim | 2 ++ autoload/go/debug_test.vim | 8 ++++++++ autoload/go/def_test.vim | 14 ++++++++++++++ autoload/go/extract_test.vim | 2 ++ autoload/go/fillstruct_test.vim | 16 ++++++++++++++++ autoload/go/highlight_test.vim | 34 +++++++++++++++++++++++++++++++++ autoload/go/impl_test.vim | 4 ++++ autoload/go/import_test.vim | 2 ++ autoload/go/indent_test.vim | 6 ++++++ autoload/go/job_test.vim | 2 ++ autoload/go/lint_test.vim | 10 ++++++++++ autoload/go/lsp_test.vim | 8 ++++++++ autoload/go/tags_test.vim | 8 ++++++++ autoload/go/template_test.vim | 8 ++++++++ autoload/go/term_test.vim | 6 ++++++ autoload/go/tool_test.vim | 4 ++++ 19 files changed, 140 insertions(+) diff --git a/autoload/go/calls_test.vim b/autoload/go/calls_test.vim index a8a8377bca..de94139e54 100644 --- a/autoload/go/calls_test.vim +++ b/autoload/go/calls_test.vim @@ -5,6 +5,7 @@ set cpo&vim scriptencoding utf-8 func! Test_Callers() abort + let l:wd = getcwd() try let l:tmp = gotest#write_file('calls/caller.go', [ \ 'package main', @@ -37,6 +38,7 @@ func! Test_Callers() abort call gotest#assert_quickfix(l:actual, l:expected) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/cmd_test.vim b/autoload/go/cmd_test.vim index 4c0b163504..8889397b6f 100644 --- a/autoload/go/cmd_test.vim +++ b/autoload/go/cmd_test.vim @@ -3,6 +3,7 @@ let s:cpo_save = &cpo set cpo&vim func! Test_GoBuildErrors() + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:filename = 'cmd/bad.go' @@ -27,6 +28,7 @@ func! Test_GoBuildErrors() call gotest#assert_quickfix(actual, l:expected) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/complete_test.vim b/autoload/go/complete_test.vim index f6a3706d74..95f42bbe98 100644 --- a/autoload/go/complete_test.vim +++ b/autoload/go/complete_test.vim @@ -9,6 +9,7 @@ endfunction func! s:getinfo() let l:filename = 'complete/complete.go' + let l:wd = getcwd() let l:tmp = gotest#load_fixture(l:filename) try call cursor(8, 3) @@ -17,6 +18,7 @@ func! s:getinfo() let actual = go#complete#GetInfo() call assert_equal(expected, actual) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunction diff --git a/autoload/go/config_test.vim b/autoload/go/config_test.vim index 9691305a55..b73ffc909c 100644 --- a/autoload/go/config_test.vim +++ b/autoload/go/config_test.vim @@ -82,6 +82,7 @@ func! Test_GoplsEnabled_Clear() abort return endif + let l:wd = getcwd() try let g:go_gopls_enabled = 0 @@ -94,6 +95,7 @@ func! Test_GoplsEnabled_Clear() abort \ ] ) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/debug_test.vim b/autoload/go/debug_test.vim index 75d0e3930d..b177943d67 100644 --- a/autoload/go/debug_test.vim +++ b/autoload/go/debug_test.vim @@ -23,6 +23,7 @@ function! Test_GoDebugStart_Errors() abort return endif + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#load_fixture('debug/compilerror/main.go') @@ -60,6 +61,7 @@ function! Test_GoDebugStart_Errors() abort call assert_false(exists(':GoDebugStop')) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') " clear the quickfix lists call setqflist([], 'r') @@ -71,6 +73,7 @@ function! Test_GoDebugModeRemapsAndRestoresKeys() abort return endif + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let g:go_debug_mappings = {'(go-debug-continue)': {'key': 'q', 'arguments': ''}} @@ -96,6 +99,7 @@ function! Test_GoDebugModeRemapsAndRestoresKeys() abort endwhile call assert_equal('', maparg('q')) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunction @@ -105,6 +109,7 @@ function! Test_GoDebugStopRemovesPlugMappings() abort return endif + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#load_fixture('debug/debugmain/debugmain.go') @@ -129,6 +134,7 @@ function! Test_GoDebugStopRemovesPlugMappings() abort endwhile call assert_equal('', maparg('(go-debug-stop')) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunction @@ -141,6 +147,7 @@ function! s:debug(...) abort return endif + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let $oldgopath = $GOPATH @@ -179,6 +186,7 @@ function! s:debug(...) abort finally call go#debug#Breakpoint(6) + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunction diff --git a/autoload/go/def_test.vim b/autoload/go/def_test.vim index 8b3fc17142..84170ae2f1 100644 --- a/autoload/go/def_test.vim +++ b/autoload/go/def_test.vim @@ -5,6 +5,7 @@ set cpo&vim scriptencoding utf-8 func! Test_jump_to_declaration_guru() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:filename = 'def/jump.go' @@ -19,11 +20,13 @@ func! Test_jump_to_declaration_guru() abort call assert_equal(l:lnum, getcurpos()[1]) call assert_equal(l:col, getcurpos()[2]) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_jump_to_declaration_godef() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:filename = 'def/jump.go' @@ -38,11 +41,13 @@ func! Test_jump_to_declaration_godef() abort call assert_equal(l:lnum, getcurpos()[1]) call assert_equal(l:col, getcurpos()[2]) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_Jump_leaves_lists() abort + let l:wd = getcwd() try let l:filename = 'def/jump.go' let l:tmp = gotest#load_fixture(l:filename) @@ -74,6 +79,7 @@ func! Test_Jump_leaves_lists() abort let l:actual = getqflist() call gotest#assert_quickfix(l:actual, l:expected) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc @@ -83,6 +89,7 @@ func! Test_DefJump_gopls_simple_first() abort return endif + let l:wd = getcwd() try let g:go_def_mode = 'gopls' @@ -108,6 +115,7 @@ func! Test_DefJump_gopls_simple_first() abort call assert_equal(l:expected, getpos('.')) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc @@ -117,6 +125,7 @@ func! Test_DefJump_gopls_simple_last() abort return endif + let l:wd = getcwd() try let g:go_def_mode = 'gopls' @@ -142,6 +151,7 @@ func! Test_DefJump_gopls_simple_last() abort call assert_equal(l:expected, getpos('.')) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc @@ -151,6 +161,7 @@ func! Test_DefJump_gopls_MultipleCodeUnit_first() abort return endif + let l:wd = getcwd() try let g:go_def_mode = 'gopls' @@ -175,6 +186,7 @@ func! Test_DefJump_gopls_MultipleCodeUnit_first() abort call assert_equal(l:expected, getpos('.')) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc @@ -185,6 +197,7 @@ func! Test_DefJump_gopls_MultipleCodeUnit_last() abort return endif + let l:wd = getcwd() try let g:go_def_mode = 'gopls' @@ -209,6 +222,7 @@ func! Test_DefJump_gopls_MultipleCodeUnit_last() abort call assert_equal(l:expected, getpos('.')) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/extract_test.vim b/autoload/go/extract_test.vim index 11d1eacefe..26e1262b67 100644 --- a/autoload/go/extract_test.vim +++ b/autoload/go/extract_test.vim @@ -3,6 +3,7 @@ let s:cpo_save = &cpo set cpo&vim func! Test_Extract() abort + let l:wd = getcwd() try let l:tmp = gotest#write_file('a/a.go', [ \ 'package a', @@ -36,6 +37,7 @@ func! Test_Extract() abort \ '}']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/fillstruct_test.vim b/autoload/go/fillstruct_test.vim index 745ed383e7..f448501dfa 100644 --- a/autoload/go/fillstruct_test.vim +++ b/autoload/go/fillstruct_test.vim @@ -3,6 +3,7 @@ let s:cpo_save = &cpo set cpo&vim func! Test_fillstruct() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let g:go_fillstruct_mode = 'fillstruct' @@ -18,11 +19,13 @@ func! Test_fillstruct() abort \ '\tAddress: "",', \ '}']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_fillstruct_line() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let g:go_fillstruct_mode = 'fillstruct' @@ -38,11 +41,13 @@ func! Test_fillstruct_line() abort \ '\tAddress: "",', \ '}']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_fillstruct_two_line() abort + let l:wd = getcwd() try let g:go_fillstruct_mode = 'fillstruct' let g:go_gopls_enabled = 0 @@ -68,11 +73,13 @@ func! Test_fillstruct_two_line() abort \ '\tAddress: "",', \ '}) }']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_fillstruct_two_cursor() abort + let l:wd = getcwd() try let g:go_fillstruct_mode = 'fillstruct' let g:go_gopls_enabled = 0 @@ -95,11 +102,13 @@ func! Test_fillstruct_two_cursor() abort \ '\tAddress: "",', \ '}) }']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_gopls_fillstruct() abort + let l:wd = getcwd() try let g:go_fillstruct_mode = 'gopls' let l:tmp = gotest#write_file('a/a.go', [ @@ -120,11 +129,13 @@ func! Test_gopls_fillstruct() abort \ '\tAddress: "",', \ '}']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_gopls_fillstruct_line() abort + let l:wd = getcwd() try let g:go_fillstruct_mode = 'gopls' let l:tmp = gotest#write_file('a/a.go', [ @@ -145,11 +156,13 @@ func! Test_gopls_fillstruct_line() abort \ '\tAddress: "",', \ '}']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_gopls_fillstruct_two_cursor_first() abort + let l:wd = getcwd() try let g:go_fillstruct_mode = 'gopls' let l:tmp = gotest#write_file('a/a.go', [ @@ -177,11 +190,13 @@ func! Test_gopls_fillstruct_two_cursor_first() abort \ '\tAddress: "",', \ '}, mail.Address{}) }']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_gopls_fillstruct_two_cursor_second() abort + let l:wd = getcwd() try let g:go_fillstruct_mode = 'gopls' let l:tmp = gotest#write_file('a/a.go', [ @@ -209,6 +224,7 @@ func! Test_gopls_fillstruct_two_cursor_second() abort \ '\tAddress: "",', \ '}) }']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/highlight_test.vim b/autoload/go/highlight_test.vim index d405d15156..5f84bf48be 100644 --- a/autoload/go/highlight_test.vim +++ b/autoload/go/highlight_test.vim @@ -7,6 +7,7 @@ function! Test_gomodVersion_highlight() abort syntax on let g:go_gopls_enabled = 0 + let l:wd = getcwd() let l:dir = gotest#write_file('gomodtest/go.mod', [ \ 'module github.com/fatih/vim-go', \ '', @@ -51,6 +52,7 @@ function! Test_gomodVersion_highlight() abort let l:lineno += 1 endwhile finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunc @@ -60,6 +62,7 @@ function! Test_gomodVersion_incompatible_highlight() abort syntax on let g:go_gopls_enabled = 0 + let l:wd = getcwd() let l:dir = gotest#write_file('gomodtest/go.mod', [ \ 'module github.com/fatih/vim-go', \ '', @@ -96,6 +99,7 @@ function! Test_gomodVersion_incompatible_highlight() abort let l:lineno += 1 endwhile finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunc @@ -180,6 +184,7 @@ function! Test_zero_as_start_slicing_slice() abort endfunction function! s:numericHighlightGroupInAssignment(testname, value) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('numeric/%s.go', a:testname), [ \ 'package numeric', \ '', @@ -191,11 +196,13 @@ function! s:numericHighlightGroupInAssignment(testname, value) let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunction function! s:stringHighlightGroupInAssignment(testname, value) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('numeric/%s.go', a:testname), [ \ 'package numeric', \ '', @@ -207,11 +214,13 @@ function! s:stringHighlightGroupInAssignment(testname, value) let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunction function! s:numericHighlightGroupInSliceElement(testname, value) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('numeric/slice-element/%s.go', a:testname), [ \ 'package numeric', \ '', @@ -223,11 +232,13 @@ function! s:numericHighlightGroupInSliceElement(testname, value) let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunction function! s:numericHighlightGroupInMultidimensionalSliceElement(testname, value) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('numeric/slice-multidimensional-element/%s.go', a:testname), [ \ 'package numeric', \ '', @@ -239,11 +250,13 @@ function! s:numericHighlightGroupInMultidimensionalSliceElement(testname, value) let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunction function! s:numericHighlightGroupInSliceIndex(testname, value) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('numeric/slice-index/%s.go', a:testname), [ \ 'package numeric', \ '', @@ -256,11 +269,13 @@ function! s:numericHighlightGroupInSliceIndex(testname, value) let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunction function! s:numericHighlightGroupInMultidimensionalSliceIndex(testname, first, second) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('numeric/slice-multidimensional-index/%s.go', a:testname), [ \ 'package numeric', \ '', @@ -273,11 +288,13 @@ function! s:numericHighlightGroupInMultidimensionalSliceIndex(testname, first, s let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunction function! s:numericHighlightGroupInSliceSlicing(testname, from, to) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('numeric/slice-slicing/%s.go', a:testname), [ \ 'package numeric', \ '', @@ -289,6 +306,7 @@ function! s:numericHighlightGroupInSliceSlicing(testname, from, to) let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunction @@ -348,6 +366,7 @@ endfunction function! Test_diagnostic_after_reload() abort let g:go_diagnostics_level = 2 + let l:wd = getcwd() let l:dir = gotest#write_file('diagnostic/after-reload.go', [ \ 'package main', \ 'import "fmt"', @@ -364,6 +383,7 @@ function! Test_diagnostic_after_reload() abort call setpos('.', l:pos) call s:check_diagnostics('', 'goDiagnosticError', 'after-reload') finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunction @@ -372,6 +392,7 @@ function! s:diagnostic_after_write(contents, changes) abort syntax on let g:go_diagnostics_level = 2 + let l:wd = getcwd() let l:dir = gotest#write_file('diagnostic/after-write.go', a:contents) try @@ -394,6 +415,7 @@ function! s:diagnostic_after_write(contents, changes) abort call s:check_diagnostics(l:actual, l:expected, 'after-write') finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunction @@ -447,6 +469,7 @@ function! Test_goStringHighlight() abort syntax on let g:go_gopls_enabled = 0 + let l:wd = getcwd() let l:dir = gotest#write_file('highlight/gostring.go', [ \ 'package highlight', \ '', @@ -462,6 +485,7 @@ function! Test_goStringHighlight() abort let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') call assert_equal('goString', l:actual) finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunc @@ -470,6 +494,7 @@ function! Test_goImportStringHighlight() abort syntax on let g:go_gopls_enabled = 0 + let l:wd = getcwd() let l:dir = gotest#write_file('highlight/import.go', [ \ 'package highlight', \ '', @@ -485,6 +510,7 @@ function! Test_goImportStringHighlight() abort let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') call assert_equal('goImportString', l:actual) finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunc @@ -517,6 +543,7 @@ endfunc function! s:receiverHighlightGroup(testname, value) let l:package = tolower(a:testname) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('%s/%s.go', l:package, a:testname), [ \ printf('package %s', l:package), \ '', @@ -530,6 +557,7 @@ function! s:receiverHighlightGroup(testname, value) let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunc @@ -552,6 +580,7 @@ endfunc function! s:typeHighlightGroup(testname, value) let l:package = tolower(a:testname) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('%s/%s.go', l:package, a:testname), [ \ printf('package %s', l:package), \ '', @@ -563,6 +592,7 @@ function! s:typeHighlightGroup(testname, value) let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunc @@ -585,6 +615,7 @@ endfunc function! s:functionHighlightGroup(testname, value) let l:package = tolower(a:testname) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('%s/%s.go', l:package, a:testname), [ \ printf('package %s', l:package), \ '', @@ -596,6 +627,7 @@ function! s:functionHighlightGroup(testname, value) let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunc @@ -618,6 +650,7 @@ endfunc function! s:functionCallHighlightGroup(testname, value) let l:package = tolower(a:testname) + let l:wd = getcwd() let l:dir = gotest#write_file(printf('%s/%s.go', l:package, a:testname), [ \ printf('package %s', l:package), \ '', @@ -633,6 +666,7 @@ function! s:functionCallHighlightGroup(testname, value) let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name') return l:actual finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunc diff --git a/autoload/go/impl_test.vim b/autoload/go/impl_test.vim index 1ee31ae2de..7aa18ea820 100644 --- a/autoload/go/impl_test.vim +++ b/autoload/go/impl_test.vim @@ -3,6 +3,7 @@ let s:cpo_save = &cpo set cpo&vim func! Test_impl() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#write_file('a/a.go', [ @@ -16,11 +17,13 @@ func! Test_impl() abort \ ' panic("not implemented") // TODO: Implement', \ '}']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_impl_get() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#write_file('a/a.go', [ @@ -38,6 +41,7 @@ func! Test_impl_get() abort \ ' panic("not implemented") // TODO: Implement', \ '}']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/import_test.vim b/autoload/go/import_test.vim index 46a7ce123c..55beb45411 100644 --- a/autoload/go/import_test.vim +++ b/autoload/go/import_test.vim @@ -3,6 +3,7 @@ let s:cpo_save = &cpo set cpo&vim func! Test_SwitchImportAddIgnoresCommented() + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#write_file('import/import.go', [ @@ -25,6 +26,7 @@ func! Test_SwitchImportAddIgnoresCommented() let l:actual = getline(4) call assert_equal("\t" . '"fmt"', l:actual) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/indent_test.vim b/autoload/go/indent_test.vim index fffdee9df8..868fcdf7cc 100644 --- a/autoload/go/indent_test.vim +++ b/autoload/go/indent_test.vim @@ -7,6 +7,7 @@ func! Test_indent_raw_string() abort syntax on let g:go_gopls_enabled = 0 + let l:wd = getcwd() try let l:dir= gotest#write_file('indent/indent.go', [ \ 'package main', @@ -23,9 +24,11 @@ func! Test_indent_raw_string() abort let l:indent = indent(line('.')) call assert_equal(0, l:indent) finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry + let l:wd = getcwd() try let l:dir= gotest#write_file('indent/indent.go', [ \ 'package main', @@ -43,8 +46,10 @@ func! Test_indent_raw_string() abort call assert_equal(0, l:indent) finally call delete(l:dir, 'rf') + call go#util#Chdir(l:wd) endtry + let l:wd = getcwd() try let l:dir= gotest#write_file('indent/indent.go', [ \ 'package main', @@ -62,6 +67,7 @@ func! Test_indent_raw_string() abort let l:indent = indent(line('.')) call assert_equal(shiftwidth(), l:indent) finally + call go#util#Chdir(l:wd) call delete(l:dir, 'rf') endtry endfunc diff --git a/autoload/go/job_test.vim b/autoload/go/job_test.vim index 9fb9633aa9..261a2bfec8 100644 --- a/autoload/go/job_test.vim +++ b/autoload/go/job_test.vim @@ -7,6 +7,7 @@ func! Test_JobDirWithSpaces() return endif + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:filename = 'job/dir has spaces/main.go' @@ -40,6 +41,7 @@ func! Test_JobDirWithSpaces() call gotest#assert_quickfix(actual, l:expected) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/lint_test.vim b/autoload/go/lint_test.vim index 423b66e46b..74ce284b74 100644 --- a/autoload/go/lint_test.vim +++ b/autoload/go/lint_test.vim @@ -120,6 +120,7 @@ func! Test_GometaAutoSaveStaticcheckKeepsErrors() abort endfunc func! s:gometaautosave(metalinter, withList) abort + let l:wd = getcwd() let l:tmp = gotest#load_fixture('lint/src/lint/lint.go') try @@ -172,6 +173,7 @@ func! s:gometaautosave(metalinter, withList) abort call gotest#assert_quickfix(l:actual, l:expected) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc @@ -358,6 +360,7 @@ endfunc func! Test_Vet() abort let g:go_gopls_enabled = 0 + let l:wd = getcwd() let l:tmp = gotest#load_fixture('lint/src/vet/vet.go') try @@ -389,12 +392,14 @@ func! Test_Vet() abort call gotest#assert_quickfix(actual, expected) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_Vet_subdir() abort let g:go_gopls_enabled = 0 + let l:wd = getcwd() let l:tmp = gotest#load_fixture('lint/src/vet/vet.go') " go up one directory to easily test that go vet's file paths are handled @@ -431,12 +436,14 @@ func! Test_Vet_subdir() abort call gotest#assert_quickfix(actual, expected) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_Vet_compilererror() abort let g:go_gopls_enabled = 0 + let l:wd = getcwd() let l:tmp = gotest#load_fixture('lint/src/vet/compilererror/compilererror.go') try @@ -460,6 +467,7 @@ func! Test_Vet_compilererror() abort call gotest#assert_quickfix(actual, expected) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc @@ -591,6 +599,7 @@ endfunc func! Test_Errcheck_compilererror() abort let g:go_gopls_enabled = 0 + let l:wd = getcwd() let l:tmp = gotest#load_fixture('lint/src/errcheck/compilererror/compilererror.go') try @@ -605,6 +614,7 @@ func! Test_Errcheck_compilererror() abort call gotest#assert_quickfix(getqflist(), expected) call assert_equal(l:bufnr, bufnr('')) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/lsp_test.vim b/autoload/go/lsp_test.vim index e51ae216bc..4e280ce16c 100644 --- a/autoload/go/lsp_test.vim +++ b/autoload/go/lsp_test.vim @@ -21,6 +21,7 @@ function! s:getinfo(str, name) return endif + let l:wd = getcwd() try let g:go_info_mode = 'gopls' @@ -37,11 +38,13 @@ function! s:getinfo(str, name) let l:actual = go#lsp#GetInfo() call assert_equal(l:expected, l:actual) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunction func! Test_Format() abort + let l:wd = getcwd() try let expected = join(readfile("test-fixtures/lsp/fmt/format_golden.go"), "\n") let l:tmp = gotest#load_fixture('lsp/fmt/format.go') @@ -53,11 +56,13 @@ func! Test_Format() abort call assert_equal(expected, actual) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_Format_SingleNewline() abort + let l:wd = getcwd() try let expected = join(readfile("test-fixtures/lsp/fmt/format_golden.go"), "\n") let l:tmp = gotest#load_fixture('lsp/fmt/newline.go') @@ -69,11 +74,13 @@ func! Test_Format_SingleNewline() abort call assert_equal(expected, actual) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_Imports() abort + let l:wd = getcwd() try let expected = join(readfile("test-fixtures/lsp/imports/imports_golden.go"), "\n") let l:tmp = gotest#load_fixture('lsp/imports/imports.go') @@ -85,6 +92,7 @@ func! Test_Imports() abort call assert_equal(expected, actual) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/tags_test.vim b/autoload/go/tags_test.vim index 4c341b5cc1..cf4e67ca22 100644 --- a/autoload/go/tags_test.vim +++ b/autoload/go/tags_test.vim @@ -3,29 +3,34 @@ let s:cpo_save = &cpo set cpo&vim func! TestAddTags() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#load_fixture('tags/add_all_input.go') silent call go#tags#run(0, 0, 40, "add", bufname(''), 1) call gotest#assert_fixture('tags/add_all_golden.go') finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! TestAddTags_WithOptions() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#load_fixture('tags/add_all_input.go') silent call go#tags#run(0, 0, 40, "add", bufname(''), 1, 'json,omitempty') call gotest#assert_fixture('tags/add_all_golden_options.go') finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! TestAddTags_AddOptions() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#load_fixture('tags/add_all_input.go') @@ -34,17 +39,20 @@ func! TestAddTags_AddOptions() abort silent call go#tags#run(0, 0, 40, "add", bufname(''), 1, 'json,omitempty') call gotest#assert_fixture('tags/add_all_golden_options.go') finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_remove_tags() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#load_fixture('tags/remove_all_input.go') silent call go#tags#run(0, 0, 40, "remove", bufname(''), 1) call gotest#assert_fixture('tags/remove_all_golden.go') finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/template_test.vim b/autoload/go/template_test.vim index 1e7f0863cd..4174c445e4 100644 --- a/autoload/go/template_test.vim +++ b/autoload/go/template_test.vim @@ -4,6 +4,7 @@ set cpo&vim func! Test_TemplateCreate() abort let g:go_gopls_enabled = 0 + let l:wd = getcwd() try let l:tmp = gotest#write_file('foo/empty.txt', ['']) @@ -14,9 +15,11 @@ func! Test_TemplateCreate() abort \ '\tfmt.Println("vim-go")', \ '}']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry + let l:wd = getcwd() try let l:tmp = gotest#write_file('foo/empty.txt', ['']) edit foo/bar_test.go @@ -26,11 +29,13 @@ func! Test_TemplateCreate() abort \ '\t// t.Fatal("not implemented")', \ '}']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_TemplateCreate_UsePkg() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#write_file('foo/empty.txt', ['']) @@ -40,11 +45,13 @@ func! Test_TemplateCreate_UsePkg() abort call gotest#assert_buffer(0, ['package foo']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_TemplateCreate_PackageExists() abort + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:tmp = gotest#write_file('quux/quux.go', ['package foo']) @@ -53,6 +60,7 @@ func! Test_TemplateCreate_PackageExists() abort call gotest#assert_buffer(0, ['package foo']) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/term_test.vim b/autoload/go/term_test.vim index f43a65fc50..f7c7123bd1 100644 --- a/autoload/go/term_test.vim +++ b/autoload/go/term_test.vim @@ -7,6 +7,7 @@ func! Test_GoTermNewMode() return endif + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:filename = 'term/term.go' @@ -33,6 +34,7 @@ func! Test_GoTermNewMode() finally call win_gotoid(l:winid) only! + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc @@ -42,6 +44,7 @@ func! Test_GoTermNewMode_SplitRight() return endif + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:filename = 'term/term.go' @@ -68,6 +71,7 @@ func! Test_GoTermNewMode_SplitRight() finally call win_gotoid(l:winid) only! + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') set nosplitright endtry @@ -78,6 +82,7 @@ func! Test_GoTermReuse() return endif + let l:wd = getcwd() try let g:go_gopls_enabled = 0 let l:filename = 'term/term.go' @@ -121,6 +126,7 @@ func! Test_GoTermReuse() finally call win_gotoid(l:winid) only! + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc diff --git a/autoload/go/tool_test.vim b/autoload/go/tool_test.vim index 9e3a563a81..eba86e3f0e 100644 --- a/autoload/go/tool_test.vim +++ b/autoload/go/tool_test.vim @@ -4,6 +4,7 @@ set cpo&vim func! Test_ExecuteInDir() abort let g:go_gopls_enabled = 0 + let l:wd = getcwd() let l:tmp = gotest#write_file('a/a.go', ['package a']) try let l:cwd = go#util#Exec(['pwd']) @@ -11,12 +12,14 @@ func! Test_ExecuteInDir() abort call assert_notequal(l:cwd, l:out) call assert_equal([l:tmp . "/src/a\n", 0], l:out) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc func! Test_ExecuteInDir_nodir() abort let g:go_gopls_enabled = 0 + let l:wd = getcwd() let l:tmp = go#util#tempdir("executeindir") exe ':e ' . l:tmp . '/new-dir/a' @@ -24,6 +27,7 @@ func! Test_ExecuteInDir_nodir() abort let l:out = go#util#ExecInDir(['pwd']) call assert_equal(['', 1], l:out) finally + call go#util#Chdir(l:wd) call delete(l:tmp, 'rf') endtry endfunc