// example: open a file should exist(local config file),// if it not exists, then it's code error or CI/CD error, not runtime error.funcTestVerify(t *testing.T){
file :=VerifyWithResult(os.Open("should_exist_conf_file"))deferfunc(){//Notice: when try to close a nil(*os.File), error with "invalid argument"_=Verify(file.Close())}()//file.Read(xxxx)}
运行效果(可以看到代码中没有写日志的代码,但是程序发生问题时,能快速定位)
2024/01/29 21:31:54 [WARN] /path/to/go-library/debugutil/verify_test.go:13 (TestVerify) FAIL(*fs.PathError), msg=open should_exist_conf_file: The system cannot find the file specified.
2024/01/29 21:31:54 [WARN] /path/to/go-library/debugutil/verify_test.go:17 (func1) FAIL(*errors.errorString), msg=invalid argument