english русский
Coverage reports can return a lot of false positives, e.g. in most cases you don't need to cover Error() string
implemenation, cause 99.9% it's just a fmt.Sprintf
caller and that's it.
Covercut cuts your cover profiles, and adding ignoring feature, when you getting cover reports. Let's see it in action:
package main
func DoSomething() error { // this part we strictly need to test! ⚠️
if answer == 42 {
return doX()
}
if err := doDangerous(); err == nil {
return nil
}
// if go test won't catch this line, your Error() func won't be covered 😱
return ErrWorldIsInFire{Wrapped: err}
}
type ErrWorldIsInFire struct {
Wrapped error
}
func (e ErrWorldIsInFire) Error() string { // But this one? Who cares? 🔥
return "Oh jeez! We will die! Here is the error: " + e.Wrapped.error()
}
This tool helps you filter coverage outputs, and ignore functions you don't need to test!
type ErrWorldIsInFire struct {
Wrapped error
}
// ↓ this comment helps you to
// ↓ filter coverage false positive!
func (e ErrWorldIsInFire) Error() string { //cover:ignore
return "Oh jeez! We will die! Here is the error: " + e.Wrapped.error()
}
Here are some usage cases, how you can do some stuff:
type ErrCustom struct{}
func (e ErrCustom) Error() string { //cover:ignore
return "Oops! Some error here!"
}
🔘 $ brew install covercut
Processing... Done!
🟢 $ go test -coverprofile=cover.out
# first argument is a path to your module,
# so covercut will understand where to find comments
🟢 $ `covercut ./path/to/source/code ./cover.out > cover_filtered.out`
🟢 $ # Tadah! Now you can analyze your cover profile without false positives!
Please read contributing guide if you want to help. And the help is very necessary!
Don't want code? Read this page! We love nocoders!
Please, don't create issue which describes security bug, this can be too offensive! Instead, please read this notification and follow that steps to notify us about problem.
- Publich to homebrew
This project uses go-task, it's not important to understand, what's
going on, (since you can just see into Taskfile.yaml
and see all commands).
For better experience, you can download go-task and run tasks e.g. via
$ task <taskname>
. All tasks can be shown via $ task --list-all
- Richard Cooper <rcooper.xelaj@protonmail.com>
This project is licensed under the MIT License - see the LICENSE file for details
Если вы находитесь в россии, или как-либо связаны с российским правительством, (например, являетесь российским налогоплательщиком) на вас распостраняется отдельная лицензия.
Even that maintainers of this project are generally from russia, we still stand up with Ukraine, and from beginning of war, decided to stop paying any taxes, or cooperate in any case with government, and companies, connected with government. This is absolutely nothing compared to how much pain putin brought to the fraternal country. And we are responsible for our inaction, and the only thing we can do is to take at least any actions that harm putin’s regime, and help the victims of regime using all resources available for us.
Created with love 💜 and magic 🦄
Xelaj Software, 2022