diff --git a/CHANGELOG.md b/CHANGELOG.md index e46917fb8d..40eae344e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,6 @@ IMPROVEMENTS: BUG FIXES: -* Term mode: fix closing location list if result is succesfull after a failed attempt [gh-768] +* Term mode: fix closing location list if result is successful after a failed attempt [gh-768] * Syntax: fix gotexttmpl identifier highlighting [gh-778] diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000..64346ff0aa --- /dev/null +++ b/Rakefile @@ -0,0 +1,13 @@ +#!/usr/bin/env rake + +task :ci => [:dump, :test] + +task :dump do + sh 'vim --version' +end + +# Firstly, `bundle install; bundle install --deployment` +# Then, `rake test` +task :test do + sh 'bundle exec vim-flavor test' +end diff --git a/VimFlavor b/VimFlavor new file mode 100644 index 0000000000..a5cacbd9da --- /dev/null +++ b/VimFlavor @@ -0,0 +1 @@ +flavor 'fatih/vim-go', '~> 1.5' diff --git a/autoload/go/cmd.vim b/autoload/go/cmd.vim index c82e0e8c1b..69a08f3c95 100644 --- a/autoload/go/cmd.vim +++ b/autoload/go/cmd.vim @@ -290,47 +290,6 @@ function! go#cmd#TestFunc(bang, ...) call call('go#cmd#Test', args) endfunction -let s:coverage_handler_id = '' -let s:coverage_handler_jobs = {} - -function! s:coverage_handler(job, exit_status, data) - if !has_key(s:coverage_handler_jobs, a:job.id) - return - endif - let l:tmpname = s:coverage_handler_jobs[a:job.id] - if a:exit_status == 0 - let openHTML = 'go tool cover -html='.l:tmpname - call go#tool#ExecuteInDir(openHTML) - endif - call delete(l:tmpname) - unlet s:coverage_handler_jobs[a:job.id] -endfunction - -" Coverage creates a new cover profile with 'go test -coverprofile' and opens -" a new HTML coverage page from that profile. -function! go#cmd#Coverage(bang, ...) - let l:tmpname=tempname() - let args = [a:bang, 0, "-coverprofile", l:tmpname] - - if a:0 - call extend(args, a:000) - endif - let id = call('go#cmd#Test', args) - if has('nvim') - if s:coverage_handler_id == '' - let s:coverage_handler_id = go#jobcontrol#AddHandler(function('s:coverage_handler')) - endif - let s:coverage_handler_jobs[id] = l:tmpname - return - endif - if !v:shell_error - let openHTML = 'go tool cover -html='.l:tmpname - call go#tool#ExecuteInDir(openHTML) - endif - - call delete(l:tmpname) -endfunction - " Generate runs 'go generate' in similar fashion to go#cmd#Build() function! go#cmd#Generate(bang, ...) let default_makeprg = &makeprg diff --git a/autoload/go/coverage.vim b/autoload/go/coverage.vim new file mode 100644 index 0000000000..367c7acf6d --- /dev/null +++ b/autoload/go/coverage.vim @@ -0,0 +1,239 @@ +let s:toggle = 0 + +" Buffer creates a new cover profile with 'go test -coverprofile' and changes +" teh current buffers highlighting to show covered and uncovered sections of +" the code. If run again it clears the annotation +function! go#coverage#Buffer(bang, ...) + if s:toggle + call go#coverage#Clear() + return + endif + + let s:toggle = 1 + let l:tmpname=tempname() + let args = [a:bang, 0, "-coverprofile", l:tmpname] + + if a:0 + call extend(args, a:000) + endif + "TODO: add -coverpkg options based on current buf list + let id = call('go#cmd#Test', args) + if has('nvim') + if s:coverage_handler_id == '' + let s:coverage_handler_id = go#jobcontrol#AddHandler(function('s:coverage_handler')) + endif + let s:coverage_handler_jobs[id] = l:tmpname + return + endif + if !v:shell_error + call go#coverage#overlay(l:tmpname) + endif + call delete(l:tmpname) +endfunction + +" Clear clears and resets the buffer annotation matches +function! go#coverage#Clear() + if exists("g:syntax_on") | syntax enable | endif + + if exists("s:toggle") | let s:toggle = 0 | endif + + " remove the autocmd we defined + if exists("#BufWinLeave#") + autocmd! BufWinLeave + endif + + call clearmatches() +endfunction + +" Browser creates a new cover profile with 'go test -coverprofile' and opens +" a new HTML coverage page from that profile in a new browser +function! go#coverage#Browser(bang, ...) + let l:tmpname=tempname() + let args = [a:bang, 0, "-coverprofile", l:tmpname] + + if a:0 + call extend(args, a:000) + endif + let id = call('go#cmd#Test', args) + if has('nvim') + if s:coverage_browser_handler_id == '' + let s:coverage_browser_handler_id = go#jobcontrol#AddHandler(function('s:coverage_browser_handler')) + endif + let s:coverage_browser_handler_jobs[id] = l:tmpname + return + endif + if !v:shell_error + let openHTML = 'go tool cover -html='.l:tmpname + call go#tool#ExecuteInDir(openHTML) + endif + + call delete(l:tmpname) +endfunction + +" Parses a single line from the cover file generated via go test -coverprofile +" and returns a single coverage profile block. +function! go#coverage#parsegocoverline(line) + " file:startline.col,endline.col numstmt count + let mx = '\([^:]\+\):\(\d\+\)\.\(\d\+\),\(\d\+\)\.\(\d\+\)\s\(\d\+\)\s\(\d\+\)' + let tokens = matchlist(a:line, mx) + let ret = {} + let ret.file = tokens[1] + let ret.startline = str2nr(tokens[2]) + let ret.startcol = str2nr(tokens[3]) + let ret.endline = str2nr(tokens[4]) + let ret.endcol = str2nr(tokens[5]) + let ret.numstmt = tokens[6] + let ret.cnt = tokens[7] + return ret +endfunction + +" Generates matches to be added to matchaddpos for the given coverage profile +" block +function! go#coverage#genmatch(cov) + let color = 'covered' + if a:cov.cnt == 0 + let color = 'uncover' + endif + + let matches = [] + + " if start and end are the same, also specify the byte length + " example: foo.go:92.2,92.65 1 0 + if a:cov.startline == a:cov.endline + call add(matches, { + \ 'group': color, + \ 'pos': [[a:cov.startline, a:cov.startcol, a:cov.endcol - a:cov.startcol]], + \ 'priority': 2, + \ }) + return matches + endif + + " add start columns. Because we don't know the length of the of + " the line, we assume it is at maximum 200 bytes. I know this is hacky, + " but that's only way of fixing the issue + call add(matches, { + \ 'group': color, + \ 'pos': [[a:cov.startline, a:cov.startcol, 200]], + \ 'priority': 2, + \ }) + + " and then the remaining lines + let start_line = a:cov.startline + while start_line < a:cov.endline + let start_line += 1 + call add(matches, { + \ 'group': color, + \ 'pos': [[start_line]], + \ 'priority': 2, + \ }) + endwhile + + " finally end columns + call add(matches, { + \ 'group': color, + \ 'pos': [[a:cov.endline, a:cov.endcol-1]], + \ 'priority': 2, + \ }) + + return matches +endfunction + +" Reads the given coverprofile file and annotates the current buffer +function! go#coverage#overlay(file) + if !filereadable(a:file) + return + endif + let lines = readfile(a:file) + + " cover mode, by default it's 'set'. Just here for debugging purposes + let mode = lines[0] + + " contains matches for matchaddpos() + let matches = [] + + " first mark all lines as normaltext. We use a custom group to not + " interfere with other buffers highlightings. Because the priority is + " lower than the cover and uncover matches, it'll be overriden. + let cnt = 1 + while cnt <= line('$') + call add(matches, {'group': 'normaltext', 'pos': [cnt], 'priority': 1}) + let cnt += 1 + endwhile + + let fname = expand('%:t') + + " when called for a _test.go file, run the coverage for the actuall file + " file + if fname =~# '^\f\+_test\.go$' + let l:root = split(fname, '_test.go$')[0] + let fname = l:root . ".go" + + " open the alternate file to show the coverage + exe ":edit ". fname + endif + + for line in lines[1:] + let cov = go#coverage#parsegocoverline(line) + + " TODO(arslan): for now only include the coverage for the current + " buffer + if fname != fnamemodify(cov.file, ':t') + continue + endif + + call extend(matches, go#coverage#genmatch(cov)) + endfor + + syntax manual + highlight normaltext term=bold ctermfg=59 guifg=#75715E + highlight covered term=bold ctermfg=118 guifg=#A6E22E + highlight uncover term=bold ctermfg=197 guifg=#F92672 + + " clear the matches if we leave the buffer + autocmd BufWinLeave call go#coverage#Clear() + + for m in matches + call matchaddpos(m.group, m.pos) + endfor +endfunction + + +" ----------------------- +" | Neovim job handlers | +" ----------------------- + +let s:coverage_handler_id = '' +let s:coverage_handler_jobs = {} + +function! s:coverage_handler(job, exit_status, data) + if !has_key(s:coverage_handler_jobs, a:job.id) + return + endif + let l:tmpname = s:coverage_handler_jobs[a:job.id] + if a:exit_status == 0 + call go#coverage#overlay(l:tmpname) + endif + + call delete(l:tmpname) + unlet s:coverage_handler_jobs[a:job.id] +endfunction + + +let s:coverage_browser_handler_id = '' +let s:coverage_browser_handler_jobs = {} + +function! s:coverage_browser_handler(job, exit_status, data) + if !has_key(s:coverage_browser_handler_jobs, a:job.id) + return + endif + let l:tmpname = s:coverage_browser_handler_jobs[a:job.id] + if a:exit_status == 0 + let openHTML = 'go tool cover -html='.l:tmpname + call go#tool#ExecuteInDir(openHTML) + endif + call delete(l:tmpname) + unlet s:coverage_browser_handler_jobs[a:job.id] +endfunction + + +" vim:ts=4:sw=4:et diff --git a/doc/vim-go.txt b/doc/vim-go.txt index 08ad5bcdbb..5b9a985d5a 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -323,13 +323,22 @@ COMMANDS *go-commands* If [!] is not given the first error is jumped to. - If using neovim `:GoTestCompile` will run in a new terminal or run asynchronously - in the background according to |g:go_term_enabled|. You can set the mode of - the new terminal with |g:go_term_mode|. + If using neovim `:GoTestCompile` will run in a new terminal or run + asynchronously in the background according to |g:go_term_enabled|. You can + set the mode of the new terminal with |g:go_term_mode|. *:GoCoverage* :GoCoverage[!] [options] + Create a coverage profile and annotates the current file's source code. If + called again clears the annotation (works as a toggle) + + If [!] is not given the first error is jumped to. + + + *:GoCoverageBrowser* +:GoCoverageBrowser[!] [options] + Create a coverage profile and open a browser to display the annotated source code of the current package. diff --git a/ftplugin/go/commands.vim b/ftplugin/go/commands.vim index 4c4f070ad4..a6bccae325 100644 --- a/ftplugin/go/commands.vim +++ b/ftplugin/go/commands.vim @@ -26,7 +26,10 @@ command! -nargs=* -bang GoInstall call go#cmd#Install(0, ) command! -nargs=* -bang GoTest call go#cmd#Test(0, 0, ) command! -nargs=* -bang GoTestFunc call go#cmd#TestFunc(0, ) command! -nargs=* -bang GoTestCompile call go#cmd#Test(0, 1, ) -command! -nargs=* -bang GoCoverage call go#cmd#Coverage(0, ) + +" -- cover +command! -nargs=* -bang GoCoverage call go#coverage#Buffer(0, ) +command! -nargs=* -bang GoCoverageBrowser call go#coverage#Browser(0, ) " -- play command! -nargs=0 -range=% GoPlay call go#play#Share(, , ) diff --git a/ftplugin/go/mappings.vim b/ftplugin/go/mappings.vim index 2529a845d1..d1afbbc484 100644 --- a/ftplugin/go/mappings.vim +++ b/ftplugin/go/mappings.vim @@ -23,7 +23,9 @@ nnoremap (go-install) :call go#cmd#Install(!g:go_jump_to_err nnoremap (go-test) :call go#cmd#Test(!g:go_jump_to_error, 0) nnoremap (go-test-func) :call go#cmd#TestFunc(!g:go_jump_to_error) nnoremap (go-test-compile) :call go#cmd#Test(!g:go_jump_to_error, 1) -nnoremap (go-coverage) :call go#cmd#Coverage(!g:go_jump_to_error) + +nnoremap (go-coverage) :call go#coverage#Buffer(!g:go_jump_to_error) +nnoremap (go-coverage-browser) :call go#coverage#Browser(!g:go_jump_to_error) nnoremap (go-files) :call go#tool#Files() nnoremap (go-deps) :call go#tool#Deps() diff --git a/t/coverlay.vim b/t/coverlay.vim new file mode 100644 index 0000000000..9d60c21d6b --- /dev/null +++ b/t/coverlay.vim @@ -0,0 +1,191 @@ +" to execute, `rake test` on parent dir + +describe 'go#coverage#Buffer' + before + new + let g:curdir = expand(':p:h') . '/' + let g:srcpath = 't/fixtures/src/' + let g:sample = 'pkg1/sample.go' + let g:sampleabs = g:curdir . g:srcpath . 'pkg1/sample.go' + let g:samplecover = g:curdir . g:srcpath . 'pkg1/sample.out' + let g:go_gopath = g:curdir . 't/fixtures' + execute "badd " . g:srcpath . g:sample + execute "buffer " . bufnr("$") + end + after + execute "bprev" + execute "bdelete " . g:srcpath . g:sample + close! + end + + it 'puts match to the list' + call go#coverage#Buffer(0) + Expect len(go#coverlay#matches()) == 5 + call go#coverlay#Clearlay() + Expect len(go#coverlay#matches()) == 0 + + call go#coverage#Buffer(0) + Expect len(go#coverlay#matches()) == 5 + call go#coverlay#Clearlay() + Expect len(go#coverlay#matches()) == 0 + + call go#coverage#Buffer(0) + Expect len(go#coverlay#matches()) == 5 + call go#coverage#Buffer(0) + Expect len(go#coverlay#matches()) == 5 + call go#coverlay#Clearlay() + Expect len(go#coverlay#matches()) == 0 + end +end + +describe 'go#coverage#Buffer fail' + before + new + let g:curdir = expand(':p:h') . '/' + let g:srcpath = 't/fixtures/src/' + let g:sample = 'failtest/sample.go' + let g:sampletest = 'failtest/sample_test.go' + let g:sampleabs = g:curdir . g:srcpath . 'failtest/sample.go' + let g:go_gopath = g:curdir . 't/fixtures' + execute "badd " . g:srcpath . g:sample + execute "buffer " . bufnr("$") + end + after + execute "bprev" + execute "bdelete " . g:srcpath . g:sampletest + execute "bdelete " . g:srcpath . g:sample + end + + it 'does nothing if test fail' + call go#coverage#Buffer(0) + Expect len(go#coverlay#matches()) == 0 + Expect len(getqflist()) == 1 + end +end + +describe 'go#coverage#Buffer build fail' + before + new + let g:curdir = expand(':p:h') . '/' + let g:srcpath = 't/fixtures/src/' + let g:sample = 'buildfail/sample.go' + let g:sampleabs = g:curdir . g:srcpath . 'buildfail/sample.go' + let g:go_gopath = g:curdir . 't/fixtures' + execute "badd " . g:srcpath . g:sample + execute "buffer " . bufnr("$") + end + after + execute "bprev" + execute "bdelete " . g:srcpath . g:sample + end + + it 'does nothing if test fail' + call go#coverage#Buffer(0) + Expect len(go#coverlay#matches()) == 0 + end +end + +describe 'go#coverage#Buffer build test fail' + before + new + let g:curdir = expand(':p:h') . '/' + let g:srcpath = 't/fixtures/src/' + let g:sample = 'buildtestfail/sample.go' + let g:sampleabs = g:curdir . g:srcpath . 'buildtestfail/sample.go' + let g:go_gopath = g:curdir . 't/fixtures' + execute "badd " . g:srcpath . g:sample + execute "buffer " . bufnr("$") + end + after + execute "bprev" + execute "bdelete " . g:srcpath . g:sample + end + + it 'does nothing if test fail' + call go#coverage#Buffer(0) + Expect len(go#coverlay#matches()) == 0 + end +end + +describe 'go#coverlay#findbufnr' + before + new + let g:curdir = expand(':p:h') . '/' + let g:srcpath = 't/fixtures/src/' + let g:sample = 'pkg1/sample.go' + let g:sample2 = 'pkg2/sample.go' + let g:sampleabs = g:curdir . g:srcpath . 'pkg1/sample.go' + let g:sampleabs2 = g:curdir . g:srcpath . 'pkg2/sample.go' + let g:go_gopath = g:curdir . 't/fixtures' + execute "badd " . g:srcpath . g:sample + execute "badd " . g:srcpath . g:sample2 + end + after + execute "bdelete " . g:srcpath . g:sample2 + execute "bdelete " . g:srcpath . g:sample + close! + end + + it 'returns BUFNR if FILE is opened at BUFNR' + Expect go#coverlay#findbufnr('_' . g:sampleabs) == bufnr(g:sampleabs) + Expect go#coverlay#findbufnr(g:sample) == bufnr(g:sampleabs) + + Expect go#coverlay#findbufnr('_' . g:sampleabs2) == bufnr(g:sampleabs2) + Expect go#coverlay#findbufnr(g:sample2) == bufnr(g:sampleabs2) + end + + it 'returns -1 if FILE is not exists' + Expect go#coverlay#findbufnr('pkg1/NOTEXISTS.go') == -1 + Expect go#coverlay#findbufnr('_' . g:curdir . g:srcpath . 'pkg1/NOTEXISTS.go') == -1 + end +end + +describe 'go#coverlay#isopenedon' + before + new + let g:curdir = expand(':p:h') . '/' + let g:srcpath = 't/fixtures/src/' + let g:sample = 'pkg1/sample.go' + let g:sampleabs = g:curdir . g:srcpath . 'pkg1/sample.go' + let g:go_gopath = g:curdir . 't/fixtures' + execute "badd " . g:srcpath . g:sample + end + after + execute "bdelete " . g:srcpath . g:sample + close! + end + + it 'returns 1 if FILE is opened at BUFNR' + Expect go#coverlay#isopenedon('_' . g:sampleabs, bufnr(g:sampleabs)) == 1 + Expect go#coverlay#isopenedon(g:sample, bufnr(g:sampleabs)) == 1 + end + + it 'returns 0 if FILE is not opened at BUFNR' + Expect go#coverlay#isopenedon('_' . g:sampleabs, 42) == 0 + Expect go#coverlay#isopenedon(g:sample, 42) == 0 + end + + it 'returns 0 if FILE is not exists' + Expect go#coverlay#isopenedon('_' . g:curdir . g:srcpath . 'pkg1/NOTEXISTS', bufnr(g:sampleabs)) == 0 + Expect go#coverlay#isopenedon('pkg1/NOTEXISTS.go', bufnr(g:sampleabs)) == 0 + end +end + + + +describe 'go#coverlay#parsegocoverline' + it 'parses a go cover output line and returns as dict' + let d = {'file': 'f',"startline": "1", "startcol": "2", "endline": "3", "endcol": "4", "numstmt": "5", "cnt": "6"} + " file:startline.col,endline.col numstmt count + Expect go#coverlay#parsegocoverline("f:1.2,3.4 5 6") == d + end +end + +describe 'go#coverlay#genmatch' + it 'generate mark pattern from cover data' + let d = {'file': 'f',"startline": "1", "startcol": "2", "endline": "3", "endcol": "4", "numstmt": "5", "cnt": "6"} + Expect go#coverlay#genmatch(d) == {'group': 'covered', "pattern": '\%>1l\_^\s\+\%<3l\|\%1l\_^\s\+\|\%3l\_^\s\+\(\}$\)\@!', "priority": 6} + let d = {'file': 'f',"startline": "1", "startcol": "2", "endline": "3", "endcol": "4", "numstmt": "5", "cnt": "0"} + Expect go#coverlay#genmatch(d) == {'group': 'uncover', "pattern": '\%>1l\_^\s\+\%<3l\|\%1l\_^\s\+\|\%3l\_^\s\+\(\}$\)\@!', "priority": 5} + end +end diff --git a/t/fixtures/src/buildfail/sample.go b/t/fixtures/src/buildfail/sample.go new file mode 100644 index 0000000000..45fc006afd --- /dev/null +++ b/t/fixtures/src/buildfail/sample.go @@ -0,0 +1,13 @@ +// set gopath before +//go:generate go test --coverprofile=sample.out +// go1.5.3 example output: +// GOPATH=`pwd`/fixtures go test --coverprofile=log.out buildfail +// # buildfail +// /tmp/go-build264733986/buildfail/_test/_obj_test/sample.go:7: undefined: IT_SHOULD_BE_BUILD_FAILED +// /tmp/go-build264733986/buildfail/_test/_obj_test/sample.go:8: missing return at end of function +// FAIL buildfail [build failed] +package pkg + +func Sample() int { + IT_SHOULD_BE_BUILD_FAILED +} diff --git a/t/fixtures/src/buildfail/sample_test.go b/t/fixtures/src/buildfail/sample_test.go new file mode 100644 index 0000000000..2356d3ed09 --- /dev/null +++ b/t/fixtures/src/buildfail/sample_test.go @@ -0,0 +1,7 @@ +package pkg + +import "testing" + +func TestSample(t *testing.T) { + Sample() +} diff --git a/t/fixtures/src/buildtestfail/sample.go b/t/fixtures/src/buildtestfail/sample.go new file mode 100644 index 0000000000..792f12349b --- /dev/null +++ b/t/fixtures/src/buildtestfail/sample.go @@ -0,0 +1,7 @@ +// set gopath before +//go:generate go test --coverprofile=sample.out +package pkg + +func Sample() int { + return 1 +} diff --git a/t/fixtures/src/buildtestfail/sample_test.go b/t/fixtures/src/buildtestfail/sample_test.go new file mode 100644 index 0000000000..17c4d4636e --- /dev/null +++ b/t/fixtures/src/buildtestfail/sample_test.go @@ -0,0 +1,15 @@ +// go1.5.3 example output: +// GOPATH=`pwd`/fixtures go test --coverprofile=log.out buildtestfail +// # buildtestfail +// fixtures/src/buildtestfail/sample_test.go:14: undefined: IT_SHOULD_BE_BUILD_FAILED +// FAIL buildtestfail [build failed] +// echo $? +// 2 + +package pkg + +import "testing" + +func TestSample(t *testing.T) { + IT_SHOULD_BE_BUILD_FAILED +} diff --git a/t/fixtures/src/failtest/sample.go b/t/fixtures/src/failtest/sample.go new file mode 100644 index 0000000000..5859e92624 --- /dev/null +++ b/t/fixtures/src/failtest/sample.go @@ -0,0 +1,12 @@ +// set gopath before +//go:generate go test --coverprofile=sample.out +package pkg + +func Sample() int { + if false { + return 0 + } else if false { + return 0 + } + return 1 +} diff --git a/t/fixtures/src/failtest/sample_test.go b/t/fixtures/src/failtest/sample_test.go new file mode 100644 index 0000000000..7f1ade0d73 --- /dev/null +++ b/t/fixtures/src/failtest/sample_test.go @@ -0,0 +1,8 @@ +package pkg + +import "testing" + +func TestSample(t *testing.T) { + Sample() + t.Fatal("itwillfail") +} diff --git a/t/fixtures/src/parsefail/sample.go b/t/fixtures/src/parsefail/sample.go new file mode 100644 index 0000000000..e9f3faa953 --- /dev/null +++ b/t/fixtures/src/parsefail/sample.go @@ -0,0 +1,14 @@ +// set gopath before +//go:generate go test --coverprofile=sample.out +// go1.5.3 example output: +// GOPATH=`pwd`/fixtures go test --coverprofile=log.out parsefail +// # cover parsefail +// 2016/01/17 23:59:08 cover: /home/sey/vimfiles/_vim/bundle/vim-go-coverlay/t/fixtures/src/parsefail/sample.go: /home/sey/vimfiles/_vim/bundle/vim-go-coverlay/t/fixtures/src/parsefail/sample.go:10:1: expected declaration, found 'IDENT' PARSEFAIL +// FAIL parsefail [build failed] +// echo $? +// 2 +package pkg + +PARSEFAIL Sample() int { + return 0 +} diff --git a/t/fixtures/src/parsefail/sample_test.go b/t/fixtures/src/parsefail/sample_test.go new file mode 100644 index 0000000000..2356d3ed09 --- /dev/null +++ b/t/fixtures/src/parsefail/sample_test.go @@ -0,0 +1,7 @@ +package pkg + +import "testing" + +func TestSample(t *testing.T) { + Sample() +} diff --git a/t/fixtures/src/pkg1/sample.go b/t/fixtures/src/pkg1/sample.go new file mode 100644 index 0000000000..6ce94b394b --- /dev/null +++ b/t/fixtures/src/pkg1/sample.go @@ -0,0 +1,12 @@ +// set gopath before +//go:generate go test --coverprofile=sample.out +package pkg1 + +func Sample() int { + if false { + return 0 + } else if false { + return 0 + } + return 1 +} diff --git a/t/fixtures/src/pkg1/sample.out b/t/fixtures/src/pkg1/sample.out new file mode 100644 index 0000000000..909a63f142 --- /dev/null +++ b/t/fixtures/src/pkg1/sample.out @@ -0,0 +1,6 @@ +mode: set +pkg1/sample.go:5.19,6.11 1 1 +pkg1/sample.go:11.2,11.10 1 1 +pkg1/sample.go:6.11,8.3 1 0 +pkg1/sample.go:8.3,8.18 1 1 +pkg1/sample.go:8.18,10.3 1 0 diff --git a/t/fixtures/src/pkg1/sample_test.go b/t/fixtures/src/pkg1/sample_test.go new file mode 100644 index 0000000000..e39d7ba835 --- /dev/null +++ b/t/fixtures/src/pkg1/sample_test.go @@ -0,0 +1,7 @@ +package pkg1 + +import "testing" + +func TestSample(t *testing.T) { + Sample() +}