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 aafd628 + 8b7594e commit 1d0b9e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
8 changes: 8 additions & 0 deletions src/lib/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,5 +638,13 @@ pub fn load(
}
}

for (name, _) in config.tasks.iter() {
match name.as_str() {
"before_each" => config.config.before_each_task = Some(name.to_string()),
"after_each" => config.config.after_each_task = Some(name.to_string()),
_ => {}
}
}

Ok(config)
}
25 changes: 4 additions & 21 deletions src/lib/execution_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,32 +549,15 @@ 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,
before_each_task,
after_each_task,
&steps,
)?
.into_owned(),
steps: Self::handle_before_each_and_after_each_tasks(&config, &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 @@ -591,11 +574,11 @@ impl<'a> ExecutionPlanBuilder<'a> {
Ok(0)
}
};
let _has_after_each: u8 = match after_each_task {
let _has_after_each: u8 = match &config.config.after_each_task {
None => 0,
Some(after_each) => handle_some(&after_each)?,
};
let _has_before_each: u8 = match before_each_task {
let _has_before_each: u8 = match &config.config.before_each_task {
None => 0,
Some(before_each) => handle_some(&before_each)?,
};
Expand All @@ -607,7 +590,7 @@ impl<'a> ExecutionPlanBuilder<'a> {
Vec::<Step>::with_capacity(steps.len() * before_and_after_each_len);
interspersed_steps.extend(steps.into_iter().flat_map(|e| -> Vec<Step> {
let mut _steps = Vec::<Step>::with_capacity(before_and_after_each_len + 1);
_steps.clone_from_slice(&before_and_after_each);
_steps.extend(before_and_after_each.clone());
_steps.push(e.to_owned());
_steps
}));
Expand Down

0 comments on commit 1d0b9e8

Please sign in to comment.