Giter Club home page Giter Club logo

gocov's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gocov's Issues

"no test files" when all tests require a build tag

I have a package with three source files:

src/mylib/normal.go
src/mylib/optional.go
src/mylib/optional_test.go

normal.go is always compiled (no build tags), but I haven't written tests for it yet.

optional*.go are only compiled with build tag optional.

go install and go test are perfectly happy with this. But gocov test claims that the package has no test files. Presumably this is because gocov doesn't have a way to set build tags?

I have a small zip file which reproduces the problem easily. Will upload shortly.

feature request: gocov test should accept multiple packages to test

gocov should accept the path globs that go test does. ie

gocov test ./...
gocov test std

The goal is to be able to produce test coverage for an entire project, ie

gocov test launchpad.net/juju-core/... | gocov report

Internally gocov will execute an independent instrumentAndTest() for each package.

False Duplicate Package Name panic

In some cases, the 'gocov test' is generating a json file which contains duplicate package name records. This is happening despite the fact that there is not a duplicate package name. Due to this incorrect behavior the generated json is unusable by the 'gocov report' as the condition on line 88 in report.go is met and panic("package already exists: result merging not implemented yet") is executed.

gocov reports test coverage on transitive dependencies

Hello,

I may be mistaking something, but for some reason gocov will annotate and report coverage on transitive dependencies. Am I missing something, or is this a bug ?

% go get github.com/davecheney/a/...
% gocov test github.com/davecheney/a/b | gocov report
warning: building out-of-date packages:
github.com/axw/gocov
github.com/davecheney/a
time
os
fmt
flag
runtime/pprof
testing
installing these packages with 'go test -i github.com/davecheney/a/b' will speed future tests.

ok github.com/davecheney/a/b 0.008s

github.com/davecheney/a/a.go A 100.00% (1/1)
github.com/davecheney/a - 100.00% (1/1)

github.com/davecheney/a/b/b.go B 66.67% (2/3)
github.com/davecheney/a/b - 66.67% (2/3)

Why is the coverage of package a being reported ?

gocov test ./my doesn't work

gocov test ./my doesn't work (at least for a package not in GOPATH), but go test ./my works.

gocov test ./my
ok      _/Users/AlekSi/Code/secret-path/colorizer   0.009s
failed to parse gocov output: stat /var/folders/v2/xzyp4lkn5nl0gpjrs3n66_5w0000gn/T/gocov740203931/gocov.out: no such file or directory

Cannot pass parameters to `go test`

Sorry if I'm just blind to see it(1), but it seems to me that there's no way to pass-through parameters to the "underlying" 'go test'.

Specifically, my problem is that I need to add -timeout (or -test.timeout) as the package I want to run gocov against is taking about 4 minutes to test w/o the coverage tooling and it timeouts after 600 secs with it.

However, the need to pass any other parameters is a general problem, which should be addressed (if not solved already[1]).

Annotate does not work on Windows

Issue written as of commit 79dd29d

I suspect this might be a consequence of the lack of proper escaping called out in issue #23.

The error message form is:
warning: failed to annotate function "github.com///"

Note that I've verified it works properly on Ubuntu and OpenBSD, so it does appear to be isolated to Windows.

segmentation fault when using gocheck with gocov

I'm receiving the following error:
go build testmain: signal: segmentation fault

I'm using gocheck as a testing framework. This works fine unless I use gocheck in a subpackage.

I don't even know where to start debugging. Any help would be greatly appreciated.

You can see the code here:
https://github.com/imosquera/uploadthis/blob/prehooks/hooks/prehooks_test.go

You can see I'm using gocheck in the main package here:
https://github.com/imosquera/uploadthis/blob/prehooks/conf_test.go

you can also "go get" the package and test it for yourself. Don't forget to check out:
go get -v launchpad.net/gocheck

note: using "go test ./..." all works fine.

gocov doesn't use canonical package names

gocov test emits only the last part of package names, rather than the canonical package ID. For example, "gocov test exp/types" will generate output where the Package struct's Name is "types".

Package names should be changed to the canonical path/ID. The annotate command should probably be changed to take separate arguments for package path and function, as in godoc.

nil pointer dereference when using -deps

A nil pointer dereference occurs when gocov is run with the -deps option. Below shows the output from:

gocov test -deps > /dev/null

in code.google.com/p/biogo.step, but similar output occurs in any package I try.

Using -exclude='math/rand' prevents this panic which is due to calling (*Statement).At() on a nil receiver. gocov test math/rand gives essentially the same failure as expected.

This is presumably because math/rand depends on sync/atomic which is excluded from testing by gocov.

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x18 pc=0x5a30b3]

goroutine 1 [running]:
sync/atomic.AddUint64(0x18, 0x1, 0x0, 0x0, 0x572b8d, ...)
/tmp/gocov810177481/src/pkg/sync/atomic/asm_amd64.s:58 +0xd
github.com/axw/gocov.(_Statement).At(0x0, 0xf84019b960)
/tmp/gocov810177481/src/pkg/github.com/axw/gocov/gocov.go:329 +0x33
math/rand.(_rngSource).Seed(0xf840154000, 0x1, 0xf8400f90a8, 0x4)
/tmp/gocov810177481/src/pkg/math/rand/rng.go:237 +0x28
math/rand.NewSource(0x1, 0x160e00001601, 0xf84021d720, 0x70e78c)
/tmp/gocov810177481/src/pkg/math/rand/rand.go:105 +0x68
math/rand.init()
/tmp/gocov810177481/src/pkg/math/rand/zipf.go:-390 +0x1f61
code.google.com/p/biogo%2estep.init()
/tmp/gocov810177481/src/pkg/code.google.com/p/biogo.step/step.go:14 +0x5b
main.init()
code.google.com/p/biogo.step/_test/_testmain.go:18 +0x3b

Getting the expected pwd instead of the generated pwd

In my testing code, I use relative paths to pull in fixtures (non-go files). This however doesn't work because there is a new, temporary path being generated such as:

/var/folders/qy/zmrxj1t14mnbxsxrz9gtknxc0000gn/T/gocov672324733/src/pkg/github.com/imosquera/uploadthis/conf

for gocov to work. Whats the best way to get the original file path?

Gocov reports impossible misses

One slice of the output from ./bin/gocov annotate coverage/gocov.json

19      func NewUserRestController(um *um.UserMapper) UserRestController {
20 MISS     return UserRestController{
21              usermodel: um,
22          }
23      }

This doesn't seem possible to me. How can line 20 be a miss, but line 21 is not a miss?

gocov always warns packages are out of date

As the subject says, there's an annoying warning each time you run gocov test.

You might think you could just do "go test -i ..." from gocov, but you'd be wrong. That changes the behaviour of "go test" such that the GOCOVOUT environment variable doesn't get properly inherited.

I think what I'll do is run "go test -c ...", to build a binary, and then execute that directly.

Add support for test coverage merging; e.g. gocov test ./...

go test -cover refuses to run tests from multiple package at once. I wrote a function to work around this in TestCoverage.run(), see https://github.com/maruel/pre-commit-go/blob/master/checks/checks.go#L532.

It runs each package test independently and concurrently, each with their own coverage file, then merges all the coverage files into one. It's ~130 lines of code in practice.

This feature request is to handle this automatically and transparently inside gocov so that the following command would work:

gocov test ./... | gocov report

gocov doesn't like packages containing only tests

Current workaround is to add a dummy.go file so the parser returns a package.

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x20 pc=0x8387]

goroutine 1 [running]:
main.(*instrumenter).instrumentPackage(0x42358e10, 0x7fff5fbffbf2, 0x15, 0x0, 0x0, ...)
/Users/vadim/Projects/go/src/github.com/axw/gocov/gocov/main.go:274 +0xc81
main.instrumentAndTest(0x7fff00000000, 0x7fff00000004)
/Users/vadim/Projects/go/src/github.com/axw/gocov/gocov/main.go:369 +0x8bb
main.main()
/Users/vadim/Projects/go/src/github.com/axw/gocov/gocov/main.go:429 +0x16e

goroutine 2 [syscall]:
created by runtime.main
/usr/local/Cellar/go/1.0.2/src/pkg/runtime/proc.c:221

gocov output data format as standard go test does?

Is it possible to generate output in the same format as standard go test does?
Some tools require output to be in standard go test format, not json. I wonder if there is any limitation to do this. In theory it could be directly generated from json... however I'm not sure if there are any known limitations?

Compile error with Go 1.0.3 on Windows

As the title indicates, this will not compile with Go 1.0.3 on Windows as of commit cacb452.

The error message is:
$GOPATH\src\github.com\axw\gocov\io.go:35: cannot use int(w) (type int) as type syscall.Handle in function argument.

Running into "flag provided but not defined: -coverprofile"

On running "gocov test ", I run into following errors.

flag provided but not defined: -coverprofile
Usage of /var/folders/zz/4ffrsh1s5vb18wn558p9bw4w001tpw/T/go-build604129205/_/t:
-test.bench="": regular expression to select benchmarks to run
-test.benchmem=false: print memory allocations for benchmarks
-test.benchtime=1s: approximate run time for each benchmark
-test.blockprofile="": write a goroutine blocking profile to the named file after execution
-test.blockprofilerate=1: if >= 0, calls runtime.SetBlockProfileRate()
-test.cpu="": comma-separated list of number of CPUs to use for each test
-test.cpuprofile="": write a cpu profile to the named file during execution
-test.memprofile="": write a memory profile to the named file after execution
-test.memprofilerate=0: if >=0, sets runtime.MemProfileRate
-test.parallel=1: maximum test parallelism
-test.run="": regular expression to select tests and examples to run
-test.short=false: run smaller test suite to save time
-test.timeout=0: if positive, sets an aggregate time limit for all tests
-test.v=false: verbose: print additional output
exit status 2

This was working till a few weeks back. has anything changed recently in gocov command usage?

no Go source files

I'm not quite sure what's happening here, but I'm trying to run tests in github.com/couchbaselabs/cbgb/cbgb and I get the following:

/var/folders/nt/_3y11_t12szbmgshvz6zgbhh0000gn/T/gocov343768907/src/pkg/github.com/couchbaselabs/cbgb/cbgb/main.go:11:2: no Go source files in /var/folders/nt/_3y11_t12szbmgshvz6zgbhh0000gn/T/gocov343768907/src/pkg/github.com/couchbaselabs/cbgb
go test failed: exit status 1
failed to parse gocov output: stat /var/folders/nt/_3y11_t12szbmgshvz6zgbhh0000gn/T/gocov343768907/gocov.out: no such file or directory

function comment stripping breaks cgo exports

The following sort of code gets its special comment stripped which breaks packages that rely on this.

//export MyFunction
func MyFunction(arg1, arg2 int, arg3 string) int64 {...}

Upon initial inspection there doesn't appear to be a trivial solution. It seems dirty but an additional print/parse pass to get new function Pos()'s to move the comments to the right location might be workable.

Output a coverage summary

Please add an option to ouput an combined coverage of all packages examined during the last run, e.g.

gocov test ./... | gocov report -s

Expected output:

[regular gocov ouput]
combined statement coverage: xx.xx%

Pass arguments to go list

It would be nice if when test.go calls go list -e it could be passed additional parameters. If you are using modules and building in say a docker environment gocov will fail when it cannot reach an external git repo. If list respected the -m flag it should just use the vendor directory instead.

gocov is broken on Debian

Reported by @AlekSi in IRC.

gocov expects "bin" and "include" directories in $GOROOT, which Debian doesn't package. I don't think the "bin" directory is actually required, and "include" is only necessary if a C file wants to refer to the runtime headers, which currently is just C files in the runtime package.

gocov should check that the directories exist before attempting to symlink them.

If a package has no test files, the lines in that package are not added to the total line count.

As described in the issue title.

Ideally, when I run gocov test ./... under a certain project folder, I want to see the reported total line numbers be the total lines to be covered in the project, no matter whether there is test file existing for a certain package or not.

However, this is not what gocov does for now, in my experiments. It seems that if there is no test file existing for a certain package, the line numbers in that package are not added to the total line number count. (please let me know if you are not able to replicate this result. :)

Also, in some circumstances, we don't want to add tests for some packages, for example, some packages are solely for testing purposes like mocks, testdata etc. If we do want to count lines no matter whether there is test file existing, we should also add an option to ignore packages. That would make the tool report the total line numbers correctly as I expect.

Thanks!

P.S. gocov is really an awesome and handy tool! It enables and empowers me to do my testing job! :)

Regression: -tags flag broken

$ gocov test -tags="test" github.com/axw/gocov
can't load package: package test: cannot find package "test" in any of:
...

This seems to have been introduced in the latest commit: 8362a2c
The previous commit, 925c99c, seems to work as expected.

Running `gocov test` doesn't appear to test subdirectories

Here's an example directory structure:

foopackage/
        bar/
                bar.go
                bar_test.go
        foo.go
        foo_test.go

The foo.go file uses the package name foopackage and imports the bar package.

When I run gocov test, it only tests foo_test.go.
In particular, I'm trying to do gocov test | gocov annotate - or gocov test | gocov report.

Is this an issue or am I doing something wrong?

report summary

Minor feature request. Would it be possible to have summary stats added at the end of a report? For example:

github.com/mypackage/mypackage.go    Foo    66.67% (4/6)
github.com/mypackage/mypackage.go    Bar    60.00% (3/5)
github.com/mypackage/mypackage.go    Baz    50.00% (6/12)
Summary                                     56.52% (13/23)

gocov's result is different from go test

gocov's result is different from go test -cover

this is go test result:

EManager.GetClusterRoute         83.33% (20/24)

this is gocov result

EManager.GetClusterRoute(...) github.com/c/e/e.go 75.00% 

cut&paste error in method comment

The comment for method Enter on type Function is wrong, and should obviously be:

// Enter informs gocov that the function has been entered.
func (f *Function) Enter() {

NUL bytes in gocov.out

Every couple of runs I see the following error:

scanning error: illegal character NUL [/var/folders/wr/7r4xdl4x11xcqy39r6n3kfbm0000gn/T/gocov899489426/gocov.out:845:1]scanning error: illegal character NUL [/var/folders/wr/7r4xdl4x11xcqy39r6n3kfbm0000gn/T/gocov899489426/gocov.out:845:2]scanning error: illegal character U+0000 [/var/folders/wr/7r4xdl4x11xcqy39r6n3kfbm0000gn/T/gocov899489426/gocov.out:845:1]failed to parse gocov output: expected 'IDENT', found 'ILLEGAL' (/var/folders/wr/7r4xdl4x11xcqy39r6n3kfbm0000gn/T/gocov899489426/gocov.out:845:1)

Here's a hexdump of that gocov.out file with the context around the line containing NUL bytes.

0000eb50  2e 41 74 28 29 0a 67 6f  63 6f 76 4f 62 6a 65 63  |.At().gocovObjec|
0000eb60  74 38 38 2e 41 74 28 29  0a 67 6f 63 6f 76 4f 62  |t88.At().gocovOb|
0000eb70  6a 65 63 74 38 39 2e 41  74 28 29 0a 67 6f 63 6f  |ject89.At().goco|
0000eb80  76 4f 62 6a 65 63 74 39  30 2e 41 74 28 29 0a 00  |vObject90.At()..|
0000eb90  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0000eba0  00 00 67 6f 63 6f 76 4f  62 6a 65 63 74 35 35 2e  |..gocovObject55.|
0000ebb0  41 74 28 29 0a 67 6f 63  6f 76 4f 62 6a 65 63 74  |At().gocovObject|
0000ebc0  39 31 2e 41 74 28 29 0a  67 6f 63 6f 76 4f 62 6a  |91.At().gocovObj|
0000ebd0  65 63 74 35 36 2e 41 74  28 29 0a 67 6f 63 6f 76  |ect56.At().gocov|
0000ebe0  4f 62 6a 65 63 74 39 32  2e 41 74 28 29 0a 67 6f  |Object92.At().go|
0000ebf0  63 6f 76 4f 62 6a 65 63  74 35 37 2e 41 74 28 29  |covObject57.At()|

If I keep rerunning the same gocov test command, it will work eventually.

Problems if using package code.google.com/p/goprotobuf/proto

If your project uses code.google.com/p/goprotobuf/proto then gocov gives an error when run.

I have a small test project https://github.com/jose-espinosa/gocov-issue

The output that I am getting and my environment are:

Jose:gocov-issue jose$ go test
?       gocov-issue [no test files]
Jose:gocov-issue jose$ gocov test 
failed to instrument package(.): open /Users/jose/go/src/gocov-issue/testdata: no such file or directory
Jose:gocov-issue jose$ go version
go version go1.0.1
Jose:gocov-issue jose$ uname -a
Darwin Jose.local 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64

Installation windows7 fails

Install on Win7
go get github.com/axw/gocov/gocov

Error:
C:\Users\timo>go get github.com/axw/gocov/gocov
"# github.com/axw/gocov/gocov"
go\src\github.com\axw\gocov\gocov\convert.go:31: can't open import: "golang.org/
x/tools/cover": Permission denied

Feature Request: Flag to disable disable recursive behavior

First, I want to thank you for this amazing tool. I've used it to get several packages to 100% test coverage now. Fantastic.

That said, perhaps I'm missing an option, but I would like to see the ability to only instrument and report the coverage for the top-level package under test (more generally, specifically named packages). There is already a way to exclude packages by name, however, I find myself not wanting to see test coverage for dependencies far more often than I want to see it. Dependencies have their own tests which ensure they work properly.

For an actual example, https://github.com/davecgh/go-spew/spew has 100% test coverage. However, when I run gocov against another package I'm developing right now that makes use of it, it reports coverage not only for the package I'm running it against, but for spew as well. Since the package under test doesn't exercise spew fully (spew has its own tests for that), it dutifully reports low test coverage. I can, of course, exclude the package, but there are several more deps too (all of which have their own tests). This results in a ton of low percentage coverage reports that are largely irrelevant since, in my opinion, it's not the job of a top-level package to test dependencies directly.

I think it would be far easier if there were, at the very least, a flag to ignore imported packages other than the current one under test or specifically named packages on the command line. Best case for me would be to reverse the behavior altogether where gocov only tests (or at least reports) the specific named package(s) unless given a flag to recurse.

xxx MISS panic("unreachable")

In a function like

    func foo() t {
            for {
                   whatever()
                   if someCond {
                       return someValue
                   }
            }
            panic("unreachable")
    }

which is, I believe, a common Go code, the last line panic(...) is reported as MIA, but this special pattern shouldn't be IMO considered.

gocov test fails when a package is already installed

Below is the description I posted on the mailing list. Obviously this doesn't happen to everyone or people would have noticed by now :-) but it is consistently hapening in my case.

If it matters, my disks are NFS-mounted on an IT-managed server that has a daemon running around taking snapshots and so on. I run into a problem with other tools when I discovered that last-modified-date of directories gets changed to the future(!) and back as part of that process. I have no idea if this is relevant here, though, I don't see that dates have anything to do with the problem.

At any rate:

The problem seems to be that if there is an installed version of the being-tested package in my current workspace (which is the only entry in my GOPATH), somehow this version is run instead of the instrumented version in the newly created temporary workspace.

Looking at the source code I see that GOROOT is modified to point at the newly created temporary workspace, and looking at it (by using the --work flag) I see the instrumented package was successfully created there. And yet, the package is taken still taken from the original workspace - that is, from my GOPATH.

The error is, as one would expect:

ok my/package/name 0.013s
failed to parse gocov output: stat /tmp/gocov072425766/gocov.out: no such file or directory

So, I added a line (next to setting the GOROOT) that sets GOPATH to be the newly created tempDir + ":" + the old value of GOPATH. I figured this will force finding the instrumented package, but this didn't make a difference(!?!?). Just for kicks I changed GOPATH to be only tempDir, and I got the expected warning that GOPATH has no effect, and of course running the tests failed due to missing dependencies - it did find the instrumented package itself though.

Automated tests for "gocov test"

The instrumentation code has become increasingly complex. As bugs are fixed, new ones are getting introduced; automated tests would be useful to mitigate this.

annotate: option to only produce results for <100% coverage

Discovered this nice tool a few days ago. Thank you for making it available. What I would like is an option to annotate to only show routines that have less than 100% coverage (= have at least one 'miss' mark). That could be of help to quickly find out where exactly testing could be improved.
Johan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.