Skip to content

Commit

Permalink
tests: change directories before deleting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bhcleek committed Jun 12, 2023
1 parent ddbab88 commit d57b398
Show file tree
Hide file tree
Showing 19 changed files with 140 additions and 0 deletions.
2 changes: 2 additions & 0 deletions autoload/go/calls_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions autoload/go/cmd_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions autoload/go/complete_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions autoload/go/config_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func! Test_GoplsEnabled_Clear() abort
return
endif

let l:wd = getcwd()
try
let g:go_gopls_enabled = 0

Expand All @@ -94,6 +95,7 @@ func! Test_GoplsEnabled_Clear() abort
\ ] )

finally
call go#util#Chdir(l:wd)
call delete(l:tmp, 'rf')
endtry
endfunc
Expand Down
8 changes: 8 additions & 0 deletions autoload/go/debug_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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': '<nowait>'}}
Expand All @@ -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
Expand All @@ -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')
Expand All @@ -129,6 +134,7 @@ function! Test_GoDebugStopRemovesPlugMappings() abort
endwhile
call assert_equal('', maparg('<Plug>(go-debug-stop'))
finally
call go#util#Chdir(l:wd)
call delete(l:tmp, 'rf')
endtry
endfunction
Expand All @@ -141,6 +147,7 @@ function! s:debug(...) abort
return
endif

let l:wd = getcwd()
try
let g:go_gopls_enabled = 0
let $oldgopath = $GOPATH
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions autoload/go/def_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -83,6 +89,7 @@ func! Test_DefJump_gopls_simple_first() abort
return
endif

let l:wd = getcwd()
try
let g:go_def_mode = 'gopls'

Expand All @@ -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
Expand All @@ -117,6 +125,7 @@ func! Test_DefJump_gopls_simple_last() abort
return
endif

let l:wd = getcwd()
try
let g:go_def_mode = 'gopls'

Expand All @@ -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
Expand All @@ -151,6 +161,7 @@ func! Test_DefJump_gopls_MultipleCodeUnit_first() abort
return
endif

let l:wd = getcwd()
try
let g:go_def_mode = 'gopls'

Expand All @@ -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
Expand All @@ -185,6 +197,7 @@ func! Test_DefJump_gopls_MultipleCodeUnit_last() abort
return
endif

let l:wd = getcwd()
try
let g:go_def_mode = 'gopls'

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions autoload/go/extract_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -36,6 +37,7 @@ func! Test_Extract() abort
\ '}'])

finally
call go#util#Chdir(l:wd)
call delete(l:tmp, 'rf')
endtry
endfunc
Expand Down
16 changes: 16 additions & 0 deletions autoload/go/fillstruct_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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', [
Expand All @@ -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', [
Expand All @@ -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', [
Expand Down Expand Up @@ -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', [
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit d57b398

Please sign in to comment.