libtest2_harness/
context.rs1pub(crate) use crate::*;
2
3pub struct TestContext {
4 pub(crate) start: std::time::Instant,
5 pub(crate) mode: RunMode,
6 pub(crate) run_ignored: bool,
7 pub(crate) notifier: notify::ArcNotifier,
8 pub(crate) test_name: String,
9}
10
11impl TestContext {
12 pub fn ignore(&self) -> Result<(), RunError> {
13 if self.run_ignored {
14 Ok(())
15 } else {
16 Err(RunError::ignore())
17 }
18 }
19
20 pub fn ignore_for(&self, reason: impl std::fmt::Display) -> Result<(), RunError> {
21 if self.run_ignored {
22 Ok(())
23 } else {
24 Err(RunError::ignore_for(reason.to_string()))
25 }
26 }
27
28 pub fn current_mode(&self) -> RunMode {
29 self.mode
30 }
31
32 pub fn notify(&self, event: notify::Event) -> std::io::Result<()> {
33 self.notifier().notify(event)
34 }
35
36 pub fn elapased_s(&self) -> notify::Elapsed {
37 notify::Elapsed(self.start.elapsed())
38 }
39
40 pub fn test_name(&self) -> &str {
41 &self.test_name
42 }
43
44 pub(crate) fn notifier(&self) -> ¬ify::ArcNotifier {
45 &self.notifier
46 }
47
48 pub(crate) fn clone(&self) -> Self {
49 Self {
50 start: self.start,
51 mode: self.mode,
52 run_ignored: self.run_ignored,
53 notifier: self.notifier.clone(),
54 test_name: self.test_name.clone(),
55 }
56 }
57}