sectionStep<T> function

T sectionStep<T>(
  1. StepSection section,
  2. String title,
  3. T body()
)

Runs body as a step inside section, restoring the previous section afterwards so the test body keeps reporting to Test (plugin tier).

Implementation

T sectionStep<T>(StepSection section, String title, T Function() body) {
  final ctx = getContext();
  if (ctx == null) return body();
  final previous = ctx.section;
  ctx.section = section;
  T result;
  try {
    result = step(title, body);
  } finally {
    // A sync body is done here; an async body settles later, but the section
    // must be back before the next statement in the caller records anything.
    ctx.section = previous;
  }
  return result;
}