- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有些项目包含多个 crate,这使得在每个 crate 中手动运行所有测试变得很麻烦。
有没有方便的方法递归运行 cargo test
?
最佳答案
更新:自添加此答案 1.15 发布以来,添加 cargo test --all
,会将其与自定义脚本进行比较。
此 shell 脚本在 git 存储库上对包含 Cargo.toml
文件的所有目录递归运行测试(对于其他 VCS 来说足够容易编辑)。
nocapture
以显示标准输出RUST_BACKTRACE
集运行测试,以获得更有用的输出。CARGO_BIN
环境变量来覆盖 cargo 命令脚本:
#!/bin/bash
# exit on first error, see: http://stackoverflow.com/a/185900/432509
error() {
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
if [[ -n "$message" ]] ; then
echo "Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}"
else
echo "Error on or near line ${parent_lineno}; exiting with status ${code}"
fi
exit "${code}"
}
trap 'error ${LINENO}' ERR
# done with trap
# support cargo command override
if [[ -z $CARGO_BIN ]]; then
CARGO_BIN=cargo
fi
# toplevel git repo
ROOT=$(git rev-parse --show-toplevel)
for cargo_dir in $(find "$ROOT" -name Cargo.toml -printf '%h\n'); do
echo "Running tests in: $cargo_dir"
pushd "$cargo_dir"
RUST_BACKTRACE=0 $CARGO_BIN test --no-run
RUST_BACKTRACE=1 $CARGO_BIN test -- --nocapture
popd
done
感谢@набиячлэвэли 的回答,这是一个扩展版本。
关于testing - 如何递归测试目录下的所有 crate ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41970758/
我正在将 parking_lot 添加到我的项目中,我希望我的依赖项也可以选择使用它来使用它。 例如,我知道 Tokio 有一个启用 parking_lot 的功能标志,但我想找到所有具有相似功能标志
我想使用 dijkstra来自 pathfinding crate 的函数: pub fn dijkstra( start: &N, neighbours: FN, succe
我有一个 Rust 项目,它在一个工作区中分为多个 crate 。其中一个 crate 是一个测试 crate,它包含用于其他 crate 中的单元和集成测试的实用程序。 在一个 crate 中,我定
此测试代码(playpen): use std::fmt::{Display, Formatter, Error}; struct MyLocalType; type MyResult = Resul
我不小心将我的私有(private)箱子发布到了 crates.io。我该如何删除它?我检查了 documentation但似乎没有办法删除已发布的 crate 。 最佳答案 预防 为避免将来出现这种
有什么比将所有内容都放在同一个模块中更好的方法吗? sub_module.rs pub struct GiantStruct { /* */ } impl GiantStruct { // t
我正在使用Cargo::Ops::Compile()函数使用Cargo::Ops::Compile()函数构建铁锈项目。我在一个json文件中也有一个定制目标。。如何使用目标文件将项目构建到正确目标?
使用hyper crate,我向端点发出了HTTP请求,然后尝试将响应主体传递给期望参数为Futures crate Stream的第三方库。 这导致类型错误。 Cargo.toml [depende
在示例中,hs 从 std 重新导出 HashSet。但它编译时没有错误或警告。为什么? #![no_std] pub use hs::HashSet; pub fn new() -> HashSet
在阅读官方书籍时,我偶然发现了包裹和 crate 。要创建一个新的“项目”,这就是我运行的: $ cargo new my-project Created binary (applicati
在示例中,hs 从 std 重新导出 HashSet。但它编译时没有错误或警告。为什么? #![no_std] pub use hs::HashSet; pub fn new() -> HashSet
我正在尝试编写一些调试辅助宏。所以我创建了一个 crate 来容纳所有这些,并使用 phase(plugin) 在外部引用该 crate : #[cfg(test)] #[phase(plugin)]
每次我看到这样的错误: error: associated constants are experimental (see issue #29646) ... = help: add #![featu
我对 crates.io 上托管的确切内容有点困惑(“ crate ”是指代这些内容的正确方式吗)?我的理解是 crate 是 Rust 中的一个编译单元,但是 crates 和 crates.io
我今天开始学习 Rust,但我卡在了 this step .我想在我的项目中使用 rand crate,所以我按照教程中的建议更新了我的 Cargo.toml: [package] name = "g
我有一个包含大量代码的箱子,所以我将其拆分为多个文件/模块。然而,一些模块有内部不安全的东西(例如原始指针),我需要向不同的模块公开,但我不想暴露给我的 crate 的用户。我该怎么做? 我能想到的唯
我有一个包含大量代码的箱子,所以我将其拆分为多个文件/模块。然而,一些模块有内部不安全的东西(例如原始指针),我需要向不同的模块公开,但我不想暴露给我的 crate 的用户。我该怎么做? 我能想到的唯
Rust 文档中讨论 patching 的部分解释了如何实现补丁,但它使用的所有示例都是为了“测试”和短期修复。我想做的是为我依赖的其中一个 crate 打一个补丁,它会增加它的子依赖性,然后我想在
This question already has answers here: Unable to read file contents to string - Result does not imp
我正在尝试在 Rust 中创建一个模块,然后从不同的文件中使用它。这是我的文件结构: matthias@X1:~/projects/bitter-oyster$ tree . ├── Cargo.lo
我是一名优秀的程序员,十分优秀!