diff options
Diffstat (limited to 'subplotlib/src')
-rw-r--r-- | subplotlib/src/scenario.rs | 28 | ||||
-rw-r--r-- | subplotlib/src/steplibrary/datadir.rs | 11 | ||||
-rw-r--r-- | subplotlib/src/steplibrary/runcmd.rs | 15 |
3 files changed, 53 insertions, 1 deletions
diff --git a/subplotlib/src/scenario.rs b/subplotlib/src/scenario.rs index b239883..c0f3e87 100644 --- a/subplotlib/src/scenario.rs +++ b/subplotlib/src/scenario.rs @@ -284,6 +284,7 @@ impl Scenario { // Firstly, we start all the contexts let mut ret = Ok(()); let mut highest_start = None; + println!("Scenario Start: {}", self.contexts.title()); for (i, hook) in self.contexts.hooks.borrow().iter().enumerate() { let res = hook.scenario_starts(&self.contexts); if res.is_err() { @@ -292,10 +293,14 @@ impl Scenario { } highest_start = Some(i); } - + println!( + "*** Context hooks returned {}", + if ret.is_ok() { "OK" } else { "Failure" } + ); if ret.is_ok() { let mut highest = None; for (i, step) in self.steps.iter().map(|(step, _)| step).enumerate() { + println!(" !!! Step {}", step.name()); let mut highest_prep = None; for (i, prep) in self.contexts.hooks.borrow().iter().enumerate() { let res = prep.step_starts(&self.contexts, step.name()); @@ -305,8 +310,17 @@ impl Scenario { } highest_prep = Some(i); } + println!( + " *** Context hooks returned {}", + if ret.is_ok() { "OK" } else { "Failure" } + ); if ret.is_ok() { + println!(" >>> Run step function"); let res = step.call(&self.contexts, false); + println!( + " Step returned {}", + if res.is_ok() { "OK" } else { "Failure" } + ); if res.is_err() { ret = res; break; @@ -314,6 +328,7 @@ impl Scenario { highest = Some(i); } if let Some(n) = highest_prep { + println!(" *** Unwinding step contexts"); for hookn in (0..=n).rev() { let res = self.contexts.hooks.borrow()[hookn].step_stops(&self.contexts); ret = ret.and(res) @@ -321,9 +336,15 @@ impl Scenario { } } if let Some(n) = highest { + println!(" *** Running cleanup functions"); for stepn in (0..=n).rev() { if let (_, Some(cleanup)) = &self.steps[stepn] { + println!(" >>> Cleanup {}", cleanup.name()); let res = cleanup.call(&self.contexts, true); + println!( + " Cleanup returned {}", + if res.is_ok() { "OK" } else { "Failure" } + ); ret = ret.and(res); } } @@ -331,11 +352,16 @@ impl Scenario { } if let Some(n) = highest_start { + println!("*** Running scenario closedown"); for hookn in (0..=n).rev() { let res = self.contexts.hooks.borrow()[hookn].scenario_stops(&self.contexts); ret = ret.and(res); } } + println!( + "<<< Scenario returns {}", + if ret.is_ok() { "OK" } else { "Failure" } + ); ret } } diff --git a/subplotlib/src/steplibrary/datadir.rs b/subplotlib/src/steplibrary/datadir.rs index 8aa6f00..88e6375 100644 --- a/subplotlib/src/steplibrary/datadir.rs +++ b/subplotlib/src/steplibrary/datadir.rs @@ -91,6 +91,17 @@ impl Datadir { .open(full_path)? } + /// Open a file for reading + #[throws(StepError)] + pub fn open_read<S: AsRef<Path>>(&self, subpath: S) -> File { + let full_path = self.canonicalise_filename(subpath)?; + OpenOptions::new() + .create(false) + .write(false) + .read(true) + .open(full_path)? + } + #[throws(StepError)] pub fn create_dir_all<S: AsRef<Path>>(&self, subpath: S) { let full_path = self.canonicalise_filename(subpath)?; diff --git a/subplotlib/src/steplibrary/runcmd.rs b/subplotlib/src/steplibrary/runcmd.rs index f42df6e..5fc12eb 100644 --- a/subplotlib/src/steplibrary/runcmd.rs +++ b/subplotlib/src/steplibrary/runcmd.rs @@ -67,9 +67,24 @@ impl ContextElement for Runcmd { } impl Runcmd { + /// Prepend the given location to the run path pub fn prepend_to_path<S: Into<OsString>>(&mut self, element: S) { self.paths.push(element.into()); } + + /// Retrieve the last run command's stdout as a string. + /// + /// This does a lossy conversion from utf8 so should always succeed. + pub fn stdout_as_string(&self) -> String { + String::from_utf8_lossy(&self.stdout).into_owned() + } + + /// Retrieve the last run command's stderr as a string. + /// + /// This does a lossy conversion from utf8 so should always succeed. + pub fn stderr_as_string(&self) -> String { + String::from_utf8_lossy(&self.stderr).into_owned() + } } #[step] |