batch_mode_batch_triple/
batch_file_state.rs1crate::ix!();
3
4#[derive(Debug, PartialEq, Eq)]
6pub enum BatchFileState {
7 InputOnly, InputOutput, InputError, InputOutputError, }
12
13impl From<&BatchFileTriple> for BatchFileState {
14
15 fn from(triple: &BatchFileTriple) -> BatchFileState {
17
18 let has_input = triple.input().is_some();
19 let has_error = triple.error().is_some();
20 let has_output = triple.output().is_some();
21
22 match (has_input, has_output, has_error) {
23 (true, true, true) => BatchFileState::InputOutputError,
24 (true, true, false) => BatchFileState::InputOutput,
25 (true, false, true) => BatchFileState::InputError,
26 (true, false, false) => BatchFileState::InputOnly,
27 _ => unreachable!("Input file must be present at this point"),
28 }
29 }
30}
31
32#[cfg(test)]
33mod batch_file_state_exhaustive_tests {
34 use super::*;
35
36 #[traced_test]
37 fn from_triple_with_input_only_yields_input_only() {
38 trace!("===== BEGIN TEST: from_triple_with_input_only_yields_input_only =====");
39 let triple = BatchFileTriple::new_direct(
40 &BatchIndex::new(),
41 Some(PathBuf::from("in.json")),
42 None, None, None,
43 Arc::new(MockBatchWorkspace::default())
44 );
45 let state = BatchFileState::from(&triple);
46 debug!("Computed state: {:?}", state);
47 pretty_assert_eq!(state, BatchFileState::InputOnly, "Expected InputOnly");
48 trace!("===== END TEST: from_triple_with_input_only_yields_input_only =====");
49 }
50
51 #[traced_test]
52 fn from_triple_with_input_output_yields_input_output() {
53 trace!("===== BEGIN TEST: from_triple_with_input_output_yields_input_output =====");
54 let triple = BatchFileTriple::new_direct(
55 &BatchIndex::new(),
56 Some(PathBuf::from("in.json")),
57 Some(PathBuf::from("out.json")),
58 None,
59 None,
60 Arc::new(MockBatchWorkspace::default())
61 );
62 let state = BatchFileState::from(&triple);
63 debug!("Computed state: {:?}", state);
64 pretty_assert_eq!(state, BatchFileState::InputOutput, "Expected InputOutput");
65 trace!("===== END TEST: from_triple_with_input_output_yields_input_output =====");
66 }
67
68 #[traced_test]
69 fn from_triple_with_input_error_yields_input_error() {
70 trace!("===== BEGIN TEST: from_triple_with_input_error_yields_input_error =====");
71 let triple = BatchFileTriple::new_direct(
72 &BatchIndex::new(),
73 Some(PathBuf::from("in.json")),
74 None,
75 Some(PathBuf::from("err.json")),
76 None,
77 Arc::new(MockBatchWorkspace::default())
78 );
79 let state = BatchFileState::from(&triple);
80 debug!("Computed state: {:?}", state);
81 pretty_assert_eq!(state, BatchFileState::InputError, "Expected InputError");
82 trace!("===== END TEST: from_triple_with_input_error_yields_input_error =====");
83 }
84
85 #[traced_test]
86 fn from_triple_with_all_three_files_yields_input_output_error() {
87 trace!("===== BEGIN TEST: from_triple_with_all_three_files_yields_input_output_error =====");
88 let triple = BatchFileTriple::new_direct(
89 &BatchIndex::new(),
90 Some(PathBuf::from("in.json")),
91 Some(PathBuf::from("out.json")),
92 Some(PathBuf::from("err.json")),
93 None,
94 Arc::new(MockBatchWorkspace::default())
95 );
96 let state = BatchFileState::from(&triple);
97 debug!("Computed state: {:?}", state);
98 pretty_assert_eq!(state, BatchFileState::InputOutputError, "Expected InputOutputError");
99 trace!("===== END TEST: from_triple_with_all_three_files_yields_input_output_error =====");
100 }
101}