bast3st_eval/evaluation/
process_cat.rs1use crate::{
2 Features, LogPfx, Messages,
3 evaluation::{
4 Context, Effects, PCategory, PMainTest, SelectableSource, WithEffects,
5 process_spec::SpecRunError, single_evaluation::EvalSignal,
6 },
7 spec::{Category, CategoryHooks},
8};
9
10impl PCategory {
11 pub async fn new<Fallback: SelectableSource + Clone + 'static>(
12 ctx: &Context,
13 log_pfx: LogPfx,
14 category: &Category,
15 fallback: Fallback,
16 ) -> Result<WithEffects<PCategory>, SpecRunError> {
17 let mut eft = Effects::default();
18 let mut p_tests = vec![];
19
20 let (before_all_tests, sig) = category
21 .hooks()
22 .before_all_tests()
23 .run_all(
24 ctx,
25 log_pfx.join("before-all-tests"),
26 &mut eft,
27 Features::PermittedFEAT_CategoryHook,
28 &fallback,
29 )
30 .await;
31 match sig {
32 Some(EvalSignal::EndTest(_)) | None => {} }
34 let mut messages: Messages<Category> = eft.take_messages();
36
37 {
38 let mut test_futures = vec![];
39 {
40 let frozen_effects = std::sync::Arc::new(eft.clone());
41 let log_pfx = log_pfx.join("test");
42 for (index, test) in category.tests().iter().enumerate() {
43 let source = (frozen_effects.clone(), fallback.clone());
44 let ctx = ctx.clone();
45 let test = test.clone();
46 let log_pfx = log_pfx.join(index);
47 test_futures.push(tokio::spawn(async move {
48 PMainTest::new(&ctx, log_pfx, &test, source).await
49 }));
50 }
51 }
52 for fut in test_futures {
53 let (test, test_effects) = fut.await??.into_parts();
54 p_tests.push(test);
55 log::trace!("[{log_pfx}] effects of finished test: {test_effects:?}");
56 eft.append(test_effects);
57 }
58 }
59 log::trace!("[{log_pfx}] category effects after test runs: {eft:?}");
60
61 let (after_all_tests, sig) = category
62 .hooks()
63 .after_all_tests()
64 .run_all(
65 ctx,
66 log_pfx.join("after-all-tests"),
67 &mut eft,
68 Features::PermittedFEAT_CategoryHook,
69 &fallback,
70 )
71 .await;
72 match sig {
73 Some(EvalSignal::EndTest(_)) | None => {} }
75 messages.extend(eft.take_messages());
76
77 Ok(WithEffects::new(
78 PCategory {
79 title: category.title().clone().into(),
80 messages,
81 tests: p_tests,
82 hooks: CategoryHooks {
83 before_all_tests,
84 after_all_tests,
85 },
86 },
87 eft,
88 ))
89 }
90}