<commit_before>package org.specs.specification

/**
 * This trait holds the actions to execute before or after examples, or a list of examples.
 */
trait ExampleContext extends ExampleLifeCycle {
  
  /** the before function will be invoked before each example */
  var before: Option[() => Any] = None
  /** the firstActions function will be invoked before all examples */
  var firstActions: Option[() => Any] = None
  /** the after function will be invoked after each example */
  var after: Option[() => Any] = None
  /** the lastActions function will be invoked after all examples */
  var lastActions: Option[() => Any] = None
  /** calls the before method of the "parent" cycle, then the sus before method before an example if that method is defined. */
  override def beforeExample(ex: Examples): Unit = {
    parent.map(_.beforeExample(ex))
    if (!(ex eq this)) {
      if (!exampleList.isEmpty && ex == exampleList.first)
        firstActions.map(_.apply)
      before.map(_.apply())
    }
  }
  /** calls the after method of the "parent" cycle, then the sus after method after an example if that method is defined. */
  override def afterExample(ex: Examples): Unit = { 
    if (!(ex eq this)) {
      after.map {_.apply()}
      if (!exampleList.isEmpty && ex == exampleList.last) lastActions.map(_.apply)
    }
    parent.map(_.afterExample(ex))
  }
  /** copy actions and results from another example. */
  override def copyExecutionResults(other: Examples) = {
    copyContextFrom(other)
    copyExecutionResults(other)
  }

  /** copy all actions from another context. */
  def copyContextFrom(other: ExampleContext) = {
    before = other.before
    after = other.after
    untilPredicate = other.untilPredicate
    firstActions = other.firstActions
    lastActions = other.lastActions
  }
}<commit_msg>reverted an erroneous change leading to infinite recursion<commit_after>package org.specs.specification

trait ExampleContext extends ExampleLifeCycle {
  
  /** the before function will be invoked before each example */
  var before: Option[() => Any] = None
  /** the firstActions function will be invoked before all examples */
  var firstActions: Option[() => Any] = None
  /** the after function will be invoked after each example */
  var after: Option[() => Any] = None
  /** the lastActions function will be invoked after all examples */
  var lastActions: Option[() => Any] = None
  /** calls the before method of the "parent" cycle, then the sus before method before an example if that method is defined. */
  override def beforeExample(ex: Examples): Unit = {
    parent.map(_.beforeExample(ex))
    if (!(ex eq this)) {
      if (!exampleList.isEmpty && ex == exampleList.first)
        firstActions.map(_.apply)
      before.map(_.apply())
    }
  }
  /** calls the after method of the "parent" cycle, then the sus after method after an example if that method is defined. */
  override def afterExample(ex: Examples): Unit = { 
    if (!(ex eq this)) {
      after.map {_.apply()}
      if (!exampleList.isEmpty && ex == exampleList.last) lastActions.map(_.apply)
    }
    parent.map(_.afterExample(ex))
  }
  override def copyExecutionResults(other: Examples) = {
    copyContextFrom(other)
    super.copyExecutionResults(other)
  }

  def copyContextFrom(other: ExampleContext) = {
    before = other.before
    after = other.after
    untilPredicate = other.untilPredicate
    firstActions = other.firstActions
    lastActions = other.lastActions
  }
}
{'fraction_non_alphanumeric': 0.10971068461758808, 'fraction_numerical': 0.0, 'mean_word_length': 3.420253164556962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1691275', 'n_tokens_mistral': 945, 'n_tokens_neox': 940, 'n_words': 348}