asmov_common_testing/
testing.rs

1use std::{fmt::Display, path::Path};
2use crate::*;
3
4/// Common to all testing models: [TestModule], [TestGroup], and [Test].
5pub trait Testing {
6    /// The testing use-case
7    fn use_case(&self)-> UseCase;
8
9    /// The namepath
10    fn namepath(&self) -> &Namepath;
11
12    /// The canonical fixture directory, if configured to use one.
13    /// By default, this is based on the use-case and namepath
14    fn fixture_dir(&self) -> &Path;
15
16    /// The canonical temporary directory, if configured to use one.
17    /// By default, this is based on the use-case and namepath.
18    /// The directory is created on construction and deleted upon destruction.
19    fn temp_dir(&self) -> &Path;
20}
21
22/// The type of testing being performed
23#[derive(Debug, Copy, Clone, PartialEq, Eq)]
24pub enum UseCase {
25    /// Unit tests
26    Unit,
27    /// Integration tests
28    Integration,
29}
30
31impl Display for UseCase {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        match self {
34            UseCase::Unit => write!(f, "unit"),
35            UseCase::Integration => write!(f, "integration"),
36        }
37    }
38}
39
40/// The type of testing model
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42pub enum TestingKind {
43    /// [TestModule]
44    Module,
45    /// [TestGroup]
46    Group,
47    /// [Test]
48    Test
49}
50
51impl Display for TestingKind {
52    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53        match self {
54            TestingKind::Module => write!(f, "module"),
55            TestingKind::Group => write!(f, "group"),
56            TestingKind::Test => write!(f, "test"),
57        }
58    }
59}