Skip to content

Commit

Permalink
Merge pull request #909 from fatih/fix-go-test-compile
Browse files Browse the repository at this point in the history
cmd: fix :GoTestCompile leaving behind artifacts
  • Loading branch information
fatih authored Jun 22, 2016
2 parents 523d5a4 + 1457e6e commit 9875a46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
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

0 comments on commit 9875a46

Please sign in to comment.