testing.shouldErrorWithCode() 函数
testing.shouldErrorWithCode() 调用一个捕捉任何错误并检查错误是否与预期值匹配的函数。
函数类型签名
(code: uint, fn: () => A, want: regexp) => stream[{match: bool, code: uint, _diff: string}]
有关更多信息,请参见 Function type signatures。
参数
函数
(必填) 调用的函数。
想要
(必填) 用于匹配预期错误的正则表达式。
代码
(必填) 期望的流量错误代码
示例
测试死亡函数错误
import "testing"
testing.shouldErrorWithCode(fn: () => die(msg: "error message"), want: /error message/, code: 3)