courtney icon indicating copy to clipboard operation
courtney copied to clipboard

"notest" comment does not work in my setup

Open lixvbnet opened this issue 3 years ago • 1 comments

Hi, it's great to find this tool. But after trying for hours, I'm still having trouble to have it work.

pac.go: (you can see I have tried adding "notest" everywhere..

package newpac

import "fmt"

func max(a, b int) int {
	if a > b {
		// notest
		fmt.Println("gt") // notest
		return a          // notest
	} else {
		fmt.Println("lt")
		return b
	}
}

pac_test.go

package newpac

import (
	"fmt"
	"testing"
)

func Test1(t *testing.T) {
	res := max(3, 5)
	fmt.Println(res)
}

Run command:

go install github.com/dave/courtney@latest
go install github.com/axw/gocov/gocov@latest
go install github.com/AlekSi/gocov-xml@latest
go install github.com/matm/gocov-html@latest

courtney -v -o c.out && gocov convert c.out | gocov-html > C.html 

But still getting same report as before, image

My Go version is 1.17, and I have downgraded to 1.16 but still got same result. Am I missing anything?

lixvbnet avatar Oct 24 '22 08:10 lixvbnet

I did further testing. This might have to do with the way gocov convert handles the c.out file.

(1) Run go test -v -coverprofile=c.out c.out

mode: set
tttmod/newpac/pac.go:5.24,6.11 1 1
tttmod/newpac/pac.go:6.11,10.3 2 0
tttmod/newpac/pac.go:10.8,13.3 2 1

(2) Run courtney -v -o c.out
c.out

mode: set
tttmod/newpac/pac.go:5.24,6.11 1 1
tttmod/newpac/pac.go:10.8,13.3 2 1

For both (1) and (2), gocov convert c.out | gocov-html > C.html would produce same report (60% coverage)

But if add the excluded lines to c.out and set last bit to 1, then coverage score becomes 100%.

mode: set
tttmod/newpac/pac.go:5.24,6.11 1 1
tttmod/newpac/pac.go:6.11,10.3 2 1
tttmod/newpac/pac.go:10.8,13.3 2 1

I have an existing setup which uses gocov-xml to integrate with Jenkins, and gocov-html for handy coverage report, but with no way to exclude code blocks for coverage report. So I really wish to have courtney and gocov tools work together!

Then my issue becomes: Is there any way or workaround to have courtney include the missing lines in the output file, with last bit set to 1 ? Thanks in advance

lixvbnet avatar Oct 24 '22 09:10 lixvbnet