← Back to index

lib/BDD/Behave/Failure.rakumod

19 / 19 lines covered (100.0%)

12class X::BDD::Behave::ExpectationFailed is Exception is export {3  has Str $.file;4  has Int $.line;5  method message(--> Str) { "expectation failed at {$!file}:{$!line}" }6}78class Failure is export {9  has Str $.file;10  has Int $.line;11  has $.given;12  has $.expected;13  has Bool $.negated = False;14  has Str  $.message;15  has Str  $.aggregation-label;16  has Bool $.from-runner-exception = False;17  has Str  $.description;1819  submethod BUILD(20    :$!file, :$!line, Mu :$given is raw, Mu :$expected is raw,21    :$!negated = False, :$!message = Str, :$aggregation-label,22    Bool :$!from-runner-exception = False,23    Str  :$description,24  ) {25    $!given = $given;26    $!expected = $expected;27    my ($path,) = $!file.split(':');28    $!file = $path;29    if $aggregation-label.defined {30      $!aggregation-label = $aggregation-label;31    } else {32      try {33        $!aggregation-label = $*BEHAVE-AGGREGATION-LABEL34          if $*BEHAVE-AGGREGATION-LABEL.defined;35      }36    }37    if $description.defined {38      $!description = $description;39    } else {40      try {41        $!description = $*BEHAVE-CURRENT-DESCRIPTION42          if $*BEHAVE-CURRENT-DESCRIPTION.defined;43      }44    }45  }46}4748# The rendered form of an expectation failure that carries no message of its49# own. The JSON event stream and the parallel parent both describe a failure50# through this, so an event carries the same fields whichever path produced it.51sub compose-failure-message($given, $expected, Bool $negated = False --> Str) is export {52  my $given-text    = ($given    // '').Str;53  my $expected-text = ($expected // '').Str;5455  return '' unless $given-text.chars || $expected-text.chars;5657  my $op = $negated ?? 'not to be' !! 'to be';5859  "Expected: $given-text\n$op: $expected-text";60}