运行 rust 单元测试时,使用属性宏 #[should_panic(expect = )] 来断言测试因正确的错误消息而发生恐慌(这意味着它在您希望它发生恐慌的行处发生恐慌,而不是因为不同的错误。
但是,在使用在errors.rs 文件中定义的标准化错误消息的应用程序中,不可能将错误消息的常量作为expect 的参数传递。
这:
pub const ERR_001: &str = "ERR_001 message";
#[test]
#[should_panic(expected = ERR_001)]
fn test_function() {
//test code here
}
Run Code Online (Sandbox Code Playgroud)
产生以下错误:
error: expected unsuffixed literal or identifier, found `ERR_001`
--> staking/src/storage.rs:74:31
|
74 | #[should_panic(expected = ERR_001)]
|
Run Code Online (Sandbox Code Playgroud)
有没有办法将常量或变量传递给 #[should_panic(expected = )] 宏?或者是否有必要总是写消息而不是?
我在 Linux 2 (WSL2) 的 Windows 子系统中的 Ubuntu 20.04 中使用 npm 版本 8.1.2。
我一直在尝试为我的项目安装 5 个依赖项,但安装挂起。
npm install solc web3 mocha ganache-cli @truffle/hdwallet-provider --verbose
Run Code Online (Sandbox Code Playgroud)
然而,安装过程非常耗时(超过 10 个小时)。
我已经检查了以下内容:
npm config set registry http://registry.npmjs.org/
Run Code Online (Sandbox Code Playgroud)
以前有人遇到过这个问题吗?解决方案是什么?
附言。stackoverflow 中确实有很多关于 npm install 速度的主题,但是,我已经阅读了很多,这导致我测试了前面提到的 4 个主题。