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

cmd: fix :GoTestCompile leaving behind artifacts #909

Merged
merged 1 commit into from
Jun 22, 2016
Merged
Show file tree
Hide file tree
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
20 changes: 8 additions & 12 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ endfunction
function! go#cmd#Test(bang, compile, ...)
let args = ["test"]

" don't run the test, only compile it. Useful to capture and fix errors or
" to create a test binary.
" don't run the test, only compile it. Useful to capture and fix errors.
if a:compile
let compile_file = "vim-go-test-compile"
call extend(args, ["-c", "-o", compile_file])
Expand Down Expand Up @@ -233,25 +232,21 @@ function! go#cmd#Test(bang, compile, ...)
redraw

let command = "go " . join(args, ' ')

let out = go#tool#ExecuteInDir(command)

let l:listtype = "quickfix"

let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
execute cd fnameescape(expand("%:p:h"))

if a:compile
call delete(compile_file)
endif

if go#util#ShellError() != 0
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
try
execute cd fnameescape(expand("%:p:h"))
let errors = go#tool#ParseErrors(split(out, '\n'))
let errors = go#tool#FilterValids(errors)
finally
execute cd . fnameescape(dir)
endtry
let errors = go#tool#ParseErrors(split(out, '\n'))
let errors = go#tool#FilterValids(errors)

call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
Expand All @@ -272,6 +267,7 @@ function! go#cmd#Test(bang, compile, ...)
echon "vim-go: " | echohl Function | echon "[test] PASS" | echohl None
endif
endif
execute cd . fnameescape(dir)
endfunction

" Testfunc runs a single test that surrounds the current cursor position.
Expand Down
20 changes: 11 additions & 9 deletions autoload/go/jobcontrol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ endfunction
" it'll be closed.
function! s:on_exit(job_id, exit_status)
let std_combined = self.stderr + self.stdout

let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
execute cd self.dir

call s:callback_handlers_on_exit(s:jobs[a:job_id], a:exit_status, std_combined)

if a:exit_status == 0
Expand All @@ -123,21 +128,18 @@ function! s:on_exit(job_id, exit_status)

let self.state = "SUCCESS"
call go#util#EchoSuccess("SUCCESS")

execute cd . fnameescape(dir)
return
endif

let self.state = "FAILED"
call go#util#EchoError("FAILED")

let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
try
execute cd self.dir
let errors = go#tool#ParseErrors(std_combined)
let errors = go#tool#FilterValids(errors)
finally
execute cd . fnameescape(dir)
endtry
let errors = go#tool#ParseErrors(std_combined)
let errors = go#tool#FilterValids(errors)

execute cd . fnameescape(dir)

if !len(errors)
" failed to parse errors, output the original content
Expand Down