Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
"like" shall not crash the script when a non-Str is passed
for example, when you were like `@things[2]` and there weren't enough items.
also, the "hack to deal with failures" was never going to work, as
Failure can't get passed to a Str parameter
  • Loading branch information
timo committed Apr 28, 2017
1 parent 6de0893 commit ba3cf4e
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions lib/Test.pm6
Expand Up @@ -467,32 +467,46 @@ multi sub can-ok(
}

multi sub like(
Str $got, Regex $expected,
$got, Regex $expected,
$desc = "text matches '$expected.perl()'"
) is export {
$time_after = nqp::time_n;
$got.defined; # Hack to deal with Failures
my $test = $got ~~ $expected;
my $ok = proclaim(?$test, $desc);
if !$test {
_diag " expected: '$expected.perl()'\n"
~ " got: '$got'";
my $ok;
if $got ~~ Str:D {
my $test = $got ~~ $expected;
$ok = proclaim(?$test, $desc);
if !$test {
_diag " expected: '$expected.perl()'\n"
~ " got: '$got'";
}
} else {
$ok = proclaim(False, $desc);
_diag " expected a Str that matches '$expected.perl()'\n"
~ " got: '$got.perl()'";
}
$time_before = nqp::time_n;
$ok or ($die_on_fail and die-on-fail) or $ok;
}

multi sub unlike(
Str $got, Regex $expected,
$got, Regex $expected,
$desc = "text does not match '$expected.perl()'"
) is export {
$time_after = nqp::time_n;
$got.defined; # Hack to deal with Failures
my $test = !($got ~~ $expected);
my $ok = proclaim(?$test, $desc);
if !$test {
_diag " expected: '$expected.perl()'\n"
~ " got: '$got'";
my $ok;
if $got ~~ Str:D {
my $test = !($got ~~ $expected);
$ok = proclaim(?$test, $desc);
if !$test {
_diag " expected: '$expected.perl()'\n"
~ " got: '$got'";
}
} else {
$ok = proclaim(False, $desc);
_diag " expected: a Str that matches '$expected.perl()'\n"
~ " got: '$got.perl()'";
}
$time_before = nqp::time_n;
$ok or ($die_on_fail and die-on-fail) or $ok;
Expand Down

0 comments on commit ba3cf4e

Please sign in to comment.