package cluster
import "fmt"
func A() error {
return fmt.Errorf("a", 1) // 这行代码应该报错
}
package cluster
import (
"testing"
)
func TestT(t *testing.T) {
A()
}
运行 TestT 函数会报错,fmt.Errorf call has arguments but no formatting directives 。
package clusterrolebinding
import (
"xx/pkg/controller/cluster"
"testing"
)
func TestT(t *testing.T) {
cluster.A()
}
但是在另外一个包里面运行 TestT 函数就不报错了,正常运行。
![]() |
1
kkhaike 100 天前
golang 编译器在构建 test 会检查 fmt 参数,还包括你的 fmt 里的格式化符对不对,但是普通构建没有这个功能,我也觉得这个功能挺好的。。。现在只能靠 golang-lint
|
![]() |
2
kk2syc 100 天前
因为你用 fmt.Errorf 但是没有格式说明符(%v\%s\%d 等),包内检查,包外不检查
|