-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcase.rs
More file actions
88 lines (79 loc) · 2.47 KB
/
case.rs
File metadata and controls
88 lines (79 loc) · 2.47 KB
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
pub(crate) use crate::*;
pub trait Case: Send + Sync + 'static {
/// The name of a test
///
/// By convention this follows the rules for rust paths; i.e., it should be a series of
/// identifiers separated by double colons. This way if some test runner wants to arrange the
/// tests hierarchically it may.
fn name(&self) -> &str;
fn kind(&self) -> TestKind;
fn source(&self) -> Option<&Source>;
/// This case cannot run in parallel to other cases within this binary
fn exclusive(&self, state: &TestContext) -> bool;
fn run(&self, state: &TestContext) -> Result<(), RunError>;
}
impl Case for Box<dyn Case> {
fn name(&self) -> &str {
self.as_ref().name()
}
fn kind(&self) -> TestKind {
self.as_ref().kind()
}
fn source(&self) -> Option<&Source> {
self.as_ref().source()
}
fn exclusive(&self, state: &TestContext) -> bool {
self.as_ref().exclusive(state)
}
fn run(&self, state: &TestContext) -> Result<(), RunError> {
self.as_ref().run(state)
}
}
impl Case for std::sync::Arc<dyn Case> {
fn name(&self) -> &str {
self.as_ref().name()
}
fn kind(&self) -> TestKind {
self.as_ref().kind()
}
fn source(&self) -> Option<&Source> {
self.as_ref().source()
}
fn exclusive(&self, state: &TestContext) -> bool {
self.as_ref().exclusive(state)
}
fn run(&self, state: &TestContext) -> Result<(), RunError> {
self.as_ref().run(state)
}
}
/// Type of the test according to the [rust book](https://doc.rust-lang.org/cargo/guide/tests.html)
/// conventions.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum TestKind {
/// Unit-tests are expected to be in the `src` folder of the crate.
UnitTest,
/// Integration-style tests are expected to be in the `tests` folder of the crate.
IntegrationTest,
/// Doctests are created by the `librustdoc` manually, so it's a different type of test.
DocTest,
/// Tests for the sources that don't follow the project layout convention
/// (e.g. tests in raw `main.rs` compiled by calling `rustc --test` directly).
Unknown,
}
impl Default for TestKind {
fn default() -> Self {
Self::Unknown
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum Source {
Rust {
source_file: std::path::PathBuf,
start_line: usize,
start_col: usize,
end_line: usize,
end_col: usize,
},
Path(std::path::PathBuf),
}