Skip to content

Commit

Permalink
Implement like()
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Sep 15, 2016
1 parent 93de986 commit 977db7b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/Test.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ sub can-ok(
@Testers[0].test: $var.^can($meth), :$desc;
}

sub like(Str $got, Regex $expected, $desc = '') is export {
@Testers[0].test: $got ~~ $expected,
:failure{ exgo "'$expected.perl()'", "'$got'" }, :$desc;
}

class Tester {
has int $.die-on-fail = ?%*ENV<PERL6_TEST_DIE_ON_FAIL>;
has int $.failed = 0;
Expand Down Expand Up @@ -336,7 +341,7 @@ Routines in category: `todo`, `subtest`
- Do Y on False

Routines in category: ✓`pass`, ✓`ok`, ✓`nok`, ✓`is`, ✓`isnt`, ✓`cmp-ok`,
✓`is-approx`, ✓`flunk`, ✓`isa-ok`, ✓`does-ok`, ✓`can-ok`, `like`,
✓`is-approx`, ✓`flunk`, ✓`isa-ok`, ✓`does-ok`, ✓`can-ok`, `like`,
`unlike`, `use-ok`, `dies-ok`, `lives-ok`,
`eval-dies-ok`, `eval-lives-ok`, `is-deeply`, `throws-like`

Expand Down Expand Up @@ -375,3 +380,11 @@ True/False.
The test routine will handle marking the test as TODO, correctly directing
the output, dying on failures, and emitting proper TAP output, depending on
the outcome of the provided test operation.
-----------------------------------------------------------
Issues in the old Test.pm6 found during refactoring:
* like (Failure, Regex) and unlike (Failure, Regex) candidates do not exist,
despite existing candidates having logic to handle failures (they won't ever
get there)
3 changes: 3 additions & 0 deletions test-volatile.t
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ does-ok $Foo but role {}, FooRole;
can-ok $Instance, 'foo';
can-ok $Class, 'foo';

like 'foo', /bar/, 'just a test';
like 'foo', /bar/;

done-testing;
3 changes: 3 additions & 0 deletions test.t
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,7 @@ can-ok Foo, 'foo';
can-ok $Instance, 'foo', 'just a test';
can-ok $Class, 'foo', 'just a test';

like 'foo', /foo/, 'just a test';
like 'foo', /foo/;

done-testing;

0 comments on commit 977db7b

Please sign in to comment.