ide*_*n42 13 testing rust rust-cargo
有些项目包括多个包,这使得在每个包中手动运行所有测试变得麻烦.
是否有一种方便的递归运行方式cargo test?
更新:自添加此答案1.15发布后,添加cargo test --all,将与自定义脚本进行比较.
这个shell脚本在包含Cargo.toml文件的所有目录的git存储库上递归运行测试(很容易编辑其他VCS).
nocapture如此标准显示RUST_BACKTRACEset 运行测试,以获得更有用的输出.CARGO_BIN环境变量,用于覆盖货物命令脚本:
#!/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
Run Code Online (Sandbox Code Playgroud)
感谢@набиячлэвэли的回答,这是一个扩展版本.
您可以使用shell脚本.根据这个答案,这个
find . -name Cargo.toml -printf '%h\n'
Run Code Online (Sandbox Code Playgroud)
将打印出包含的目录Cargo.toml,因此,将其与标准shell utils的其余部分组合在一起产生我们
for f in $(find . -name Cargo.toml -printf '%h\n' | sort -u); do
pushd $f > /dev/null;
cargo test;
popd > /dev/null;
done
Run Code Online (Sandbox Code Playgroud)
这将迭代所有包含Cargo.toml(对于板条箱的好赌注)的目录并cargo test在其中运行.
| 归档时间: |
|
| 查看次数: |
424 次 |
| 最近记录: |