Closed vfaronov closed 11 months ago
That's a tricky situation, and you need to read the message very carefully.
toy.go:9:7: condition "rand.Intn(2) == 1" was once true but never false
The "once true" refers to TestFoo_one. The "never false" says that the cases rand.Intn(2) == 0
and rand.Intn(2) == 1
are covered, but other values for rand.Intn(2)
were never seen. This is not surprising since rand.Intn(2)
is guaranteed to only ever return 0 or 1, never a higher number.
In other words, gobco is trying to tell you that you don't need the case 1
and could simply replace it with default:
.
If you have an idea how to improve gobco's message to make it easier to understand, please tell me. Otherwise you can just close the issue since gobco is correct here.
Ah, right, thank you.
If you have an idea how to improve gobco's message to make it easier to understand, please tell me.
This would help:
toy.go:6:2: "switch rand.Intn(2)" never took the implicit default branch
I thought about the improved diagnostic again, and I'm not going to implement it.
Given the following
toy.go
:and the following
toy_test.go
:gobco reports:
although both cases are actually covered.