diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-18 10:01:53 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-18 10:01:53 +0800 |
| commit | 570b2bc1710c0ab8a68ad69a6121144e4f5e3aca (patch) | |
| tree | 76995f8437ea0175724a1669a8f821736a20de60 /mingling_ci/src/task/cmd_test.rs | |
| parent | a7adc172b3cc58e0555b1cddb45d6301c733be81 (diff) | |
feat(ci-new): add test-all task with per-crate config support
Add a new `test-all` command that runs tests across all crates with
optional per-crate command overrides via `mingling-ci.toml` files.
Diffstat (limited to 'mingling_ci/src/task/cmd_test.rs')
| -rw-r--r-- | mingling_ci/src/task/cmd_test.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/mingling_ci/src/task/cmd_test.rs b/mingling_ci/src/task/cmd_test.rs new file mode 100644 index 0000000..3ed193c --- /dev/null +++ b/mingling_ci/src/task/cmd_test.rs @@ -0,0 +1,54 @@ +use std::ffi::OsString; +use std::path::Path; + +use mingling::{ + Grouped, Routable, + macros::{buffer, command, renderer}, + res::ResExitCode, +}; + +use crate::Next; +use crate::res::{Manifests, ResCrateConfig}; +use crate::task::run::run_parallel_checks; + +#[command(node = "test-all")] +pub async fn test_all(manifests: &Manifests, config: &ResCrateConfig) -> Next { + let tasks = manifests + .package_dirs + .iter() + .map(|(name, path)| { + let args = config.test_command(name).map_or_else( + || test_args(path), + |cmd| cmd.iter().map(|s| OsString::from(s.as_str())).collect(), + ); + (name.clone(), args) + }) + .collect(); + let fail_count = run_parallel_checks("Test-All", "Testing", tasks).await; + ResultTestAll { fail_count }.to_chain() +} + +/// Default: `cargo test --manifest-path <path>` (crates without a +/// `mingling-ci.toml` override). +fn test_args(path: &Path) -> Vec<OsString> { + vec![ + "cargo".into(), + "test".into(), + "--manifest-path".into(), + path.as_os_str().to_os_string(), + ] +} + +/// Number of packages that failed tests. +#[derive(Grouped)] +pub struct ResultTestAll { + pub fail_count: usize, +} + +/// Silently sets a non-zero exit code when any test failed. +#[renderer(buffer)] +pub fn render_test_all(r: ResultTestAll, exit_code: &mut ResExitCode) { + if r.fail_count > 0 { + exit_code.exit_code = 1; + } +} |
