rillig / gobco

Measure branch coverage of golang tests
62 stars 12 forks source link

use gobco cannot work #24

Closed greenpipig closed 1 year ago

greenpipig commented 2 years ago

use gobco cannot work

go-version: echo $GOROOT /go/go1.16

origin func:

func BranchCovTest(node int) {
    _ = node > 50
    _ = node == 0
    _ = node < 0

    if node == 1 {
        logs.Errorf("xypDEBUG|1")
    }
    if node == 3 {
        logs.Errorf("xypDEBUG|3")
    } else if node == 1 {
        logs.Errorf("xypDEBUG|1")
    } else {
        logs.Errorf("xypDEBUG|else")
    }
}

test func:

func TestBranchCovTest(t *testing.T) {
    BranchCovTest(1)
    BranchCovTest(10)
}

output:

ok      code.byted.org/ad/demeter-case-box/common       0.032s

Branch coverage: 0/0
rillig commented 2 years ago

This looks strange indeed.

My first idea is that the function BranchCovTest is in the test code. By default, gobco doesn't instrument any code in *_test.go.

If that's not the cause, please run gobco in verbose mode and keep the temporary files. Maybe you get some hints from there.

If that doesn't help either, please provide a self-contained runnable example so I can reproduce the problem on my own computer.

rillig commented 2 years ago

I tried to reproduce the problem you described:

$ gobco
ok      gobco-24        2.833s

Branch coverage: 8/12
main.go:6:6: condition "node > 50" was 2 times false but never true
main.go:7:6: condition "node == 0" was 2 times false but never true
main.go:8:6: condition "node < 0" was 2 times false but never true
main.go:13:5: condition "node == 3" was 2 times false but never true
rillig commented 1 year ago

Feedback timeout.