Skip to content

Commit

Permalink
Make the 'is' routine in Test not throwing an error on failure when t…
Browse files Browse the repository at this point in the history
…he type can't be stringified, falling back on .raku instead.

A good example is the Buf type that has a Str routine that fail to encourage the user to use encode instead.

is Buf.new(42), Buf.new(43)

This will fail with the error :
Cannot use a Buf as a string, but you called the Stringy method on it
instead of the regular got, expected message.

This fix issue #3535
  • Loading branch information
Skarsnik committed May 23, 2020
1 parent 604085f commit c9e9462
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Test.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,15 @@ multi sub is(Mu $got, Mu:D $expected, $desc = '') is export {
~ " got: $got.raku()";
}
else {
_diag "expected: '$expected'\n"
try { # if the type support Stringification
# note: we can't use ^can('Str') as Buf error in its Str method itself
_diag "expected: '$expected'\n"
~ " got: '$got'";
True;
} or {
_diag "expected: $expected.raku()\n"
~ " got: $got.raku()";
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions t/01-sanity/99-test-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ todo( 'failing is-deeply returns False' );
my $is-deeply = is-deeply {a => 1}, {}, 'is-deeply with exta key fails';
nok $is-deeply, 'failing is-deeply returns False';

# Testing issue #3535
is Buf.new(42), Buf.new(42), "Comparing eq Buf";
lives-ok {
# NOT_TODO
todo("Comparing 2 not eq Buf, should not pass");
is Buf.new(42), Buf.new(43);
}, "Comparing neq Buf";

done-testing;

# vim: ft=perl6

0 comments on commit c9e9462

Please sign in to comment.