|
1 | 1 | use std::future::Future;
|
2 | 2 | use std::path::Path;
|
| 3 | +use std::time::{Duration, Instant}; |
3 | 4 |
|
4 | 5 | use anyhow::{anyhow, Context, Error, Result};
|
5 | 6 | use console::style;
|
@@ -29,11 +30,17 @@ where
|
29 | 30 | Ok::<_, Error>((path, testname))
|
30 | 31 | })
|
31 | 32 | .collect::<Result<Vec<_>, _>>()?;
|
| 33 | + |
| 34 | + struct TestResult { |
| 35 | + testname: String, |
| 36 | + time: Duration, |
| 37 | + } |
32 | 38 | let test_stream = stream::iter(tests).map(|(path, testname)| {
|
33 | 39 | let runner_fn = &runner_fn;
|
34 | 40 | let testname_x = testname.clone();
|
35 | 41 | async {
|
36 | 42 | let mut runner = runner_fn().await?;
|
| 43 | + let start = Instant::now(); |
37 | 44 | tokio::spawn(async move {
|
38 | 45 | let testcases = tokio::fs::read(&path).await?;
|
39 | 46 | let testcases: Vec<TestCase> = serde_yaml::from_slice(&testcases)?;
|
|
53 | 60 | Ok::<_, Error>(())
|
54 | 61 | })
|
55 | 62 | .await??;
|
56 |
| - Ok::<_, Error>(testname) |
| 63 | + let time = start.elapsed(); |
| 64 | + Ok::<_, Error>(TestResult { testname, time }) |
57 | 65 | }
|
58 | 66 | .map_err(|e| (e, testname_x))
|
59 | 67 | });
|
|
65 | 73 | let mut failed_cases = vec![];
|
66 | 74 | while let Some(item) = test_stream.next().await {
|
67 | 75 | match item {
|
68 |
| - Ok(name) => println!("{} {}", style("[DONE]").green().bold(), name), |
| 76 | + Ok(item) => println!( |
| 77 | + "{} {}, took {} ms", |
| 78 | + style("[DONE]").green().bold(), |
| 79 | + item.testname, |
| 80 | + item.time.as_millis() |
| 81 | + ), |
69 | 82 | Err((e, name)) => {
|
70 | 83 | println!("{} {}: {:#}", style("[FAIL]").red().bold(), name, e);
|
71 | 84 | failed_cases.push(name);
|
|
0 commit comments