1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
use colored::Colorize;
use mingling::{
Grouped, Routable,
macros::{buffer, command, renderer},
res::ResExitCode,
};
use crate::Next;
use crate::examples::{check_example, load_test_configs};
use crate::progress::task_progress_bar;
use crate::reporter::{self, ReportResult};
#[command(node = "example-check")]
pub async fn example_check() -> Next {
reporter::set_task("Example-Check");
let configs = load_test_configs();
let total = configs.len();
let pb = task_progress_bar(total, "Testing");
pb.set_message("examples");
// One blocking task per example: build + run its test cases.
let mut handles = Vec::new();
for example in configs {
handles.push(tokio::task::spawn_blocking(move || check_example(example)));
}
let mut fail_count = 0;
for handle in handles {
let Ok(outcome) = handle.await else {
continue;
};
pb.set_message(outcome.name.clone());
pb.inc(1);
if outcome.ok {
reporter::export(&outcome.name, &outcome.location, ReportResult::Ok);
} else {
fail_count += 1;
// Plain stderr: `pb.println` is swallowed on non-TTY (CI).
eprintln!(" {} {}", "failed".bright_red(), outcome.name);
eprintln!(" {}", outcome.output);
reporter::export(
&outcome.name,
&outcome.location,
ReportResult::Error(outcome.output),
);
}
}
pb.finish_and_clear();
reporter::flush();
ResultExampleCheck { fail_count }.to_chain()
}
/// Number of examples that failed to build or pass their tests.
#[derive(Grouped)]
pub struct ResultExampleCheck {
pub fail_count: usize,
}
/// Silently sets a non-zero exit code when any example failed.
#[renderer(buffer)]
pub fn render_example_check(r: ResultExampleCheck, exit_code: &mut ResExitCode) {
if r.fail_count > 0 {
exit_code.exit_code = 1;
}
}
|