bitbelay_report/section/test.rs
1//! A section describing a test result.
2
3use nonempty::NonEmpty;
4
5mod builder;
6pub mod module;
7
8pub use builder::Builder;
9pub use module::Module;
10
11/// A section of a [`Report`](crate::Report) describing a test that was
12/// conducted.
13#[derive(Clone, Debug, Eq, PartialEq)]
14pub struct Test {
15 /// The test title.
16 title: String,
17
18 /// The test description.
19 description: String,
20
21 /// The modules of the test.
22 modules: NonEmpty<Module>,
23}
24
25impl Test {
26 /// Gets the title from the [`Test`].
27 ///
28 /// # Examples
29 ///
30 /// ```
31 /// use bitbelay_report::section::test;
32 /// use bitbelay_report::section::test::module::Result;
33 /// use bitbelay_report::section::test::Module;
34 /// use bitbelay_report::Builder;
35 ///
36 /// let result = test::Builder::default()
37 /// .title("Foo")?
38 /// .description("Bar")?
39 /// .push_module(Module::new(Result::Inconclusive, "Baz", None, None))
40 /// .try_build()?;
41 ///
42 /// assert_eq!(result.title(), "Foo");
43 ///
44 /// # Ok::<(), Box<dyn std::error::Error>>(())
45 /// ```
46 pub fn title(&self) -> &str {
47 self.title.as_ref()
48 }
49
50 /// Gets the description from the [`Test`].
51 ///
52 /// # Examples
53 ///
54 /// ```
55 /// use bitbelay_report::section::test;
56 /// use bitbelay_report::section::test::module::Result;
57 /// use bitbelay_report::section::test::Module;
58 /// use bitbelay_report::Builder;
59 ///
60 /// let result = test::Builder::default()
61 /// .title("Foo")?
62 /// .description("Bar")?
63 /// .push_module(Module::new(Result::Inconclusive, "Baz", None, None))
64 /// .try_build()?;
65 ///
66 /// assert_eq!(result.description(), "Bar");
67 ///
68 /// # Ok::<(), Box<dyn std::error::Error>>(())
69 /// ```
70 pub fn description(&self) -> &str {
71 self.description.as_ref()
72 }
73
74 /// Gets the [`Module`]s from the [`Test`].
75 ///
76 /// # Examples
77 ///
78 /// ```
79 /// use bitbelay_report::section::test;
80 /// use bitbelay_report::section::test::module::Result;
81 /// use bitbelay_report::section::test::Module;
82 /// use bitbelay_report::Builder;
83 ///
84 /// let module = Module::new(Result::Inconclusive, "Baz", None, None);
85 /// let result = test::Builder::default()
86 /// .title("Foo")?
87 /// .description("Bar")?
88 /// .push_module(module.clone())
89 /// .try_build()?;
90 ///
91 /// assert_eq!(result.modules().len(), 1);
92 /// assert_eq!(result.modules().first(), &module);
93 ///
94 /// # Ok::<(), Box<dyn std::error::Error>>(())
95 /// ```
96 pub fn modules(&self) -> &NonEmpty<Module> {
97 &self.modules
98 }
99}