conformer/
lib.rs

1//! A simple framework for authoring conformance test suites.
2
3#![deny(missing_docs)]
4
5pub use self::test_case_results::*;
6pub use self::test_suite::*;
7pub use self::visualizer::*;
8
9mod test_case_results;
10mod test_suite;
11mod visualizer;
12
13/// Run a test suite.
14pub fn run_test_suite<TypeToTest, TypeToTestCreator>(
15    type_to_test_creator: TypeToTestCreator,
16    suite: TestSuite<TypeToTest>,
17) -> TestCaseResults
18where
19    TypeToTestCreator: Fn(&Box<dyn TestCase<TypeToTest>>) -> TypeToTest,
20{
21    let mut results = Vec::with_capacity(suite.test_cases.len());
22
23    for test_case in suite.test_cases {
24        let type_to_test = type_to_test_creator(&test_case);
25
26        let test_case_result = test_case.run(type_to_test);
27        results.push(test_case_result);
28    }
29
30    TestCaseResults::new(suite.title, suite.description, results)
31}
32
33/// Used to indicate a type that can be used to create test cases to test some aspect of a
34/// Renderer.
35pub trait TestCase<TypeToTest> {
36    /// Ok if the test case was successful, otherwise an error message is returned.
37    fn run(self: Box<Self>, type_to_test: TypeToTest) -> TestCaseResult;
38
39    /// Useful for downcasting.
40    ///
41    /// ```
42    /// # struct Foo;
43    /// # impl Foo {
44    /// fn as_any(&self) -> &dyn std::any::Any {
45    ///     self
46    /// }
47    /// #}
48    /// ```
49    fn as_any(&self) -> &dyn std::any::Any;
50}