humane/
lib.rs

1use std::env;
2
3use cucumber::{gherkin::Scenario, Cucumber, WorldInit};
4
5use civilization::Civilization;
6use options::RobotHumaneConfig;
7
8mod civilization;
9pub mod options;
10
11pub struct Humane {
12    options: RobotHumaneConfig,
13}
14
15impl Humane {
16    pub fn new(options: RobotHumaneConfig) -> Self {
17        Self { options }
18    }
19
20    pub async fn go(&mut self) {
21        let has_tag = |sc: &Scenario, tag| sc.tags.iter().any(|t| t == tag);
22
23        let r = Cucumber::new()
24            .steps(Civilization::collection())
25            .max_concurrent_scenarios(Some(4))
26            .after(|_, _, _, maybe_world| {
27                Box::pin(async move {
28                    if let Some(world) = maybe_world {
29                        world.shutdown().await;
30                    }
31                })
32            })
33            .filter_run(&self.options.test_file_root, move |_, _, sc| {
34                if has_tag(sc, "skip") {
35                    return false;
36                }
37                let is_platform_limited = sc.tags.iter().any(|t| t.starts_with("platform-"));
38                if is_platform_limited {
39                    match env::consts::OS {
40                        "linux" => has_tag(sc, "platform-linux") || has_tag(sc, "platform-unix"),
41                        "macos" => has_tag(sc, "platform-macos") || has_tag(sc, "platform-unix"),
42                        "windows" => has_tag(sc, "platform-windows"),
43                        _ => false,
44                    }
45                } else {
46                    true
47                }
48            })
49            .await;
50        if r.parsing_errors > 0
51            || r.failed_hooks > 0
52            || r.scenarios.failed > 0
53            || r.steps.failed > 0
54        {
55            std::process::exit(1);
56        }
57    }
58}