Skip to content

Commit

Permalink
Merge branch 'beforeach-and-aftereach' into draft
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelMarks committed Jul 26, 2024
2 parents 809280d + 41cf1ce commit aafd628
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 31 deletions.
52 changes: 26 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 22 additions & 5 deletions src/lib/execution_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,32 @@ impl<'a> ExecutionPlanBuilder<'a> {
}
};
}
let mut before_each_task: Option<String> = None;
let mut after_each_task: Option<String> = None;
for step in steps.iter() {
match step.name.as_str() {
"before_each" => before_each_task = Some(step.name.clone()),
"after_each" => after_each_task = Some(step.name.clone()),
_ => {}
}
}

Ok(ExecutionPlan {
steps: Self::handle_before_each_and_after_each_tasks(&config, &steps)?.into_owned(),
steps: Self::handle_before_each_and_after_each_tasks(
&config,
before_each_task,
after_each_task,
&steps,
)?
.into_owned(),
})
}

/// `before_each` and `after_each` interspersal for the steps vector
fn handle_before_each_and_after_each_tasks<'b>(
config: &Config,
before_each_task: Option<String>,
after_each_task: Option<String>,
steps: &'b Vec<Step>,
) -> Result<Cow<'b, Vec<Step>>, CargoMakeError> {
let mut before_and_after_each = Vec::<Step>::with_capacity(2);
Expand All @@ -574,13 +591,13 @@ impl<'a> ExecutionPlanBuilder<'a> {
Ok(0)
}
};
let _has_after_each: u8 = match &config.config.after_each_task {
let _has_after_each: u8 = match after_each_task {
None => 0,
Some(after_each) => handle_some(after_each)?,
Some(after_each) => handle_some(&after_each)?,
};
let _has_before_each: u8 = match &config.config.before_each_task {
let _has_before_each: u8 = match before_each_task {
None => 0,
Some(before_each) => handle_some(before_each)?,
Some(before_each) => handle_some(&before_each)?,
};
_has_before_each + _has_after_each
};
Expand Down
22 changes: 22 additions & 0 deletions src/lib/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,20 @@ impl ConfigSection {
));
}

if self.before_each_task.is_some() {
self.before_each_task = Some(get_namespaced_task_name(
namespace,
&self.before_each_task.clone().unwrap(),
));
}

if self.after_each_task.is_some() {
self.after_each_task = Some(get_namespaced_task_name(
namespace,
&self.after_each_task.clone().unwrap(),
));
}

if self.on_error_task.is_some() {
self.on_error_task = Some(get_namespaced_task_name(
namespace,
Expand Down Expand Up @@ -2254,6 +2268,14 @@ impl ConfigSection {
self.end_task = extended.end_task.clone();
}

if let Some(before_each_task) = &extended.before_each_task {
self.before_each_task = Some(before_each_task.clone());
}

if let Some(after_each_task) = &extended.after_each_task {
self.after_each_task = Some(after_each_task.clone());
}

if extended.on_error_task.is_some() {
self.on_error_task = extended.on_error_task.clone();
}
Expand Down

0 comments on commit aafd628

Please sign in to comment.