test_r/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
pub use test_r_macro::add_test;
pub use test_r_macro::bench;
pub use test_r_macro::inherit_test_dep;
pub use test_r_macro::sequential;
pub use test_r_macro::test;
pub use test_r_macro::test_dep;
pub use test_r_macro::test_gen;
pub use test_r_macro::uses_test_r as enable;

#[cfg(feature = "tokio")]
pub use test_r_core::bench::AsyncBencher;
pub use test_r_core::bench::Bencher;

pub mod core {
    pub use test_r_core::internal::{
        DependencyConstructor, DependencyView, DynamicTestRegistration, GeneratedTest, ShouldPanic,
        TestFunction, TestGeneratorFunction, TestType,
    };
    pub use test_r_core::*;

    pub fn register_test(
        name: &str,
        module_path: &str,
        is_ignored: bool,
        should_panic: ShouldPanic,
        test_type: TestType,
        run: TestFunction,
    ) {
        let (crate_name, module_path) = split_module_path(module_path);

        internal::REGISTERED_TESTS
            .lock()
            .unwrap()
            .push(internal::RegisteredTest {
                name: name.to_string(),
                crate_name,
                module_path,
                is_ignored,
                should_panic,
                run,
                test_type,
            });
    }

    pub fn register_dependency_constructor(
        name: &str,
        module_path: &str,
        cons: DependencyConstructor,
        dependencies: Vec<String>,
    ) {
        let (crate_name, module_path) = split_module_path(module_path);

        internal::REGISTERED_DEPENDENCY_CONSTRUCTORS
            .lock()
            .unwrap()
            .push(internal::RegisteredDependency {
                name: name.to_string(),
                crate_name,
                module_path,
                constructor: cons,
                dependencies,
            });
    }

    pub fn register_suite_sequential(name: &str, module_path: &str) {
        let (crate_name, module_path) = split_module_path(module_path);

        internal::REGISTERED_TESTSUITE_PROPS.lock().unwrap().push(
            internal::RegisteredTestSuiteProperty::Sequential {
                name: name.to_string(),
                crate_name,
                module_path,
            },
        );
    }

    pub fn register_test_generator(
        name: &str,
        module_path: &str,
        is_ignored: bool,
        run: TestGeneratorFunction,
    ) {
        let (crate_name, module_path) = split_module_path(module_path);

        internal::REGISTERED_TEST_GENERATORS.lock().unwrap().push(
            internal::RegisteredTestGenerator {
                name: name.to_string(),
                crate_name,
                module_path,
                run,
                is_ignored,
            },
        );
    }

    fn split_module_path(module_path: &str) -> (String, String) {
        let (crate_name, module_path) =
            if let Some((crate_name, module_path)) = module_path.split_once("::") {
                (crate_name.to_string(), module_path.to_string())
            } else {
                (module_path.to_string(), String::new())
            };
        (crate_name, module_path)
    }
}

pub use ::ctor;