Skip to content

Commit

Permalink
Refactor Test.pm6 to use an inner Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jul 28, 2010
1 parent 78e1546 commit f506534
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions Test.pm6
Expand Up @@ -2,21 +2,47 @@ module Test; # XXX our due to the STD pad bug

constant $?TRANSPARENT = 1;

sub blame() {
my $frame = caller;
while $frame.hints('$?TRANSPARENT') {
$frame = $frame.caller;
class Builder {
has $.current-test;

method new() {
$*TEST-BUILDER;
}
$frame.file ~ (" line " ~ $frame.line);
}

my $testnum = 1;
sub ok($bool, $tag) is export {
my $not = (if $bool { "" } else { "not " });
say ($not ~ ("ok " ~ ($testnum++ ~ (" - " ~ $tag))));
if !$bool { say ("# " ~ blame()); }
}
method blame() {
my $frame = caller;
while $frame.hints('$?TRANSPARENT') {
$frame = $frame.caller;
}
$frame.file ~ (" line " ~ $frame.line);
}

method _output($text) {
say $text;
}

method reset() {
$.current-test = 1;
}

sub plan($num) is export {
say ("1.." ~ $num);
method note($m) {
self._output("# " ~ $m);
0;
}

method ok($bool, $tag) {
my $not = $bool ?? "" !! "not ";
self._output($not ~ ("ok " ~ ($.current-test++ ~ (" - " ~ $tag))));
if !$bool { self.note(self.blame); }
}

method expected-tests($num) {
self._output("1.." ~ $num);
}
}

$GLOBAL::TEST-BUILDER = Builder.CREATE;
$GLOBAL::TEST-BUILDER.reset;

sub ok($bool, $tag) is export { $*TEST-BUILDER.ok($bool, $tag) }
sub plan($num) is export { $*TEST-BUILDER.expected-tests($num) }

0 comments on commit f506534

Please sign in to comment.