provola_testrunners/
lib.rs

1use provola_core::test_runners::TestRunner;
2use provola_core::{Error, Executable};
3use strum_macros::{Display, EnumString};
4
5fn from_exec<T>(info: TestRunnerInfo) -> Result<Box<dyn TestRunner>, Error>
6where
7    T: From<Executable> + provola_core::test_runners::TestRunner + 'static,
8{
9    Ok(Box::new(T::from(info.exec)))
10}
11
12pub fn make_test_runner(info: TestRunnerInfo) -> Result<Box<dyn TestRunner>, Error> {
13    let test_runner_type = info.trt;
14    match test_runner_type {
15        #[cfg(feature = "googletest")]
16        TestRunnerType::GoogleTest => from_exec::<provola_googletest::TestRunner>(info),
17        #[cfg(feature = "catch2")]
18        TestRunnerType::Catch2 => from_exec::<provola_catch2::TestRunner>(info),
19    }
20}
21
22#[derive(
23    Debug, EnumString, Clone, Copy, Display, serde::Deserialize, serde::Serialize, PartialEq, Eq,
24)]
25pub enum TestRunnerType {
26    #[cfg(feature = "googletest")]
27    GoogleTest,
28    #[cfg(feature = "catch2")]
29    Catch2,
30}
31
32#[derive(serde::Deserialize, serde::Serialize, Clone, Debug, PartialEq, Eq)]
33pub struct TestRunnerInfo {
34    pub exec: Executable,
35    pub trt: TestRunnerType,
36}
37
38impl TestRunnerInfo {
39    pub fn new(exec: Executable, trt: TestRunnerType) -> Self {
40        Self { exec, trt }
41    }
42}