litcheck_lit/test/
mod.rs

1mod config;
2mod list;
3mod registry;
4mod result;
5mod status;
6
7pub use self::config::{TestConfig, TestConfigError};
8pub use self::list::TestList;
9pub use self::registry::{DefaultTestRegistry, TestRegistry};
10pub use self::result::TestResult;
11pub use self::status::TestStatus;
12
13use std::{
14    path::{Path, PathBuf},
15    sync::Arc,
16    time::Duration,
17};
18
19use crate::suite::TestSuite;
20
21/// [Test] represents information about a single test instance
22pub struct Test {
23    link: intrusive_collections::LinkedListAtomicLink,
24    /// The test suite which this test belongs to
25    pub suite: Arc<TestSuite>,
26    /// The test configuration which applies to this test
27    pub config: Arc<TestConfig>,
28    /// The full name of this test
29    pub name: Arc<str>,
30    /// The path relative to `suite_path`
31    pub path: PathBuf,
32    /// The absolute path to this test
33    pub absolute_path: PathBuf,
34    /// If true, ignore `xfails`
35    pub xfail_not: bool,
36    /// The previous test failure state, if applicable.
37    pub previous_failure: Option<TestResult>,
38    /// The previous test elapsed time, if applicable.
39    pub previous_elapsed: Option<Duration>,
40}
41impl Test {
42    pub fn new(path_in_suite: PathBuf, suite: Arc<TestSuite>, config: Arc<TestConfig>) -> Self {
43        let absolute_path = suite.source_dir.get_ref().join(&path_in_suite);
44        let name =
45            Arc::from(format!("{}::{}", suite.name(), path_in_suite.display()).into_boxed_str());
46        Self {
47            link: Default::default(),
48            suite,
49            config,
50            name,
51            path: path_in_suite,
52            absolute_path,
53            xfail_not: false,
54            previous_failure: None,
55            previous_elapsed: None,
56        }
57    }
58
59    pub fn name(&self) -> &str {
60        self.name.as_ref()
61    }
62
63    pub fn source_path(&self) -> &Path {
64        self.absolute_path.as_path()
65    }
66}