| 1 |
// Licensed under the MIT license, see LICENCE file for details. |
| 2 |
|
| 3 |
package qt |
| 4 |
|
| 5 |
import ( |
| 6 |
"fmt" |
| 7 |
) |
| 8 |
|
| 9 |
// BadCheckf returns an error used to report a problem with the checker |
| 10 |
// invocation or testing execution itself (like wrong number or type of |
| 11 |
// arguments) rather than a real Check or Assert failure. |
| 12 |
// This helper can be used when implementing checkers. |
| 13 |
func BadCheckf(format string, a ...any) error { |
| 14 |
e := badCheck(fmt.Sprintf(format, a...)) |
| 15 |
return &e |
| 16 |
} |
| 17 |
|
| 18 |
// IsBadCheck reports whether the given error has been created by BadCheckf. |
| 19 |
// This helper can be used when implementing checkers. |
| 20 |
func IsBadCheck(err error) bool { |
| 21 |
_, ok := err.(*badCheck) |
| 22 |
return ok |
| 23 |
} |
| 24 |
|
| 25 |
type badCheck string |
| 26 |
|
| 27 |
// Error implements the error interface. |
| 28 |
func (e *badCheck) Error() string { |
| 29 |
return "bad check: " + string(*e) |
| 30 |
} |
| 31 |
|
| 32 |
// ErrSilent is the error used when there is no need to include in the failure |
| 33 |
// output the "error" and "check" keys and all the keys automatically |
| 34 |
// added for args. This helper can be used when implementing checkers. |
| 35 |
var ErrSilent = fmt.Errorf("silent failure") |