anya_core/testing/
sectional_test_utils.rs1use std::collections::HashMap;
5
6#[derive(Debug, Clone)]
8pub struct TestSection {
9 pub name: String,
10 pub enabled: bool,
11 pub timeout_seconds: u64,
12 pub dependencies: Vec<String>,
13}
14
15impl Default for TestSection {
16 fn default() -> Self {
17 Self {
18 name: "default".to_string(),
19 enabled: true,
20 timeout_seconds: 300, dependencies: Vec::new(),
22 }
23 }
24}
25
26pub struct SectionRunner {
28 sections: HashMap<String, TestSection>,
29}
30
31impl SectionRunner {
32 pub fn new() -> Self {
33 Self {
34 sections: HashMap::new(),
35 }
36 }
37
38 pub fn add_section(&mut self, section: TestSection) {
39 self.sections.insert(section.name.clone(), section);
40 }
41
42 pub fn enable_section(&mut self, name: &str) {
43 if let Some(section) = self.sections.get_mut(name) {
44 section.enabled = true;
45 }
46 }
47
48 pub fn disable_section(&mut self, name: &str) {
49 if let Some(section) = self.sections.get_mut(name) {
50 section.enabled = false;
51 }
52 }
53
54 pub fn run_section(&self, name: &str) -> Result<(), String> {
55 if let Some(section) = self.sections.get(name) {
56 if !section.enabled {
57 return Err(format!("Section '{name}' is disabled"));
58 }
59
60 for dep in §ion.dependencies {
62 if !self.sections.contains_key(dep) {
63 return Err(format!("Missing dependency '{dep}' for section '{name}'"));
64 }
65 }
66
67 println!("Running test section: {}", section.name);
68 Ok(())
70 } else {
71 Err(format!("Section '{name}' not found"))
72 }
73 }
74
75 pub fn list_sections(&self) -> Vec<&str> {
76 self.sections.keys().map(|s| s.as_str()).collect()
77 }
78}
79
80impl Default for SectionRunner {
81 fn default() -> Self {
82 Self::new()
83 }
84}