summaryrefslogtreecommitdiff
path: root/subplotlib
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2022-04-01 19:28:02 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2022-04-01 19:32:51 +0100
commited25345d6986aca6d115f86ff1ee4cb904340979 (patch)
treed97494f6751fb2bbc96cc0a82875183e770c53f5 /subplotlib
parentd2edcaed3ae20c0b6ebde1b9c6c778ef94cf157e (diff)
downloadsubplot-ed25345d6986aca6d115f86ff1ee4cb904340979.tar.gz
(subplotlib): Make ScenarioStep hold a full step text rather than just a function name
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'subplotlib')
-rw-r--r--subplotlib/src/scenario.rs8
-rw-r--r--subplotlib/src/step.rs18
2 files changed, 14 insertions, 12 deletions
diff --git a/subplotlib/src/scenario.rs b/subplotlib/src/scenario.rs
index 1200a99..7cebb31 100644
--- a/subplotlib/src/scenario.rs
+++ b/subplotlib/src/scenario.rs
@@ -235,7 +235,7 @@ impl ScenarioContext {
/// let run_step = subplotlib::steplibrary::runcmd::run::Builder::default()
/// .argv0("true")
/// .args("")
-/// .build();
+/// .build("when I run true".to_string());
/// scenario.add_step(run_step, None);
///
/// ```
@@ -314,10 +314,10 @@ impl Scenario {
if ret.is_ok() {
let mut highest = None;
for (i, step) in self.steps.iter().map(|(step, _)| step).enumerate() {
- println!(" step: {}", step.name());
+ println!(" step: {}", step.step_text());
let mut highest_prep = None;
for (i, prep) in self.contexts.hooks.borrow().iter().enumerate() {
- let res = prep.step_starts(&self.contexts, step.name());
+ let res = prep.step_starts(&self.contexts, step.step_text());
if res.is_err() {
ret = res;
break;
@@ -345,7 +345,7 @@ impl Scenario {
if let Some(n) = highest {
for stepn in (0..=n).rev() {
if let (_, Some(cleanup)) = &self.steps[stepn] {
- println!(" cleanup: {}", cleanup.name());
+ println!(" cleanup: {}", cleanup.step_text());
let res = cleanup.call(&self.contexts, true);
if res.is_err() {
println!("*** Cleanup returned failure",);
diff --git a/subplotlib/src/step.rs b/subplotlib/src/step.rs
index b9c2a86..bbea249 100644
--- a/subplotlib/src/step.rs
+++ b/subplotlib/src/step.rs
@@ -22,10 +22,12 @@ use crate::types::StepResult;
/// ```
/// # use subplotlib::prelude::*;
///
-/// let step = ScenarioStep::new("step name", |ctx, ok| Ok(()), |scen| ());
+/// let step = ScenarioStep::new(
+/// "when everything works".to_string(), |ctx, ok| Ok(()), |scen| ()
+/// );
/// ```
pub struct ScenarioStep {
- name: String,
+ step_text: String,
func: Box<dyn Fn(&ScenarioContext, bool) -> StepResult>,
reg: Box<dyn Fn(&Scenario)>,
}
@@ -36,13 +38,13 @@ impl ScenarioStep {
/// This is used to construct a scenario step from a function which
/// takes the scenario context container. This will generally be
/// called from the generated build method for the step.
- pub fn new<F, R>(name: &str, func: F, reg: R) -> Self
+ pub fn new<F, R>(step_text: String, func: F, reg: R) -> Self
where
F: Fn(&ScenarioContext, bool) -> StepResult + 'static,
R: Fn(&Scenario) + 'static,
{
Self {
- name: name.to_string(),
+ step_text,
func: Box::new(func),
reg: Box::new(reg),
}
@@ -69,12 +71,12 @@ impl ScenarioStep {
// subsequent step calls may not be sound. There's not a lot we can
// do to ensure things are good except try.
let func = AssertUnwindSafe(|| (*self.func)(context, defuse_poison));
- catch_unwind(func).map_err(|e| Self::render_panic(self.name(), e))?
+ catch_unwind(func).map_err(|e| Self::render_panic(self.step_text(), e))?
}
- /// Return the name of this step
- pub fn name(&self) -> &str {
- &self.name
+ /// Return the full text of this step
+ pub fn step_text(&self) -> &str {
+ &self.step_text
}
/// Register any context types needed by this step