Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:rakudo/rakudo
Browse files Browse the repository at this point in the history
  • Loading branch information
chromatic committed Feb 14, 2010
2 parents 30e0ed3 + ac581a1 commit 100bb16
Show file tree
Hide file tree
Showing 255 changed files with 16,285 additions and 3,014 deletions.
9 changes: 5 additions & 4 deletions .gitignore
@@ -1,6 +1,6 @@
*~
src/gen_*.pir
src/gen_*.pm
/src/gen/*
/nqp-rx/
Makefile
.*.swp
*.patch
Expand All @@ -19,8 +19,8 @@ perl6.pdb
perl6.rc
t/localtest.data
t/spec
parrot
parrot_install
/parrot
/parrot_install
perl6
perl6.c
perl6.o
Expand All @@ -34,3 +34,4 @@ perl6_group.?
libparrot.dll
src/binder/bind.bundle
src/binder/bind.o
docs/test_summary.times
6 changes: 3 additions & 3 deletions README
Expand Up @@ -88,9 +88,9 @@ Once built, Rakudo's C<make install> target will install Rakudo
and its libraries into the Parrot installation that was used to
create it. Until this step is performed, the "perl6" executable
created by C<make> above can only be reliably run from the root of
Rakudo's build directory. After C<make install> is performed
the executable can be run from any directory (as long as the
Parrot installation that was used to create it remains intact).
Rakudo's build directory. After C<make install> is performed,
the installed executable can be run from any directory (as long as
the Parrot installation that was used to create it remains intact).

If the Rakudo compiler is invoked without an explicit script to
run, it enters a small interactive mode that allows Perl 6 statements
Expand Down
158 changes: 68 additions & 90 deletions Test.pm
Expand Up @@ -14,8 +14,6 @@ our $num_of_tests_planned;
our $no_plan = 1;
our $die_on_fail;

our $GLOBAL::WARNINGS = 0;

## If done_testing hasn't been run when we hit our END block, we need to know
## so that it can be run. This allows compatibility with old tests that use
## plans and don't call done_testing.
Expand All @@ -31,36 +29,43 @@ sub die_on_fail($fail=1) {

# "plan 'no_plan';" is now "plan *;"
# It is also the default if nobody calls plan at all
multi sub plan(Whatever $plan) is export(:DEFAULT) {
$no_plan = 1;
}
# multi sub plan(Whatever $plan) is export {
# $no_plan = 1;
# }

multi sub plan($number_of_tests) is export(:DEFAULT) {
$num_of_tests_planned = $number_of_tests;
$no_plan = 0;
multi sub plan($number_of_tests) is export {
if $number_of_tests ~~ ::Whatever {
$no_plan = 1;
}
else {
$num_of_tests_planned = $number_of_tests;
$no_plan = 0;

say '1..' ~ $number_of_tests;
say '1..' ~ $number_of_tests;
}
# say '# t=' ~ time;
}

multi sub pass($desc) is export(:DEFAULT) {
multi sub pass($desc) is export {
proclaim(1, $desc);
}

multi sub ok(Object $cond, $desc) is export(:DEFAULT) {
multi sub ok(Mu $cond, $desc) is export {
proclaim(?$cond, $desc);
}

multi sub ok(Object $cond) is export(:DEFAULT) { ok(?$cond, ''); }
multi sub ok(Mu $cond) is export { ok(?$cond, ''); }


multi sub nok(Object $cond, $desc) is export(:DEFAULT) {
multi sub nok(Mu $cond, $desc) is export {
proclaim(!$cond, $desc);
}

multi sub nok(Object $cond) is export(:DEFAULT) { nok($cond, ''); }
multi sub nok(Mu $cond) is export { nok($cond, ''); }


multi sub is(Object $got, Object $expected, $desc) is export(:DEFAULT) {
multi sub is(Mu $got, Mu $expected, $desc) is export {
$got.defined; # Hack to deal with Failures
my $test = $got eq $expected;
proclaim(?$test, $desc);
if !$test {
Expand All @@ -73,106 +78,107 @@ multi sub is(Object $got, Object $expected, $desc) is export(:DEFAULT) {
}
}

multi sub is(Object $got, Object $expected) is export(:DEFAULT) { is($got, $expected, ''); }
multi sub is(Mu $got, Mu $expected) is export { is($got, $expected, ''); }


multi sub isnt(Object $got, Object $expected, $desc) is export(:DEFAULT) {
multi sub isnt(Mu $got, Mu $expected, $desc) is export {
my $test = !($got eq $expected);
proclaim($test, $desc);
}

multi sub isnt(Object $got, Object $expected) is export(:DEFAULT) { isnt($got, $expected, ''); }
multi sub isnt(Mu $got, Mu $expected) is export { isnt($got, $expected, ''); }

multi sub is_approx(Object $got, Object $expected, $desc) is export(:DEFAULT) {
my $test = ($got - $expected).abs <= 0.00001;
multi sub is_approx(Mu $got, Mu $expected, $desc) is export {
my $test = ($got - $expected).abs <= 1/100000;
proclaim(?$test, $desc);
}

multi sub is_approx(Object $got, Object $expected) is export(:DEFAULT) {
multi sub is_approx(Mu $got, Mu $expected) is export {
is_approx($got, $expected, '');
}

multi sub todo($reason, $count) is export(:DEFAULT) {
multi sub todo($reason, $count) is export {
$todo_upto_test_num = $num_of_tests_run + $count;
$todo_reason = '# TODO ' ~ $reason;
}

multi sub todo($reason) is export(:DEFAULT) {
multi sub todo($reason) is export {
$todo_upto_test_num = $num_of_tests_run + 1;
$todo_reason = '# TODO ' ~ $reason;
}

multi sub skip() is export(:DEFAULT) { proclaim(1, "# SKIP"); }
multi sub skip($reason) is export(:DEFAULT) { proclaim(1, "# SKIP " ~ $reason); }
multi sub skip($count, $reason) is export(:DEFAULT) {
for 1..$count {
proclaim(1, "# SKIP " ~ $reason);
}
multi sub skip() is export { proclaim(1, "# SKIP"); }
multi sub skip($reason) is export { proclaim(1, "# SKIP " ~ $reason); }
multi sub skip($count, $reason) is export {
my $i = 1;
while $i <= $count { proclaim(1, "# SKIP " ~ $reason); $i = $i + 1; }
}

multi sub skip_rest() is export(:DEFAULT) {
multi sub skip_rest() is export {
skip($num_of_tests_planned - $num_of_tests_run, "");
}

multi sub skip_rest($reason) is export(:DEFAULT) {
multi sub skip_rest($reason) is export {
skip($num_of_tests_planned - $num_of_tests_run, $reason);
}

sub diag($message) is export(:DEFAULT) { say '# '~$message; }
sub diag($message) is export { say '# '~$message; }


multi sub flunk($reason) is export(:DEFAULT) { proclaim(0, "flunk $reason")}
multi sub flunk($reason) is export { proclaim(0, "flunk $reason")}


multi sub isa_ok(Object $var,$type) is export(:DEFAULT) {
multi sub isa_ok(Mu $var,$type) is export {
ok($var.isa($type), "The object is-a '$type'");
}
multi sub isa_ok(Object $var,$type, $msg) is export(:DEFAULT) { ok($var.isa($type), $msg); }
multi sub isa_ok(Mu $var,$type, $msg) is export { ok($var.isa($type), $msg); }

multi sub dies_ok(Callable $closure, $reason) is export(:DEFAULT) {
multi sub dies_ok($closure, $reason) is export {
try {
$closure();
}
if "$!" ~~ / ^ 'Null PMC access ' / {
diag "wrong way to die: '$!'";
}
proclaim((defined $! && "$!" !~~ / ^ 'Null PMC access ' /), $reason);
#if "$!" ~~ / ^ 'Null PMC access ' / {
# diag "wrong way to die: '$!'";
#}
proclaim(defined($!), $reason);
#proclaim((defined $! && "$!" !~~ / ^ 'Null PMC access ' /), $reason);
}
multi sub dies_ok(Callable $closure) is export(:DEFAULT) {
multi sub dies_ok($closure) is export {
dies_ok($closure, '');
}

multi sub lives_ok(Callable $closure, $reason) is export(:DEFAULT) {
multi sub lives_ok($closure, $reason) is export {
try {
$closure();
}
proclaim((not defined $!), $reason);
}
multi sub lives_ok(Callable $closure) is export(:DEFAULT) {
multi sub lives_ok($closure) is export {
lives_ok($closure, '');
}

multi sub eval_dies_ok(Str $code, $reason) is export(:DEFAULT) {
multi sub eval_dies_ok(Str $code, $reason) is export {
my $ee = eval_exception($code);
if "$ee" ~~ / ^ 'Null PMC access ' / {
diag "wrong way to die: '$ee'";
}
proclaim((defined $ee && "$ee" !~~ / ^ 'Null PMC access' /), $reason);
#if "$ee" ~~ / ^ 'Null PMC access ' / {
# diag "wrong way to die: '$ee'";
#}
proclaim((defined $ee), $reason);
# proclaim((defined $ee && "$ee" !~~ / ^ 'Null PMC access' /), $reason);
}
multi sub eval_dies_ok(Str $code) is export(:DEFAULT) {
multi sub eval_dies_ok(Str $code) is export {
eval_dies_ok($code, '');
}

multi sub eval_lives_ok(Str $code, $reason) is export(:DEFAULT) {
multi sub eval_lives_ok(Str $code, $reason) is export {
proclaim((not defined eval_exception($code)), $reason);
}
multi sub eval_lives_ok(Str $code) is export(:DEFAULT) {
multi sub eval_lives_ok(Str $code) is export {
eval_lives_ok($code, '');
}


multi sub is_deeply(Object $got, Object $expected, $reason = '')
is export(:DEFAULT)
multi sub is_deeply(Mu $got, Mu $expected, $reason = '')
is export
{
my $test = _is_deeply( $got, $expected );
proclaim($test, $reason);
Expand All @@ -186,38 +192,8 @@ multi sub is_deeply(Object $got, Object $expected, $reason = '')
}
}

sub _is_deeply(Object $got, Object $expected) {

if $got ~~ List && $expected ~~ List {
return if +$got.values != +$expected.values;
for $got Z $expected -> $a, $b {
return if ! _is_deeply( $a, $b );
}
return True;
}
elsif $got ~~ Hash && $expected ~~ Hash {
return if +$got.keys != +$expected.keys;
for $got.keys.sort Z $expected.keys.sort -> $a, $b {
return if $a ne $b;
return if ! _is_deeply( $got{$a}, $expected{$b} );
}
return True;
}
elsif $got ~~ Str | Num | Int && $expected ~~ Str | Num | Int {
return $got eq $expected;
}
elsif $got ~~ Pair && $expected ~~ Pair {
return $got.key eq $expected.key
&& _is_deeply( $got.value, $expected.value );
}
elsif $got ~~ undef && $expected ~~ undef && $got.WHAT eq $expected.WHAT {
return True;
}
elsif $got ~~ Bool && $expected ~~ Bool {
return ($got && $expected) || (!$got && !$expected);
}

return;
sub _is_deeply(Mu $got, Mu $expected) {
$got eqv $expected;
}


Expand All @@ -234,24 +210,26 @@ sub proclaim($cond, $desc) {

unless $cond {
print "not ";
$num_of_tests_failed = $num_of_tests_failed + 1
unless $num_of_tests_run <= $todo_upto_test_num;
unless $num_of_tests_run <= $todo_upto_test_num {
$num_of_tests_failed = $num_of_tests_failed + 1
}
}
print "ok ", $num_of_tests_run, " - ", $desc;
if $todo_reason and $num_of_tests_run <= $todo_upto_test_num {
print $todo_reason;
}
print "\n";
# say '# t=' ~ time;

if !$cond && $die_on_fail && !$todo_reason {
die "Test failed. Stopping test";
}
# must clear this between tests
$todo_reason = '' if $todo_upto_test_num == $num_of_tests_run;
return $cond;
if $todo_upto_test_num == $num_of_tests_run { $todo_reason = '' }
$cond;
}

sub done_testing() is export(:DEFAULT) {
sub done_testing() is export {
our $done_testing_has_been_run;

$done_testing_has_been_run = 1;
Expand Down

0 comments on commit 100bb16

Please sign in to comment.