diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-18 10:36:53 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-18 10:36:53 +0800 |
| commit | b5941040586c3707620bbef6cf8ace4e565f7693 (patch) | |
| tree | b09ff500bb187328941372b1a79381afb0123e4f /mingling_ci/src/markdown/test.rs | |
| parent | 721536eae99d468299c6d7f5ecd6b7dbeac4c34a (diff) | |
feat(ci-new): report per-file results
Add per-file report generation for markdown checks using the
reporter module, grouping outcomes by source file and exporting
ok or error results with snake_case item names.
Diffstat (limited to 'mingling_ci/src/markdown/test.rs')
| -rw-r--r-- | mingling_ci/src/markdown/test.rs | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/mingling_ci/src/markdown/test.rs b/mingling_ci/src/markdown/test.rs index c010e8c..f8bd1f7 100644 --- a/mingling_ci/src/markdown/test.rs +++ b/mingling_ci/src/markdown/test.rs @@ -13,12 +13,23 @@ use super::project::{ /// Temporary root for the generated test crates. const TEMP_BASE: &str = ".temp/doc-test"; +/// Outcome of testing one code block. +pub(crate) struct MarkdownBlockOutcome { + pub source_file: String, + pub line: usize, + pub ok: bool, + /// Failure detail; empty when `ok`. + pub output: String, +} + /// Runs the given projects in parallel. /// /// Projects sharing a dependency hash share one temporary crate (written /// serially within the group); groups run in parallel. Progress is shown on -/// stderr; failures print immediately. Returns the number of failed blocks. -pub(crate) async fn try_test_markdown_project(projs: Vec<MarkdownTestProject>) -> usize { +/// stderr; failures print there too. Returns one outcome per block. +pub(crate) async fn try_test_markdown_project( + projs: Vec<MarkdownTestProject>, +) -> Vec<MarkdownBlockOutcome> { // Group by dependency hash for crate sharing. let mut groups: BTreeMap<String, Vec<MarkdownTestProject>> = BTreeMap::new(); for proj in projs { @@ -49,7 +60,7 @@ pub(crate) async fn try_test_markdown_project(projs: Vec<MarkdownTestProject>) - let manifest_path = crate_dir.join("Cargo.toml"); let cargo_toml = generate_cargo_toml(&blocks[0], &manifest_path); - let mut failed = 0; + let mut group_outcomes = Vec::new(); for proj in &blocks { let label = format!("{}:{}", proj.source_file, proj.line); pb.set_message(label.clone()); @@ -69,25 +80,30 @@ pub(crate) async fn try_test_markdown_project(projs: Vec<MarkdownTestProject>) - pb.inc(1); if !ok { - failed += 1; // Plain stderr: `pb.println` is swallowed on non-TTY (CI). eprintln!(" {} {label}", "failed".bold().bright_red()); eprintln!(" {label} FAILED:\n{err}"); } + group_outcomes.push(MarkdownBlockOutcome { + source_file: proj.source_file.clone(), + line: proj.line, + ok, + output: err, + }); } - failed + group_outcomes })); } - let mut fail_count = 0; + let mut all_outcomes = Vec::new(); for handle in handles { - if let Ok(failed) = handle.await { - fail_count += failed; + if let Ok(group_outcomes) = handle.await { + all_outcomes.extend(group_outcomes); } } pb.finish_and_clear(); - fail_count + all_outcomes } /// Writes the temporary crate files and runs `cargo check`. |
