1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-30 08:57:07 +02:00
revive/fixtures/golint/errorf.go
2018-02-04 15:02:45 -08:00

41 lines
832 B
Go

// Test for not using fmt.Errorf or testing.Errorf.
// Package foo ...
package foo
import (
"errors"
"fmt"
"testing"
)
func f(x int) error {
if x > 10 {
return errors.New(fmt.Sprintf("something %d", x)) // MATCH /should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)/ -> return fmt.Errorf("something %d", x)`
}
if x > 5 {
return errors.New(g("blah")) // ok
}
if x > 4 {
return errors.New("something else") // ok
}
return nil
}
// TestF is a dummy test
func TestF(t *testing.T) error {
x := 1
if x > 10 {
return t.Error(fmt.Sprintf("something %d", x)) // MATCH /should replace t.Error(fmt.Sprintf(...)) with t.Errorf(...)/
}
if x > 5 {
return t.Error(g("blah")) // ok
}
if x > 4 {
return t.Error("something else") // ok
}
return nil
}
func g(s string) string { return "prefix: " + s }