nextest_runner/config/
junit.rs1use camino::{Utf8Path, Utf8PathBuf};
5use serde::Deserialize;
6
7#[derive(Clone, Debug)]
11pub struct JunitConfig<'cfg> {
12 path: Utf8PathBuf,
13 report_name: &'cfg str,
14 store_success_output: bool,
15 store_failure_output: bool,
16}
17
18impl<'cfg> JunitConfig<'cfg> {
19 pub(super) fn new(
20 store_dir: &Utf8Path,
21 custom_data: Option<&'cfg JunitImpl>,
22 default_data: &'cfg DefaultJunitImpl,
23 ) -> Option<Self> {
24 let path = custom_data
25 .map(|custom| &custom.path)
26 .unwrap_or(&default_data.path)
27 .as_deref();
28
29 path.map(|path| {
30 let path = store_dir.join(path);
31 let report_name = custom_data
32 .and_then(|custom| custom.report_name.as_deref())
33 .unwrap_or(&default_data.report_name);
34 let store_success_output = custom_data
35 .and_then(|custom| custom.store_success_output)
36 .unwrap_or(default_data.store_success_output);
37 let store_failure_output = custom_data
38 .and_then(|custom| custom.store_failure_output)
39 .unwrap_or(default_data.store_failure_output);
40 Self {
41 path,
42 report_name,
43 store_success_output,
44 store_failure_output,
45 }
46 })
47 }
48
49 pub fn path(&self) -> &Utf8Path {
51 &self.path
52 }
53
54 pub fn report_name(&self) -> &'cfg str {
56 self.report_name
57 }
58
59 pub fn store_success_output(&self) -> bool {
61 self.store_success_output
62 }
63
64 pub fn store_failure_output(&self) -> bool {
66 self.store_failure_output
67 }
68}
69
70#[derive(Clone, Debug)]
71pub(super) struct DefaultJunitImpl {
72 path: Option<Utf8PathBuf>,
73 report_name: String,
74 store_success_output: bool,
75 store_failure_output: bool,
76}
77
78impl DefaultJunitImpl {
79 pub(crate) fn for_default_profile(data: JunitImpl) -> Self {
81 DefaultJunitImpl {
82 path: data.path,
83 report_name: data
84 .report_name
85 .expect("junit.report present in default profile"),
86 store_success_output: data
87 .store_success_output
88 .expect("junit.store-success-output present in default profile"),
89 store_failure_output: data
90 .store_failure_output
91 .expect("junit.store-failure-output present in default profile"),
92 }
93 }
94}
95
96#[derive(Clone, Debug, Default, Deserialize)]
97#[serde(rename_all = "kebab-case")]
98pub(super) struct JunitImpl {
99 #[serde(default)]
100 path: Option<Utf8PathBuf>,
101 #[serde(default)]
102 report_name: Option<String>,
103 #[serde(default)]
104 store_success_output: Option<bool>,
105 #[serde(default)]
106 store_failure_output: Option<bool>,
107}