在 Debian 上跑 Rust 测试,基本步骤和在其他 Linux 发行版上一样,前提是已经装好了 Rust 工具链。
推荐用官方方式安装(Debian 仓库里的版本通常偏旧):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
验证:
rustc --version
cargo --version
在 Rust 项目目录下:
cargo test
这会:
cargo test
cargo test test_name
cargo test module_name::
cargo test -- --nocapture
cargo test -- --test-threads=1
src/lib.rs 或 src/main.rs 中:
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
然后:
cargo test
放在 tests/ 目录:
tests/integration.rs
use my_crate::add;
#[test]
fn test_add() {
assert_eq!(add(1, 2), 3);
}
运行方式一样:
cargo test
sudo apt install build-essential
sudo apt install pkg-config libssl-dev
如果你是指 Debian 上跑 Rust 的 Debian 包测试、CI 环境测试,或者是 交叉编译测试,可以告诉我具体场景,我可以进一步说明。