Open Dieterbe opened 6 years ago
When I reorganize the code a bit, it works fine:
$ pwd
/home/dieter/go/src/github.com/Dieterbe/deadtest
$ find .
.
./main.go
./foo
./foo/f.go
./foo/f_test.go
$ cat main.go
package main
import (
"fmt"
"github.com/Dieterbe/deadtest/foo"
)
func main() {
fmt.Println(foo.F(10))
}
$ cat ./foo/f.go
package foo
func F(in int) int {
return in / 10
}
$ cat ./foo/f_test.go
package foo
import "testing"
func TestF(t *testing.T) {
if F(10) != 1 {
t.Errorf("F(10) should be 1")
}
}
$ go test -v github.com/Dieterbe/deadtest/foo
=== RUN TestF
--- PASS: TestF (0.00s)
PASS
ok github.com/Dieterbe/deadtest/foo 0.001s
$ deadcode -test .
$ deadcode -test github.com/Dieterbe/deadtest/foo
$
I have the same issue.
I'm experiencing the same issue. Tests in the main
package are falsely reported as unused.
This issue has been fixed in golangci-lint
. I recommend using the forked-and-fixed deadcode
in that tool.
golangci-lint run --disable-all --enable deadcode
Hello Rémy, first of all, deadcode is a neat tool. thank you. i've used it to find some deadcode that i was able to remove.
I found a problem though. It doesn't recognize Test methods. see this example: (or am i using the tool wrong?)
Btw happy holidays! hope you are doing well.