//! Test case definitions
use crate::result::{CaseResult, Error};
use std::{
fmt::Debug,
path::{Path, PathBuf},
};
/// A single test case, capable of loading a JSON description of itself and running it.
///
/// See for test specs.
pub trait Case: Debug + Sync + Sized {
/// A description of the test.
fn description(&self) -> String {
"no description".to_string()
}
/// Load the test from the given file path.
///
/// The file can be assumed to be a valid EF test case as described on .
fn load(path: &Path) -> Result;
/// Run the test.
fn run(&self) -> Result<(), Error>;
}
/// A container for multiple test cases.
#[derive(Debug)]
pub struct Cases {
/// The contained test cases and the path to each test.
pub test_cases: Vec<(PathBuf, T)>,
}
impl Cases {
/// Run the contained test cases.
pub fn run(&self) -> Vec {
self.test_cases.iter().map(|(path, case)| CaseResult::new(path, case, case.run())).collect()
}
}