← Back to index

lib/BDD/Behave/Failures.rakumod

26 / 26 lines covered (100.0%)

12use BDD::Behave::Colors;3use BDD::Behave::Diff;4use BDD::Behave::Failure;56class Failures is export {7  my @.list of Failure;89  method say(Int :$from = 0) {10    my $total = Failures.list.elems;11    return if $total <= $from;12    my @slice = Failures.list[$from .. $total - 1];13    say red("Failures:") ~ "\n";14    for @slice -> $failure {15      my $location = $failure.file ~ ':' ~ $failure.line;16      if $failure.aggregation-label.defined {17        $location ~= " (aggregate: {$failure.aggregation-label})";18      }19      say '  [' ~ red(" ✗ ") ~ '] ' ~ $location;20      if $failure.description.defined && !$failure.from-runner-exception {21        say '      ' ~ yellow($failure.description);22      }23      if $failure.message.defined {24        for $failure.message.lines -> $line {25          say "      $line";26        }27      } elsif $failure.given.defined || $failure.expected.defined {28        my $op = $failure.negated ?? "not to be" !! "to be";29        say "      Expected: " ~ $failure.given.raku;30        say "      $op: " ~ $failure.expected.raku;31        my $expected-is-junction = is-junction($failure.expected);32        if ($expected-is-junction || !$failure.negated)33           && diffable($failure.given, $failure.expected) {34          say "      Diff:";35          my $rendered = $expected-is-junction36            ?? render-diff($failure.given, $failure.expected, :negated($failure.negated))37            !! render-diff($failure.given, $failure.expected);38          for $rendered.lines -> $line {39            say "        $line";40          }41        }42      }43    }44    say '';45  }46}