in Go source code, there are many occurrences of a pattern where the code early returns after executing a function that returns a non-nil error, for example:
result, err := foo()
if err != nil {
return ...
}
these cases can sometimes be non-trivial to fully cover with unit tests because it could be challenging to make the function foo return an error. it is definitely possible to cover this case, but it would require developers to write mocks, which can sometimes take a lot of time and may not be the primary focus of development.
cases like these could be annoying for developers because they can constantly break coverage targets set by developers.
in order to aid developers in these cases, a new configuration option could be added to the go-test-coverage tool, which will omit code with this pattern from coverage statistics.
implementation details:
this option should only ignore code in if bodies where the condition is err != nil.
there could be cases where the body might have many statements inside, and this option should ignore these cases. namely, it should only ignore cases where there is an early return (one-line return statement) or cases where bodies have logging followed by a return statement.
in Go source code, there are many occurrences of a pattern where the code early returns after executing a function that returns a non-nil error, for example:
these cases can sometimes be non-trivial to fully cover with unit tests because it could be challenging to make the function
foo
return an error. it is definitely possible to cover this case, but it would require developers to write mocks, which can sometimes take a lot of time and may not be the primary focus of development.cases like these could be annoying for developers because they can constantly break coverage targets set by developers.
in order to aid developers in these cases, a new configuration option could be added to the
go-test-coverage
tool, which will omit code with this pattern from coverage statistics.implementation details:
err != nil
.return
statement) or cases where bodies have logging followed by areturn
statement.