litcheck_lit/test/registry/
mod.rs

1mod default;
2
3pub use self::default::DefaultTestRegistry;
4
5use std::{path::Path, sync::Arc};
6
7use litcheck::diagnostics::DiagResult;
8
9use crate::{
10    suite::TestSuite,
11    test::{Test, TestConfig, TestList},
12};
13
14pub trait TestRegistry {
15    /// Get the all tests belonging to `suite`, based on its provided configuration
16    fn all(&self, suite: Arc<TestSuite>) -> DiagResult<TestList>;
17
18    /// Search for tests belonging to `suite` which are located under `path_in_suite`,
19    /// a file/directory path which must be located within `suite`.
20    ///
21    /// The search takes into account the current configuration to ensure that only those
22    /// tests that should be discoverable are found.
23    ///
24    /// The default implementation of this function generates a single test from the given
25    /// path, under the assumption that it is already valid. It is up to the test format to
26    /// either override the default implementation, or raise an error if the test is invalid
27    /// under these assumptions.
28    fn find(
29        &self,
30        path_in_suite: &Path,
31        suite: Arc<TestSuite>,
32        config: Arc<TestConfig>,
33    ) -> DiagResult<TestList> {
34        let mut tests = TestList::default();
35
36        tests.push_back(Arc::new(Test::new(
37            path_in_suite.to_path_buf(),
38            suite,
39            config,
40        )));
41
42        Ok(tests)
43    }
44}
45impl<T: TestRegistry> TestRegistry for &T {
46    #[inline]
47    fn all(&self, suite: Arc<TestSuite>) -> DiagResult<TestList> {
48        (**self).all(suite)
49    }
50    #[inline]
51    fn find(
52        &self,
53        path_in_suite: &Path,
54        suite: Arc<TestSuite>,
55        config: Arc<TestConfig>,
56    ) -> DiagResult<TestList> {
57        (**self).find(path_in_suite, suite, config)
58    }
59}